-
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
122 changed files
with
2,014 additions
and
2,634 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,4 +102,3 @@ ENV/ | |
|
||
# other | ||
*.swp | ||
*.got |
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
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 os | ||
import pytest | ||
|
||
import nested_diff | ||
|
||
|
||
def do_test_function(test, func): | ||
if 'diff' not in test: | ||
print(nested_diff.diff(test['a'], test['b'])) | ||
|
||
if 'raises' in test: | ||
with test['raises']: | ||
func(test) | ||
else: | ||
assert test['result'] == 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']) | ||
|
||
if 'result' in test or 'raises' in test: | ||
marks = [] | ||
else: | ||
marks = [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='') | ||
""") |
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
Oops, something went wrong.