Skip to content

Commit 6626ec1

Browse files
authored
Merge pull request #694 from macgyver13/local-test-runner
Add Local Test Runner Script
2 parents 20dd9fd + 06f167a commit 6626ec1

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

test/local_test_runner.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env python
2+
import subprocess
3+
import sys
4+
5+
import yaml
6+
7+
# developers can use this tool to verify all repo workflow test execute to completion
8+
#
9+
# execute from repo root like this to execute all tests
10+
# python test/local_test_runner.py
11+
#
12+
# add optional argument to just execute any matching tests
13+
# python test/local_test_runner.py [ln_ | graph]
14+
15+
16+
def has_key_path(d, key_path, separator="."):
17+
"""Check if a nested key path (dotted notation) exists in a dictionary."""
18+
keys = key_path.split(separator)
19+
for key in keys:
20+
if not isinstance(d, dict) or key not in d:
21+
return False
22+
d = d[key]
23+
return True
24+
25+
26+
# Load the workflow file
27+
with open(".github/workflows/test.yml") as file:
28+
workflow = yaml.safe_load(file)
29+
30+
tests_total = 0
31+
tests_skipped = 0
32+
tests_completed = 0
33+
34+
for job_details in workflow.get("jobs", {}).values():
35+
if has_key_path(job_details, "strategy.matrix.test"):
36+
print("Found test strategy job, starting serial execution of each test")
37+
tests = job_details["strategy"]["matrix"]["test"]
38+
39+
for test in tests:
40+
tests_total += 1
41+
if len(sys.argv) > 1 and sys.argv[1] not in test:
42+
print("skipping test as requested:", test)
43+
tests_skipped += 1
44+
continue
45+
command = f"python test/{test}"
46+
print(
47+
"###################################################################################################"
48+
)
49+
print("############## executing:", command)
50+
print(
51+
"###################################################################################################"
52+
)
53+
process = subprocess.run(command, shell=True)
54+
if process.returncode != 0:
55+
print("******** testing failed")
56+
if process.stdout:
57+
print("stdout:", process.stdout)
58+
if process.stderr:
59+
print("stderr:", process.stderr)
60+
sys.exit(1)
61+
tests_completed += 1
62+
63+
print(
64+
"###################################################################################################"
65+
)
66+
print("testing complete")
67+
print(f"{tests_completed} of {tests_total} complete - skipped: {tests_skipped} tests")
68+
print(
69+
"###################################################################################################"
70+
)

0 commit comments

Comments
 (0)