@@ -47,8 +47,10 @@ def submit_image(result: TestResult, hardware: str, timestamp: str, file: str,
4747 Submits a new candidate image to the provided URL. This function logs a method
4848 indicating whether the image submission succeeded
4949 """
50+ f = open (file , "rb" )
5051 res = requests .post (
5152 url ,
53+ timeout = 30 ,
5254 data = {
5355 "group" : result .group ,
5456 "name" : result .name ,
@@ -59,7 +61,7 @@ def submit_image(result: TestResult, hardware: str, timestamp: str, file: str,
5961 "commitHash" : result .commit
6062 },
6163 files = {
62- "file" : open ( file , "rb" ) ,
64+ "file" : f ,
6365 "log" : result .error
6466 }
6567 )
@@ -68,6 +70,7 @@ def submit_image(result: TestResult, hardware: str, timestamp: str, file: str,
6870 print (res .text )
6971 else :
7072 print ("Image submitted successfully" )
73+ f .close ()
7174
7275
7376
@@ -132,80 +135,88 @@ def setup_argparse():
132135 return args
133136
134137
138+ if __name__ == "__main__" :
139+ global_start = time .perf_counter ()
140+ if os .path .exists ("config.json" ):
141+ submit_images = True
142+ with open ("config.json" ) as f :
143+ config = json .load (f )
144+ url = config ["url" ]
145+ submit_url = f"{ url } /api/submit-test"
146+ hardware = config ["hardware" ]
147+ runner_id = config ["id" ]
148+ else :
149+ print ("No 'config.json' provided. Test results will be stored locally instead" )
150+ submit_images = False
151+
152+
153+ args = setup_argparse ()
135154
136- global_start = time .perf_counter ()
137- if os .path .exists ("config.json" ):
138- submit_images = True
139- with open ("config.json" ) as f :
140- config = json .load (f )
141- url = config ["url" ]
142- submit_url = f"{ url } /api/submit-test"
143- hardware = config ["hardware" ]
144- runner_id = config ["id" ]
145- else :
146- print ("No 'config.json' provided. Test results will be stored locally instead" )
147- submit_images = False
148-
149-
150- args = setup_argparse ()
151-
152- # Find the executable location and its name
153- if os .name == "nt" :
154- # Windows
155- executable = f"{ args .dir } /bin/RelWithDebInfo/OpenSpace.exe"
156- else :
157- # Linux/Mac
158- executable = f"{ args .dir } /bin/OpenSpace"
159-
160- if not os .path .exists (executable ):
161- raise Exception (f"Could not find executable '{ executable } '" )
162-
163-
164- if args .overwrite_path != None :
165- write_configuration_overwrite (args .dir , args .overwrite_path )
166-
167-
168-
169- # Running the tests
170- if args .test is None :
171- print ("Running all tests in OpenSpace folder" )
172- files = glob .glob (f"{ args .dir } /{ test_base_dir } /**/*.ostest" , recursive = True )
173- for file in files :
174- # Normalize the path endings to always do forward slashes
175- file = file .replace (os .sep , "/" )
176- timestamp = datetime .datetime .now (datetime .timezone .utc ).isoformat ()
177- if args .dry_run :
178- print (f"Test: '{ file } ' run against executable '{ executable } '" )
179- continue
180-
181- result = run_single_test (file , executable )
182- for file in result .files :
183- if submit_images :
184- submit_image (result , hardware , timestamp , file , runner_id , submit_url )
185- else :
186- store_image (result , file )
187- time .sleep (5.0 )
188- else :
189- tests = args .test .split ("," )
190- print (f"Running tests: { tests } " )
191- for test in tests :
192- path = f"{ args .dir } /{ test_base_dir } /{ test } .ostest"
193- if not os .path .isfile (path ):
194- raise Exception (f"Could not find test '{ path } '" )
195-
196- timestamp = datetime .datetime .now (datetime .timezone .utc ).isoformat ()
197-
198- if args .dry_run :
199- print (f"Test: '{ path } ' run against executable '{ executable } '" )
200- continue
201-
202- result = run_single_test (path , executable )
203- for file in result .files :
204- if submit_images :
205- submit_image (result , hardware , timestamp , file , runner_id , submit_url )
206- else :
207- store_image (result , file )
208- time .sleep (5.0 )
209-
210- global_end = time .perf_counter ()
211- print (f"Total time for all tests: { global_end - global_start } " )
155+ # Find the executable location and its name
156+ if os .name == "nt" :
157+ # Windows
158+ executable = f"{ args .dir } /bin/RelWithDebInfo/OpenSpace.exe"
159+ else :
160+ # Linux
161+ executable = f"{ args .dir } /bin/OpenSpace"
162+
163+ if not os .path .exists (executable ):
164+ raise Exception (f"Could not find executable '{ executable } '" )
165+
166+
167+ if args .overwrite_path != None :
168+ write_configuration_overwrite (args .dir , args .overwrite_path )
169+
170+
171+
172+ # Running the tests
173+ if args .test is None :
174+ print ("Running all tests in OpenSpace folder" )
175+ files = glob .glob (f"{ args .dir } /{ test_base_dir } /**/*.ostest" , recursive = True )
176+ for file in files :
177+ # Normalize the path endings to always do forward slashes
178+ file = file .replace (os .sep , "/" )
179+ timestamp = datetime .datetime .now (datetime .timezone .utc ).isoformat ()
180+ if args .dry_run :
181+ print (f"Test: '{ file } ' run against executable '{ executable } '" )
182+ continue
183+
184+ try :
185+ result = run_single_test (file , executable )
186+ except Exception as e :
187+ print (f"Test '{ file } ' failed with error: { e } " )
188+ continue
189+ for img in result .files :
190+ if submit_images :
191+ submit_image (result , hardware , timestamp , img , runner_id , submit_url )
192+ else :
193+ store_image (result , img )
194+ time .sleep (5.0 )
195+ else :
196+ tests = args .test .split ("," )
197+ print (f"Running tests: { tests } " )
198+ for test in tests :
199+ path = f"{ args .dir } /{ test_base_dir } /{ test } .ostest"
200+ if not os .path .isfile (path ):
201+ raise Exception (f"Could not find test '{ path } '" )
202+
203+ timestamp = datetime .datetime .now (datetime .timezone .utc ).isoformat ()
204+
205+ if args .dry_run :
206+ print (f"Test: '{ path } ' run against executable '{ executable } '" )
207+ continue
208+
209+ try :
210+ result = run_single_test (path , executable )
211+ except Exception as e :
212+ print (f"Test '{ path } ' failed with error: { e } " )
213+ continue
214+ for file in result .files :
215+ if submit_images :
216+ submit_image (result , hardware , timestamp , file , runner_id , submit_url )
217+ else :
218+ store_image (result , file )
219+ time .sleep (5.0 )
220+
221+ global_end = time .perf_counter ()
222+ print (f"Total time for all tests: { global_end - global_start } " )
0 commit comments