Skip to content

Commit

Permalink
Fix tests for lxml 4.4.0+ (#152)
Browse files Browse the repository at this point in the history
* Fix tests for lxml 4.4.0+

It seems that LXML addressed a quirk we had noticed in our tests. Now
it behaves more like we would expect.

* Drop testing Py34

* Fix for no-lxml test run

We need to skip the test_defined_xhtml test if lxml is not available.
  • Loading branch information
facelessuser authored Aug 14, 2019
1 parent 65a039a commit b9fddc0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ matrix:
- python: 2.7
env:
- TOXENV=py27
- python: 3.4
env:
- TOXENV=py34
- python: 3.5
env:
- TOXENV=py35
Expand Down
4 changes: 1 addition & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ environment:
matrix:
- PYTHON: "C:/Python27"
TOXENV: "py27"
- PYTHON: "C:/Python34"
TOXENV: "py34"
- PYTHON: "C:/Python35"
TOXENV: "py35"
- PYTHON: "C:/Python36"
TOXENV: "py36"
- PYTHON: "C:/Python37"
TOXENV: "py37"
- PYTHON: "C:/Python36"
- PYTHON: "C:/Python37"
TOXENV: "lint"

init:
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def get_description():
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
Expand Down
13 changes: 8 additions & 5 deletions tests/test_level4/test_defined.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def test_defined_html(self):
flags=util.HTML
)

@util.skip_no_lxml
def test_defined_xhtml(self):
"""Test defined XHTML."""

Expand All @@ -45,21 +46,23 @@ def test_defined_xhtml(self):
<div-custom id="1"></div-custom>
<prefix:div id="2"></prefix:div>
<!--
lxml or BeautifulSoup seems to strip away the prefix.
This is most likely because prefix with no namespace is not really valid.
lxml seems to strip away the prefix in versions less than 4.4.0.
This was most likely because prefix with no namespace is not really valid.
XML does allow colons in names, but encourages them to be used for namespaces.
Do we really care that the prefix is wiped out in XHTML if there is no namespace?
If we do, we should look into this in the future.
This is a quirk of LXML, but it appears to be fine in 4.4.0+.
-->
<prefix:div-custom id="3"></prefix:div-custom>
</body>
</html>
"""

from lxml import etree

self.assert_selector(
markup,
'body :defined',
['0', '2'], # We should get 3, but we don't for reasons stated above.
# We should get 3, but for LXML versions less than 4.4.0 we don't for reasons stated above.
['0', '2'] if etree.LXML_VERSION < (4, 4, 0, 0) else ['0', '1', '2'],
flags=util.XHTML
)

Expand Down
12 changes: 12 additions & 0 deletions tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ def skip_if(self, *args, **kwargs):
return skip_if


def skip_no_lxml(func):
"""Decorator that skips lxml is not available."""

def skip_if(self, *args, **kwargs):
"""Skip conditional wrapper."""

if LXML_PRESENT:
return func(self, *args, **kwargs)
else:
raise pytest.skip('lxml is not found')


class TestCase(unittest.TestCase):
"""Test case."""

Expand Down

0 comments on commit b9fddc0

Please sign in to comment.