Skip to content

Commit

Permalink
test: spec: Always generate specifications with relative path
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiaswal committed Sep 9, 2024
1 parent 257c2ac commit d79d6b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions test/spec/generate_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ def visit_Call(self, node):
self.generic_visit(node) # Continue visiting other nodes

class TestCase:
def __init__(self, directory):
self.root=Path(directory)
def __init__(self, directory, rootdir=None):
self.test_dir=Path(directory)
if rootdir:
rootdir=Path(f"{rootdir}")
self.test_dir=self.test_dir.relative_to(rootdir)
self.topology_dot=f"{directory}/topology.dot"
self.topology_image=f"{directory}/topology"
self.test_case=f"{directory}/test.py"
Expand All @@ -59,7 +62,6 @@ def __init__(self, directory):
def generate_topology(self):
with open(self.topology_dot, 'r') as dot_file:
dot_graph = dot_file.read()
# Create a Graph object
graph = graphviz.Source(dot_graph)
graph.render(self.topology_image, format='png', cleanup=True)

Expand All @@ -71,19 +73,16 @@ def generate_specification(self):
spec.write(self.description + "\n\n")
spec.write("==== Topology\n")
spec.write("ifdef::topdoc[]\n")
spec.write(f"image::{self.root}/topology.png[{self.name} topology]\n\n")
spec.write(f"image::../../{self.test_dir}/topology.png[{self.name} topology]\n")
spec.write("endif::topdoc[]\n")

spec.write("ifndef::topdoc[]\n")
spec.write("ifdef::testgroup[]\n")
spec.write(f"image::{Path(*self.root.parts[2:])}/topology.png[{self.name} topology]\n\n")
spec.write(f"image::{Path(*self.test_dir.parts[3:])}/topology.png[{self.name} topology]\n")
spec.write("endif::testgroup[]\n")

spec.write("ifndef::testgroup[]\n")
spec.write(f"image::topology.png[{self.name} topology]\n\n")
spec.write(f"image::topology.png[{self.name} topology]\n")
spec.write("endif::testgroup[]\n")
spec.write("endif::topdoc[]\n")
#spec.write(f"image::topology.png[{self.name}]\n\n")
spec.write("==== Test sequence\n")
spec.writelines([f". {step}\n" for step in self.test_steps])
spec.write("\n\n<<<\n\n") # need empty lines to pagebreak
Expand All @@ -108,9 +107,10 @@ def parse_directory_tree(directory):

parser = argparse.ArgumentParser(description="Generate a test specification for a subtree.")
parser.add_argument("-d", "--directory", required=True, help="The directory to parse.")
parser.add_argument("-r", "--root-dir", help="Path that all paths should be relative to")
args=parser.parse_args()

directories=parse_directory_tree(args.directory)
for directory in directories:
test_case=TestCase(directory)
test_case=TestCase(directory, args.root_dir)
test_case.generate_specification()
2 changes: 1 addition & 1 deletion test/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test-sh:

test-spec:
@sed 's/{REPLACE}/$(subst ",,$(INFIX_NAME))/' $(spec-dir)/Readme.adoc.in > $(spec-dir)/Readme.adoc
@$(spec-dir)/generate_spec.py -d $(test-dir)/case
@$(spec-dir)/generate_spec.py -d $(test-dir)/case -r $(BR2_EXTERNAL_INFIX_PATH)
@asciidoctor-pdf --theme $(spec-dir)/theme.yml -a pdf-fontsdir=$(spec-dir)/fonts -o $(test-specification) $(spec-dir)/Readme.adoc

# Unit tests run with random (-r) hostname and container name to
Expand Down

0 comments on commit d79d6b7

Please sign in to comment.