|
1 | 1 | import os.path |
2 | 2 |
|
| 3 | +import pkg_resources |
3 | 4 | import pytest |
4 | 5 |
|
5 | 6 | from .tree_construction import TreeConstructionFile |
6 | 7 | from .tokenizer import TokenizerFile |
7 | 8 | from .sanitizer import SanitizerFile |
8 | 9 |
|
9 | 10 | _dir = os.path.abspath(os.path.dirname(__file__)) |
| 11 | +_root = os.path.join(_dir, "..", "..") |
10 | 12 | _testdata = os.path.join(_dir, "testdata") |
11 | 13 | _tree_construction = os.path.join(_testdata, "tree-construction") |
12 | 14 | _tokenizer = os.path.join(_testdata, "tokenizer") |
|
15 | 17 |
|
16 | 18 | def pytest_configure(config): |
17 | 19 | msgs = [] |
| 20 | + |
18 | 21 | if not os.path.exists(_testdata): |
19 | 22 | msg = "testdata not available! " |
20 | | - if os.path.exists(os.path.join(_dir, "..", "..", ".git")): |
| 23 | + if os.path.exists(os.path.join(_root, ".git")): |
21 | 24 | msg += ("Please run git submodule update --init --recursive " + |
22 | 25 | "and then run tests again.") |
23 | 26 | else: |
24 | 27 | msg += ("The testdata doesn't appear to be included with this package, " + |
25 | 28 | "so finding the right version will be hard. :(") |
26 | 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 | + |
27 | 67 | if msgs: |
28 | 68 | pytest.exit("\n".join(msgs)) |
29 | 69 |
|
|
0 commit comments