Skip to content

Commit ec4d23e

Browse files
committed
9pm.py: redesign handling of included test specifications
Prior to this commit, test specification where copied to the log directory and renamed to there sha1sum. The idea was to avoid needing the source code when generating the final .pdf report (not done by 9pm). However, test specifications rely on included data which also has to be copied, making this solution messy and error prone. In this commit we therefor abandon the idea of copying test specifications to the log directory and instead add them with absolute paths to the report.adoc (which is still located in the log directory). In addition to this we add a new project config variable "PROJECT-TOPDIR" which is intended to specify the root path of the relative test specification files. Example: From included test specification: image::{topdoc}test/case/ietf_system/hostname/topology.svg[] 9pm cloned in: /home/user/foobar/9pm PROJECT-TOPDOC: "../" Resulting image include path (from generated report.adoc): /home/user/foobar/9pm/../test/case/hostname/topology.svg Signed-off-by: Richard Alpe <[email protected]>
1 parent e1ce469 commit ec4d23e

File tree

1 file changed

+32
-21
lines changed

1 file changed

+32
-21
lines changed

9pm.py

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ def vcprint(color, *args, **kwargs):
5252
if VERBOSE:
5353
cprint(color, *args, **kwargs)
5454

55+
def rootify_path(path):
56+
path = os.path.join(ROOT_PATH, path)
57+
path = os.path.expanduser(path)
58+
path = os.path.normpath(path)
59+
return path
60+
5561
def execute(args, test, output_log):
5662
proc = subprocess.Popen([test['case']] + args, stdout=subprocess.PIPE)
5763
skip_suite = False
@@ -325,28 +331,14 @@ def write_report_result_tree(file, includes, data, depth):
325331
string += f" {test['name']}"
326332

327333
# Append (Spec) if there's a test specification
328-
if 'test-spec' in test:
329-
if test['test-spec-sha'] not in includes:
330-
includes.append(test['test-spec-sha'])
331-
332-
include_dir = os.path.join(LOGDIR, "report-incl")
333-
os.makedirs(include_dir, exist_ok=True)
334-
# We ignore potential overwrites
335-
shutil.copy(test['test-spec'], os.path.join(include_dir, test['test-spec-sha']))
336-
334+
if 'test-spec-sha' in test:
337335
string += f" <<incl-{test['test-spec-sha']},(Spec)>>"
338336

339337
file.write(f"{string}\n")
340338

341339
if 'suite' in test:
342340
write_report_result_tree(file, includes, test, depth + 1)
343341

344-
def write_report_includes(file, includes, data, depth):
345-
for sha1sum in includes:
346-
# Note: not having incl- and breaks asciidoctor
347-
file.write(f"\n[[incl-{sha1sum}]]\n")
348-
file.write("include::{}[]\n" . format(os.path.join("report-incl", sha1sum)))
349-
350342
def write_report_output(file, data, depth):
351343
for test in data['suite']:
352344

@@ -364,12 +356,22 @@ def write_report_output(file, data, depth):
364356
if 'suite' in test:
365357
write_report_output(file, test, depth + 1)
366358

359+
def write_report_specifications(file, data, depth):
360+
for test in data['suite']:
361+
362+
if 'test-spec-sha' in test:
363+
file.write(f"\n[[incl-{test['test-spec-sha']}]]\n")
364+
file.write("include::{}[]\n" . format(test['test-spec']))
365+
366+
if 'suite' in test:
367+
write_report_specifications(file, test, depth + 1)
368+
367369
def write_report_project_info(file, config):
368370
if 'PROJECT-NAME' not in config or 'PROJECT-ROOT' not in config:
369371
return None
370372

371373
name = config['PROJECT-NAME']
372-
root = os.path.join(ROOT_PATH, config['PROJECT-ROOT'])
374+
root = config['PROJECT-ROOT']
373375
version = run_git_cmd(root, ["describe", "--tags", "--always"])
374376
sha = run_git_cmd(root, ['rev-parse', 'HEAD'])[:12]
375377

@@ -386,12 +388,14 @@ def write_report(data, config):
386388
with open(os.path.join(LOGDIR, 'report.adoc'), 'a') as file:
387389
current_date = datetime.now().strftime("%Y-%m-%d")
388390
name = config['PROJECT-NAME'] if 'PROJECT-NAME' in config else "9pm"
391+
topdoc = config['PROJECT-TOPDOC'] + "/" if 'PROJECT-TOPDOC' in config else ""
389392

390393
file.write(f"= {name} Test Report\n")
391394
file.write("Author: 9pm Test Framework\n")
392395
file.write(f"Date: {current_date}\n")
393396
file.write(":toc: left\n")
394397
file.write(":toc-title: INDEX\n")
398+
file.write(f":topdoc: {topdoc}\n")
395399
file.write(":sectnums:\n")
396400
file.write(":pdf-page-size: A4\n")
397401

@@ -411,7 +415,7 @@ def write_report(data, config):
411415

412416
file.write("\n<<<\n")
413417
file.write("\n== Test Specification\n")
414-
write_report_includes(file, includes, data, 0)
418+
write_report_specifications(file, data, 0)
415419

416420

417421
def write_github_result_tree(file, data, depth):
@@ -587,9 +591,16 @@ def parse_proj_config(root_path, args):
587591
print(f"error, parsing YAML {path} config.")
588592
sys.exit(1)
589593

590-
if '9pm' in data:
591-
return data['9pm']
592-
return []
594+
if not '9pm' in data:
595+
return []
596+
597+
if 'PROJECT-ROOT' in data['9pm']:
598+
data['9pm']['PROJECT-ROOT'] = rootify_path(data['9pm']['PROJECT-ROOT'])
599+
600+
if 'PROJECT-TOPDOC' in data['9pm']:
601+
data['9pm']['PROJECT-TOPDOC'] = rootify_path(data['9pm']['PROJECT-TOPDOC'])
602+
603+
return data['9pm']
593604

594605
def parse_rc(root_path, args):
595606
required_keys = ["LOG_PATH"]
@@ -699,7 +710,7 @@ def pr_proj_info(proj):
699710
str += f" {proj['PROJECT-NAME']}"
700711

701712
if 'PROJECT-ROOT' in proj:
702-
git_sha = run_git_cmd(os.path.join(ROOT_PATH, proj['PROJECT-ROOT']), ['rev-parse', 'HEAD'])[:12]
713+
git_sha = run_git_cmd(proj['PROJECT-ROOT'], ['rev-parse', 'HEAD'])[:12]
703714

704715
if git_sha:
705716
str += f" ({git_sha})"

0 commit comments

Comments
 (0)