|
43 | 43 | # 'test_' and end with '.py'. A shell-style wildcard is used with glob() to
|
44 | 44 | # match desired filenames. All the tests matching the pattern will be loaded
|
45 | 45 | # and run in a test suite.
|
46 |
| -tests_list = glob.glob('test_*.py') |
| 46 | +available_tests = glob.glob('test_*.py') |
47 | 47 |
|
48 | 48 | # A dictionary of test modules that should only run in certain python versions.
|
49 | 49 | # Carefully consider the impact of only testing these in a given version.
|
50 | 50 | # test_proxy_use.py: uses a proxy that only runs in Python2.7. TUF's
|
51 | 51 | # compatibility with proxies is not likely to vary based on the Python version
|
52 | 52 | # in use, so this is OK for now. See comments in that module.
|
53 |
| -# The format here is: if major is included, limit version to that listed here. |
54 |
| -# If minor is included, limit version to that listed here. Skip the test if any |
55 |
| -# such listed constraints don't match the python version currently running. |
| 53 | +# The semantics here are: only add to this list the particular tests that are |
| 54 | +# to be run in a single major version or a single minor version. An entry must |
| 55 | +# include major version, and may include minor version. |
| 56 | +# Skip the test if any such listed constraints don't match the python version |
| 57 | +# currently running. |
| 58 | +# Note that aggregate_tests.py is run for each version of Python that tox is |
| 59 | +# configured to use. Note also that this TUF implementation does not support |
| 60 | +# any Python versions <2.7 or any Python3 versions <3.4. |
56 | 61 | VERSION_SPECIFIC_TESTS = {
|
57 | 62 | 'test_proxy_use': {'major': 2, 'minor': 7}} # Run test only if Python2.7
|
| 63 | +# Further example: |
| 64 | +# 'test_abc': {'major': 2} # Run test only if Python2 |
58 | 65 |
|
59 |
| -# Remove '.py' from each filename to allow loadTestsFromNames() (called below) |
60 |
| -# to properly load the file as a module. |
61 |
| -tests_without_extension = [] |
62 |
| -for test in tests_list: |
| 66 | +# Determine which tests should be run. |
| 67 | +test_modules_to_run = [] |
| 68 | +for test in available_tests: |
| 69 | + # Remove '.py' from each filename to allow loadTestsFromNames() (called below) |
| 70 | + # to properly load the file as a module. |
| 71 | + assert test[-3:] == '.py', 'aggregate_tests.py is inconsistent; fix.' |
63 | 72 | test = test[:-3]
|
| 73 | + |
64 | 74 | if test in VERSION_SPECIFIC_TESTS:
|
65 |
| - if 'major' in VERSION_SPECIFIC_TESTS[test] \ |
66 |
| - and sys.version_info.major != VERSION_SPECIFIC_TESTS[test]['major']: |
| 75 | + # Consistency checks. |
| 76 | + assert 'major' in VERSION_SPECIFIC_TESTS[test], 'Empty/illogical constraint' |
| 77 | + for keyword in VERSION_SPECIFIC_TESTS[test]: |
| 78 | + assert keyword in ['major', 'minor'], 'Unrecognized test constraint' |
| 79 | + |
| 80 | + if sys.version_info.major != VERSION_SPECIFIC_TESTS[test]['major']: |
67 | 81 | continue
|
68 |
| - elif 'minor' in VERSION_SPECIFIC_TESTS[test] \ |
| 82 | + if 'minor' in VERSION_SPECIFIC_TESTS[test] \ |
69 | 83 | and sys.version_info.minor != VERSION_SPECIFIC_TESTS[test]['minor']:
|
70 | 84 | continue
|
71 |
| - tests_without_extension.append(test) |
| 85 | + test_modules_to_run.append(test) |
72 | 86 |
|
73 | 87 | # Randomize the order in which the tests run. Randomization might catch errors
|
74 | 88 | # with unit tests that do not properly clean up or restore monkey-patched
|
75 | 89 | # modules.
|
76 |
| -random.shuffle(tests_without_extension) |
| 90 | +random.shuffle(test_modules_to_run) |
77 | 91 |
|
78 | 92 | if __name__ == '__main__':
|
79 |
| - suite = unittest.TestLoader().loadTestsFromNames(tests_without_extension) |
| 93 | + suite = unittest.TestLoader().loadTestsFromNames(test_modules_to_run) |
80 | 94 | all_tests_passed = unittest.TextTestRunner(verbosity=1).run(suite).wasSuccessful()
|
81 | 95 | if not all_tests_passed:
|
82 | 96 | sys.exit(1)
|
|
0 commit comments