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