-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Surgically remove the notion of suites
- Loading branch information
1 parent
9ea5c7c
commit b889ff1
Showing
6 changed files
with
72 additions
and
105 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
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 |
---|---|---|
@@ -1,66 +1,51 @@ | ||
import importlib | ||
import os | ||
import subprocess | ||
|
||
import trio | ||
|
||
from lib.console import ConsoleWriter | ||
|
||
TESTS_DIR = 'scripts' | ||
|
||
def script_to_module(script): | ||
return script.replace('/', '.')[0:-3] | ||
|
||
|
||
def script_to_test(script): | ||
remove_prefix_suffix = script[8:len(script) - 3] | ||
return remove_prefix_suffix.replace('/', '.') | ||
|
||
|
||
def run_script(script, args, cw): | ||
script_list = ['python3', '-m', script_to_module(script)] | ||
arg_list = [item for sublist in [['--' + k, v] for k, v in args.items()] for item in sublist] | ||
def all_test_files(): | ||
tests = [] | ||
for root, dirs, files in os.walk(TESTS_DIR): | ||
# skip files in top-level | ||
if root == 'scripts': | ||
continue | ||
|
||
output = subprocess.run( | ||
script_list + arg_list, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
text=True | ||
) | ||
tests.extend([f'{root}/{f}' for f in files if f.endswith('.py')]) | ||
|
||
if len(output.stderr) > 0: | ||
cw.fail('FAILED') | ||
cw.info(output.stderr) | ||
return tests | ||
|
||
else: | ||
cw.success('SUCCESS') | ||
def file_to_module(script): | ||
return script.replace('/', '.')[0:-3] | ||
|
||
|
||
def run_module(module, args, cw): | ||
module = importlib.import_module(module) | ||
# TODO: add args back in | ||
def run_module(module, cw): | ||
print(f'Running module: {module}') | ||
#module = importlib.import_module(module) | ||
|
||
if not hasattr(module, 'run'): | ||
cw.fail(f'module {module} does not have a run method') | ||
return | ||
#if not hasattr(module, 'run'): | ||
#cw.fail(f'module {module} does not have a run method') | ||
#return | ||
|
||
return_code = trio.run(module.run, args) | ||
if return_code == 0: | ||
cw.success('SUCCESS') | ||
#return_code = trio.run(module.run, args) | ||
#if return_code == 0: | ||
#cw.success('SUCCESS') | ||
|
||
else: | ||
cw.fail('FAILED') | ||
#else: | ||
#cw.fail('FAILED') | ||
|
||
|
||
def test_matches_filter(test, test_filter): | ||
return test_filter is None or test == test_filter or test.startswith(test_filter) | ||
|
||
|
||
def run_test_config(test_config, cw=ConsoleWriter(None, None, None), test_filter=None): | ||
tests = test_config['test_suite'] | ||
|
||
for test in tests: | ||
if test_matches_filter(test['name'], test_filter): | ||
script = test['script'] | ||
args = test['args'] | ||
return test_filter is None or test == test_filter | ||
|
||
cw = cw._replace(test=script_to_test(script)) | ||
def run_all_tests(cw=ConsoleWriter(None, None), test_filter=None): | ||
for test_file in all_test_files(): | ||
if test_matches_filter(test_file, test_filter): | ||
cw = cw._replace(test=file_to_module(test_file)) | ||
|
||
run_module(script_to_module(script), args, cw) | ||
run_module(file_to_module(test_file), cw) |
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