@@ -346,12 +346,12 @@ def write_report_output(file, data, depth):
346346 if 'suite' in test :
347347 write_report_output (file , test , depth + 1 )
348348
349- def write_report_parent_info (file , rc ):
350- if 'PARENT_PROJECT_NAME ' not in rc or 'PARENT_PROJECT_ROOT ' not in rc :
349+ def write_report_project_info (file , config ):
350+ if 'PROJECT-NAME ' not in config or 'PROJECT-ROOT ' not in config :
351351 return None
352352
353- name = rc [ 'PARENT_PROJECT_NAME ' ]
354- root = rc [ 'PARENT_PROJECT_ROOT ' ]
353+ name = config [ 'PROJECT-NAME ' ]
354+ root = config [ 'PROJECT-ROOT ' ]
355355 version = run_git_cmd (root , ["describe" , "--tags" , "--always" ])
356356 sha = run_git_cmd (root , ['rev-parse' , 'HEAD' ])[:12 ]
357357
@@ -364,10 +364,10 @@ def write_report_parent_info(file, rc):
364364
365365 file .write ("|===\n " )
366366
367- def write_report (data , rc ):
367+ def write_report (data , config ):
368368 with open (os .path .join (LOGDIR , 'report.adoc' ), 'a' ) as file :
369369 current_date = datetime .now ().strftime ("%Y-%m-%d" )
370- name = rc [ 'PARENT_PROJECT_NAME ' ] if 'PARENT_PROJECT_NAME ' in rc else "9pm"
370+ name = config [ 'PROJECT-NAME ' ] if 'PROJECT-NAME ' in config else "9pm"
371371
372372 file .write (f"= { name } Test Report\n " )
373373 file .write ("Author: 9pm Test Framework\n " )
@@ -379,7 +379,7 @@ def write_report(data, rc):
379379
380380 file .write ("\n <<<\n " )
381381 file .write ("\n == Test Summary\n \n " )
382- write_report_parent_info (file , rc )
382+ write_report_project_info (file , config )
383383
384384 file .write ("\n <<<\n " )
385385 file .write ("\n == Test Result\n \n " )
@@ -537,20 +537,46 @@ def run_suite(cmdline, data, skip_suite):
537537
538538 return skip , err
539539
540+ def parse_config (root_path , config_file ):
541+ files = [
542+ os .path .join (root_path , '..' , '9pm.yaml' ),
543+ os .path .join (root_path , 'etc' , '9pm.yaml' )
544+ ]
545+
546+ path = next ((os .path .expanduser (f ) for f in files if os .path .exists (os .path .expanduser (f ))), None )
547+
548+ if config_file :
549+ if not os .path .exists (config_file ):
550+ print (f"error, config file \" { config_file } \" not found." )
551+ sys .exit (1 )
552+
553+ path = config_file
554+
555+ if path :
556+ cprint (pcolor .faint , f"Using Config: { path } " )
557+ else :
558+ print ("Running without config" )
559+ return
560+
561+ try :
562+ with open (path , 'r' ) as f :
563+ data = yaml .safe_load (f ) or {}
564+ except yaml .YAMLError :
565+ print (f"error, parsing YAML { path } config." )
566+ sys .exit (1 )
567+
568+ if '9pm' in data :
569+ return data ['9pm' ]
570+ return []
571+
540572def parse_rc (root_path ):
541573 rc = {}
542574 required_keys = ["LOG_PATH" ]
543- voluntary_keys = [
544- "PARENT_PROJECT_NAME" ,
545- "PARENT_PROJECT_ROOT" ,
546- ]
547575
548576 files = [
549- os .path .join (root_path , '..' , '9pm.rc' ),
550577 os .path .join ("~/.9pm.rc" ),
551578 os .path .join (root_path , 'etc' , '9pm.rc' )
552579 ]
553-
554580 path = next ((os .path .expanduser (f ) for f in files if os .path .exists (os .path .expanduser (f ))), None )
555581
556582 if path :
@@ -571,11 +597,6 @@ def parse_rc(root_path):
571597 print (f"error, 9pm.rc is missing required keys: { ', ' .join (missing_keys )} " )
572598 sys .exit (1 )
573599
574- allowed_keys = set (required_keys + voluntary_keys )
575- unsupported_keys = [key for key in data if key not in allowed_keys ]
576- if unsupported_keys :
577- print (f"warning, 9pm.rc contains unsupported keys: { ', ' .join (unsupported_keys )} " )
578-
579600 return data
580601
581602def parse_cmdline ():
@@ -655,14 +676,16 @@ def main():
655676
656677 LOGDIR = setup_log_dir (rc ['LOG_PATH' ])
657678
658- if 'PARENT_PROJECT_NAME' in rc :
659- str = f"\n Testing { rc ['PARENT_PROJECT_NAME' ]} "
660- if 'PARENT_PROJECT_ROOT' in rc :
661- str += f" ({ run_git_cmd (rc ['PARENT_PROJECT_ROOT' ], ['rev-parse' , 'HEAD' ])[:12 ]} )"
662- cprint (pcolor .yellow , str )
663-
664679 args = parse_cmdline ()
665680
681+ config = parse_config (ROOT_PATH , args .config )
682+
683+ if 'PROJECT-NAME' in config :
684+ str = f"\n Testing { config ['PROJECT-NAME' ]} "
685+ if 'PROJECT-ROOT' in config :
686+ str += f" ({ run_git_cmd (config ['PROJECT-ROOT' ], ['rev-parse' , 'HEAD' ])[:12 ]} )"
687+ cprint (pcolor .yellow , str )
688+
666689 scratch = tempfile .mkdtemp (suffix = '' , prefix = '9pm_' , dir = '/tmp' )
667690 if args .debug :
668691 print ("Created scratch dir:" , scratch )
@@ -706,7 +729,7 @@ def main():
706729 print_result_tree (cmdl , "" )
707730 write_md_result (cmdl )
708731 write_github_result (cmdl )
709- write_report (cmdl , rc )
732+ write_report (cmdl , config )
710733
711734 db .close ()
712735 sys .exit (err )
0 commit comments