@@ -343,13 +343,16 @@ def main(suite_name, json_file, waiver_file='waiver.json', output_json_file='tes
343343 print (f"INFO: Failed to read or parse { waiver_file } : { e } " )
344344 return
345345
346- # Load test_category.json
347- try :
348- with open (output_json_file , 'r' ) as f :
349- output_json_data = json .load (f )
350- except Exception as e :
351- print (f"WARNING: Failed to read or parse { output_json_file } : { e } " )
352- return
346+ # Load test_category.json if provided
347+ if output_json_file :
348+ try :
349+ with open (output_json_file , 'r' ) as f :
350+ output_json_data = json .load (f )
351+ except Exception as e :
352+ print (f"WARNING: Failed to read or parse { output_json_file } : { e } " )
353+ output_json_data = None
354+ else :
355+ output_json_data = None
353356
354357 # Get waivers for the suite, categorized by their scope
355358 suite_level_waivers , testsuite_level_waivers , subsuite_level_waivers , testcase_level_waivers , subtest_level_waivers = load_waivers (waiver_data , suite_name )
@@ -368,7 +371,8 @@ def main(suite_name, json_file, waiver_file='waiver.json', output_json_file='tes
368371 elif isinstance (json_data , dict ):
369372 test_suite_entries = [json_data ]
370373 else :
371- print (f"ERROR: Unexpected JSON data structure in { json_file } " )
374+ if verbose :
375+ print (f"ERROR: Unexpected JSON data structure in { json_file } " )
372376 return
373377
374378 # Process each test suite in the JSON data
@@ -377,22 +381,27 @@ def main(suite_name, json_file, waiver_file='waiver.json', output_json_file='tes
377381 if not test_suite_name :
378382 continue # Skip entries that are not test suites
379383
380- # Check if the test suite is waivable according to test_category.json
381- waivable = False
382- for catID , catData in output_json_data .items ():
383- for suiteID , suiteData in catData .items ():
384- for sname_key , sname_value in suiteData .items ():
385- if sname_key .startswith ('SName:' ) and sname_key == f'SName: { suite_name } ' :
386- ts_list = sname_value # This is a list
387- for ts_entry in ts_list :
388- if ts_entry .get ('TSName' ).lower () == test_suite_name .lower ():
389- if ts_entry .get ('Waivable' , '' ).lower () == 'yes' :
390- waivable = True
391- break # Found a waivable test suite, exit the loops
392- if waivable :
393- break
394- if waivable :
395- break
384+ # Determine if waivers should be applied based on test_category.json
385+ if output_json_data is None :
386+ # test_category.json not provided, apply all waivers
387+ waivable = True
388+ else :
389+ # Check if the test suite is waivable according to test_category.json
390+ waivable = False
391+ for catID , catData in output_json_data .items ():
392+ for suiteID , suiteData in catData .items ():
393+ for sname_key , sname_value in suiteData .items ():
394+ if sname_key .startswith ('SName:' ) and sname_key == f'SName: { suite_name } ' :
395+ ts_list = sname_value # This is a list
396+ for ts_entry in ts_list :
397+ if ts_entry .get ('TSName' ).lower () == test_suite_name .lower ():
398+ if ts_entry .get ('Waivable' , '' ).lower () == 'yes' :
399+ waivable = True
400+ break # Found a waivable test suite, exit the loops
401+ if waivable :
402+ break
403+ if waivable :
404+ break
396405
397406 if not waivable :
398407 # Do not process non-waivable test suites
@@ -483,14 +492,21 @@ def main(suite_name, json_file, waiver_file='waiver.json', output_json_file='tes
483492 print (f"ERROR: Failed to write updated data to { json_file } : { e } " )
484493 return
485494
486- if __name__ == '__main__' :
487- if len (sys .argv ) < 3 or len (sys .argv ) > 5 :
488- print ("Usage: apply_waivers.py <suite_name> <json_file> [waiver.json] [test_category.json]" )
489- sys .exit (1 )
495+ def main ():
496+ parser = argparse .ArgumentParser (description = 'Apply waivers to test suite JSON results.' )
497+ parser .add_argument ('suite_name' , help = 'Name of the test suite' )
498+ parser .add_argument ('json_file' , help = 'Path to the JSON file' )
499+ parser .add_argument ('waiver_file' , nargs = '?' , default = 'waiver.json' , help = 'Path to the waiver file (default: waiver.json)' )
500+ parser .add_argument ('output_json_file' , nargs = '?' , default = None , help = 'Path to the test category file (default: None)' )
501+ parser .add_argument ('--quiet' , action = 'store_true' , help = 'Suppress detailed output' )
502+ args = parser .parse_args ()
490503
491- suite_name = sys .argv [1 ]
492- json_file = sys .argv [2 ]
493- waiver_file = sys .argv [3 ] if len (sys .argv ) >= 4 else 'waiver.json'
494- output_json_file = sys .argv [4 ] if len (sys .argv ) == 5 else 'test_category.json'
504+ # Set the global verbosity flag
505+ global verbose
506+ verbose = not args .quiet
495507
496- main (suite_name , json_file , waiver_file , output_json_file )
508+ # Now call the apply_waivers function
509+ apply_waivers (args .suite_name , args .json_file , args .waiver_file , args .output_json_file )
510+
511+ if __name__ == '__main__' :
512+ main ()
0 commit comments