|
4 | 4 | import yaml |
5 | 5 |
|
6 | 6 | # These tests assumes the green-metrics-tool directory lives side by side with the examples-repository |
7 | | -current_dir = os.path.dirname(os.path.abspath(__file__)) |
8 | | -sys.path.append(f"{current_dir}/../../green-metrics-tool") |
9 | | -sys.path.append(f"{current_dir}/../../green-metrics-tool/tools") |
10 | | -sys.path.append(f"{current_dir}/../../green-metrics-tool/lib") |
| 7 | +CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 8 | +ROOT_DIR = os.path.abspath(f"{CURRENT_DIR}/../") |
| 9 | +sys.path.append(f"{CURRENT_DIR}/../../green-metrics-tool") |
| 10 | +sys.path.append(f"{CURRENT_DIR}/../../green-metrics-tool/tools") |
| 11 | +sys.path.append(f"{CURRENT_DIR}/../../green-metrics-tool/lib") |
11 | 12 |
|
12 | 13 | from runner import Runner |
13 | 14 | from global_config import GlobalConfig |
|
20 | 21 |
|
21 | 22 | def example_directories(): |
22 | 23 | example_dirs = [] |
23 | | - root = f"{current_dir}/../" |
24 | | - |
25 | | - for path, directories, files in os.walk(root): |
| 24 | + for path, directories, files in os.walk(ROOT_DIR): |
26 | 25 | dirname = path.split(os.path.sep)[-1] |
27 | | - if path == root or '.scantest' in files: |
| 26 | + if path == ROOT_DIR or '.scantest' in files: |
28 | 27 | continue |
29 | 28 | if '.skiptest' in files or dirname.startswith("."): |
30 | 29 | directories.clear() |
31 | 30 | continue |
32 | | - example_dirs.append(os.path.abspath(path)) |
| 31 | + print(os.path.abspath(path)) |
| 32 | + repo_path = os.path.abspath(path) |
| 33 | + repo_path_rel = repo_path[len(ROOT_DIR)+1:] |
| 34 | + example_dirs.append(repo_path_rel) |
33 | 35 | directories.clear() |
34 | | - |
35 | 36 | return example_dirs |
36 | 37 |
|
37 | | -def run_test_on_directory(directory, capsys, skip_unsafe=False): |
| 38 | +def run_test_on_directory(directory, capsys): |
38 | 39 | name = f"test_{utils.randomword(12)}" |
39 | 40 |
|
40 | 41 | # Run the application |
41 | | - runner = Runner(name=name, uri=directory, uri_type="folder", dev_no_build=True, skip_unsafe=skip_unsafe, skip_system_checks=True) |
| 42 | + runner = Runner(name=name, uri=ROOT_DIR, filename=f"{directory}/usage_scenario.yml", uri_type="folder", dev_no_build=True, dev_no_sleeps=True, skip_unsafe=True, skip_system_checks=True) |
42 | 43 | runner.run() |
43 | 44 |
|
44 | 45 | # Capture Std.Out and Std.Err and make Assertions |
@@ -99,31 +100,11 @@ def recursive_lookup(k, d): |
99 | 100 |
|
100 | 101 | Loader.add_constructor('!include', Loader.include) |
101 | 102 |
|
102 | | -def check_for_ports(directory): |
103 | | - if os.path.exists(f"{directory}/usage_scenario.yml"): |
104 | | - with open(f"{directory}/usage_scenario.yml", encoding='utf8') as f: |
105 | | - usage_scenario = yaml.load(f, Loader=Loader) |
106 | | - if 'services' in usage_scenario: |
107 | | - for service in usage_scenario['services']: |
108 | | - if 'ports' in usage_scenario['services'][service]: |
109 | | - return True |
110 | | - |
111 | | - if os.path.exists(f"{directory}/compose.yml"): |
112 | | - with open(f"{directory}/compose.yml", encoding='utf8') as f: |
113 | | - compose_yml = yaml.load(f, Loader=Loader) |
114 | | - if 'services' in compose_yml: |
115 | | - for service in compose_yml['services']: |
116 | | - if 'ports' in compose_yml['services'][service]: |
117 | | - return True |
118 | | - return False |
119 | | - |
120 | 103 | @pytest.mark.parametrize("example_directory", example_directories()) |
121 | 104 | def test_all_directories(example_directory, capsys): |
122 | | - skip_unsafe = check_for_ports(example_directory) |
123 | | - run_test_on_directory(example_directory, capsys, skip_unsafe=skip_unsafe) |
| 105 | + run_test_on_directory(example_directory, capsys) |
124 | 106 |
|
| 107 | +# Trigger a single test by supplying --name "my_directory" for this one |
125 | 108 | def test_a_directory(name, capsys): |
126 | | - uri = os.path.abspath(f"{current_dir}/../{name}") |
127 | | - skip_unsafe = check_for_ports(uri) |
128 | | - run_test_on_directory(uri, capsys, skip_unsafe=skip_unsafe) |
| 109 | + run_test_on_directory(name, capsys) |
129 | 110 |
|
0 commit comments