Skip to content

Commit cff7576

Browse files
committed
9pm.py: redesign 9pm project config handling
It was a mistake to use -c (config), that config is intended solely for the test case. It should really be named NINEPM_TEST_CONFIG and not NINEPM_CONFIG. It's intended to make the test dynamic. For example, the same test could be executed twice with different configurations to test slightly different things. The project config however is different. It shall only contain project static data. Such as the project name. It's passed to test cases as well, so a user could add additional top level data intended for the test cases. Such as default user credentials for the project. Signed-off-by: Richard Alpe <[email protected]>
1 parent 199d4ab commit cff7576

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

9pm.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -537,12 +537,15 @@ def run_suite(cmdline, data, skip_suite):
537537

538538
return skip, err
539539

540-
def parse_config(root_path, config_file):
540+
def parse_proj_config(root_path, config_file):
541541
files = [
542-
os.path.join(root_path, '..', '9pm.yaml'),
543-
os.path.join(root_path, 'etc', '9pm.yaml')
542+
os.path.join(root_path, '..', '9pm-proj.yaml'),
543+
os.path.join(root_path, 'etc', '9pm-proj.yaml')
544544
]
545545

546+
if "NINEPM_PROJ_CONFIG" in os.environ:
547+
files.insert(0, os.environ["NINEPM_PROJ_CONFIG"])
548+
546549
path = next((os.path.expanduser(f) for f in files if os.path.exists(os.path.expanduser(f))), None)
547550

548551
if config_file:
@@ -553,10 +556,11 @@ def parse_config(root_path, config_file):
553556
path = config_file
554557

555558
if path:
556-
cprint(pcolor.faint, f"Using Config: {path}")
559+
cprint(pcolor.faint, f"Using Project Config: {path}")
560+
os.environ["NINEPM_PROJ_CONFIG"] = path
557561
else:
558-
print("Running without config")
559-
return
562+
print("error, can't find any 9pm project config")
563+
sys.exit(1)
560564

561565
try:
562566
with open(path, 'r') as f:
@@ -570,7 +574,6 @@ def parse_config(root_path, config_file):
570574
return []
571575

572576
def parse_rc(root_path):
573-
rc = {}
574577
required_keys = ["LOG_PATH"]
575578

576579
files = [
@@ -603,6 +606,8 @@ def parse_cmdline():
603606
parser = argparse.ArgumentParser()
604607
parser.add_argument('-a', '--abort', action='store_true',
605608
help='(9PM) Abort execution if test fails')
609+
parser.add_argument('-p', '--proj', metavar='FILE', action='store',
610+
help='(9PM) Path to project configuration')
606611
parser.add_argument('-c', '--config', metavar='FILE', action='store',
607612
help='(TEST) Config file passed to test case')
608613
parser.add_argument('-d', '--debug', action='store_true',
@@ -678,12 +683,12 @@ def main():
678683

679684
args = parse_cmdline()
680685

681-
config = parse_config(ROOT_PATH, args.config)
686+
proj = parse_proj_config(ROOT_PATH, args.proj)
682687

683-
if 'PROJECT-NAME' in config:
684-
str = f"\nTesting {config['PROJECT-NAME']}"
685-
if 'PROJECT-ROOT' in config:
686-
str += f" ({run_git_cmd(config['PROJECT-ROOT'], ['rev-parse', 'HEAD'])[:12]})"
688+
if 'PROJECT-NAME' in proj:
689+
str = f"\nTesting {proj['PROJECT-NAME']}"
690+
if 'PROJECT-ROOT' in proj:
691+
str += f" ({run_git_cmd(proj['PROJECT-ROOT'], ['rev-parse', 'HEAD'])[:12]})"
687692
cprint(pcolor.yellow, str)
688693

689694
scratch = tempfile.mkdtemp(suffix='', prefix='9pm_', dir='/tmp')
@@ -729,7 +734,7 @@ def main():
729734
print_result_tree(cmdl, "")
730735
write_md_result(cmdl)
731736
write_github_result(cmdl)
732-
write_report(cmdl, config)
737+
write_report(cmdl, proj)
733738

734739
db.close()
735740
sys.exit(err)

etc/9pm.yaml renamed to etc/9pm-proj.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# This is the default config for 9pm and its test cases.
1+
# This is the default project config for 9pm.
22
# The top level "9pm" contains data aimed for the 9pm.py test executor.
3-
# This file is passed down to test cases as the env variable NINEPM_CONFIG.
3+
# This file is passed down to test cases as the env variable NINEPM_PROJ_CONFIG.
44

55
9pm:
66
PROJECT-NAME: "9pm"

0 commit comments

Comments
 (0)