Skip to content

Commit 2665e0d

Browse files
authoredJun 27, 2016
Merge pull request #265 from gsnedders/testing_cleanup
A bunch of testing fixes
2 parents 11bdb49 + a6550ac commit 2665e0d

File tree

3 files changed

+944
-9
lines changed

3 files changed

+944
-9
lines changed
 

‎.pytest.expect

Lines changed: 880 additions & 0 deletions
Large diffs are not rendered by default.

‎html5lib/tests/conftest.py

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,86 @@
11
import os.path
22

3+
import pkg_resources
4+
import pytest
5+
36
from .tree_construction import TreeConstructionFile
47
from .tokenizer import TokenizerFile
58
from .sanitizer import SanitizerFile
69

710
_dir = os.path.abspath(os.path.dirname(__file__))
11+
_root = os.path.join(_dir, "..", "..")
812
_testdata = os.path.join(_dir, "testdata")
913
_tree_construction = os.path.join(_testdata, "tree-construction")
1014
_tokenizer = os.path.join(_testdata, "tokenizer")
1115
_sanitizer_testdata = os.path.join(_dir, "sanitizer-testdata")
1216

1317

14-
def pytest_collectstart():
15-
"""check to see if the git submodule has been init'd"""
16-
pass
18+
def pytest_configure(config):
19+
msgs = []
20+
21+
if not os.path.exists(_testdata):
22+
msg = "testdata not available! "
23+
if os.path.exists(os.path.join(_root, ".git")):
24+
msg += ("Please run git submodule update --init --recursive " +
25+
"and then run tests again.")
26+
else:
27+
msg += ("The testdata doesn't appear to be included with this package, " +
28+
"so finding the right version will be hard. :(")
29+
msgs.append(msg)
30+
31+
if config.option.update_xfail:
32+
# Check for optional requirements
33+
req_file = os.path.join(_root, "requirements-optional.txt")
34+
if os.path.exists(req_file):
35+
with open(req_file, "r") as fp:
36+
for line in fp:
37+
if (line.strip() and
38+
not (line.startswith("-r") or
39+
line.startswith("#"))):
40+
if ";" in line:
41+
spec, marker = line.strip().split(";", 1)
42+
else:
43+
spec, marker = line.strip(), None
44+
req = pkg_resources.Requirement.parse(spec)
45+
if marker and not pkg_resources.evaluate_marker(marker):
46+
msgs.append("%s not available in this environment" % spec)
47+
else:
48+
try:
49+
installed = pkg_resources.working_set.find(req)
50+
except pkg_resources.VersionConflict:
51+
msgs.append("Outdated version of %s installed, need %s" % (req.name, spec))
52+
else:
53+
if not installed:
54+
msgs.append("Need %s" % spec)
55+
56+
# Check cElementTree
57+
import xml.etree.ElementTree as ElementTree
58+
59+
try:
60+
import xml.etree.cElementTree as cElementTree
61+
except ImportError:
62+
msgs.append("cElementTree unable to be imported")
63+
else:
64+
if cElementTree.Element is ElementTree.Element:
65+
msgs.append("cElementTree is just an alias for ElementTree")
66+
67+
if msgs:
68+
pytest.exit("\n".join(msgs))
1769

1870

1971
def pytest_collect_file(path, parent):
2072
dir = os.path.abspath(path.dirname)
21-
if dir == _tree_construction:
22-
if path.basename == "template.dat":
23-
return
73+
dir_and_parents = set()
74+
while dir not in dir_and_parents:
75+
dir_and_parents.add(dir)
76+
dir = os.path.dirname(dir)
77+
78+
if _tree_construction in dir_and_parents:
2479
if path.ext == ".dat":
2580
return TreeConstructionFile(path, parent)
26-
elif dir == _tokenizer:
81+
elif _tokenizer in dir_and_parents:
2782
if path.ext == ".test":
2883
return TokenizerFile(path, parent)
29-
elif dir == _sanitizer_testdata:
84+
elif _sanitizer_testdata in dir_and_parents:
3085
if path.ext == ".dat":
3186
return SanitizerFile(path, parent)

‎html5lib/tests/support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
try:
6363
import genshi # noqa
6464
except ImportError:
65-
pass
65+
treeTypes["genshi"] = None
6666
else:
6767
treeTypes["genshi"] = {
6868
"builder": treebuilders.getTreeBuilder("dom"),

0 commit comments

Comments
 (0)
Please sign in to comment.