-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
118 changed files
with
1,897 additions
and
2,595 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import contextlib | ||
import os | ||
import pytest | ||
|
||
|
||
def do_test_function(test, func): | ||
with test['raises']: | ||
assert test.get('result', None) == func(test) | ||
|
||
|
||
def iterate_test_suite(tests_map, results_mod, func): | ||
results_map = {} if 'CANONIZE' in os.environ else results_mod.RESULTS | ||
|
||
for name, test in sorted(tests_map.items()): | ||
if 'CANONIZE' in os.environ: | ||
try: | ||
test['result'] = func(test) | ||
results_map[name] = {'result': test['result']} | ||
except Exception as e: | ||
results_map[name] = { | ||
'raises': e if type(e) is type else type(e), | ||
} | ||
else: | ||
try: | ||
test['result'] = results_map[name]['result'] | ||
except KeyError: | ||
test['raises'] = pytest.raises(results_map[name]['raises']) | ||
|
||
marks = [] | ||
if 'raises' not in test: | ||
test['raises'] = pytest_param_does_not_raise() | ||
if 'result' not in test: | ||
test['result'] = None | ||
marks.append(pytest.mark.xfail) | ||
|
||
yield pytest.param(test, func, id=name, marks=marks) | ||
|
||
if 'CANONIZE' in os.environ: | ||
save_test_suite(results_mod.__file__, results_map) | ||
|
||
|
||
def save_test_suite(filename, results): | ||
with open(filename, 'w') as f: | ||
f.write('''""" | ||
Autogenerated, do not edit manually! | ||
""" | ||
import sys | ||
RESULTS = { | ||
''') | ||
|
||
for k, v in sorted(results.items()): | ||
t = 'result' if 'result' in v else 'raises' | ||
if 'raises' in v: | ||
t = 'raises' | ||
r = v['raises'].__name__ | ||
else: | ||
t = 'result' | ||
r = repr(v['result']) | ||
|
||
f.write("""\ | ||
'{name}': {{ | ||
'{type}': {result}, | ||
}}, | ||
""".format(name=k, type=t, result=r)) | ||
|
||
f.write("""} | ||
if __name__ == '__main__': | ||
names = sys.argv[1:] if len(sys.argv) > 1 else sorted(RESULTS.keys()) | ||
headers = len(names) > 1 | ||
for name in names: | ||
if headers: | ||
print('========== ' + name + ' ==========') | ||
print(RESULTS[name].get('result', None), end='') | ||
""") | ||
|
||
|
||
@contextlib.contextmanager | ||
def pytest_param_does_not_raise(): | ||
yield |
Oops, something went wrong.