Skip to content

Commit

Permalink
Fix #237: fail if --update-xfail is used in wrong environment
Browse files Browse the repository at this point in the history
  • Loading branch information
gsnedders committed Jun 8, 2016
1 parent 662f2db commit ae141b8
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion html5lib/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import os.path

import pkg_resources
import pytest

from .tree_construction import TreeConstructionFile
from .tokenizer import TokenizerFile
from .sanitizer import SanitizerFile

_dir = os.path.abspath(os.path.dirname(__file__))
_root = os.path.join(_dir, "..", "..")
_testdata = os.path.join(_dir, "testdata")
_tree_construction = os.path.join(_testdata, "tree-construction")
_tokenizer = os.path.join(_testdata, "tokenizer")
Expand All @@ -15,15 +17,53 @@

def pytest_configure(config):
msgs = []

if not os.path.exists(_testdata):
msg = "testdata not available! "
if os.path.exists(os.path.join(_dir, "..", "..", ".git")):
if os.path.exists(os.path.join(_root, ".git")):
msg += ("Please run git submodule update --init --recursive " +
"and then run tests again.")
else:
msg += ("The testdata doesn't appear to be included with this package, " +
"so finding the right version will be hard. :(")
msgs.append(msg)

if config.option.update_xfail:
# Check for optional requirements
req_file = os.path.join(_root, "requirements-optional.txt")
if os.path.exists(req_file):
with open(req_file, "r") as fp:
for line in fp:
if (line.strip() and
not (line.startswith("-r") or
line.startswith("#"))):
if ";" in line:
spec, marker = line.strip().split(";", 1)
else:
spec, marker = line.strip(), None
req = pkg_resources.Requirement.parse(spec)
if marker and not pkg_resources.evaluate_marker(marker):
msgs.append("%s not available in this environment" % spec)
else:
try:
installed = pkg_resources.working_set.find(req)
except pkg_resources.VersionConflict:
msgs.append("Outdated version of %s installed, need %s" % (req.name, spec))
else:
if not installed:
msgs.append("Need %s" % spec)

# Check cElementTree
import xml.etree.ElementTree as ElementTree

try:
import xml.etree.cElementTree as cElementTree
except ImportError:
msgs.append("cElementTree unable to be imported")
else:
if cElementTree.Element is ElementTree.Element:
msgs.append("cElementTree is just an alias for ElementTree")

if msgs:
pytest.exit("\n".join(msgs))

Expand Down

0 comments on commit ae141b8

Please sign in to comment.