From 9a9c09302a690f16a895dff5828e0a0b80731ae3 Mon Sep 17 00:00:00 2001 From: Julian Geiger Date: Tue, 17 Dec 2024 14:37:51 +0100 Subject: [PATCH] Fix svgs being created in main directory. (#67) Create `svg` files in subdirectory under `tests/files/svgs` instead of top-level directory, and ignore them via `.gitignore`, while syncing the `svgs` directory. --- .gitignore | 2 ++ src/sirocco/vizgraph.py | 6 ++++-- tests/files/svgs/.gitkeep | 0 tests/test_wc_workflow.py | 30 ++++++++++++++---------------- 4 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 tests/files/svgs/.gitkeep diff --git a/.gitignore b/.gitignore index 6caa7a4..140e783 100644 --- a/.gitignore +++ b/.gitignore @@ -164,3 +164,5 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +tests/files/svgs/* +!tests/files/svgs/.gitkeep diff --git a/src/sirocco/vizgraph.py b/src/sirocco/vizgraph.py index 7349368..252409f 100644 --- a/src/sirocco/vizgraph.py +++ b/src/sirocco/vizgraph.py @@ -77,10 +77,12 @@ def __init__(self, name: str, cycles: Store, data: Store) -> None: def tooltip(node) -> str: return "\n".join(chain([node.name], (f" {k}: {v}" for k, v in node.coordinates.items()))) - def draw(self, **kwargs): + def draw(self, file_path: Path | None = None, **kwargs): # draw graphviz dot graph to svg file self.agraph.layout(prog="dot") - file_path = Path(f"./{self.name}.svg") + if file_path is None: + file_path = Path(f"./{self.name}.svg") + self.agraph.draw(path=file_path, format="svg", **kwargs) # Add interactive capabilities to the svg graph thanks to diff --git a/tests/files/svgs/.gitkeep b/tests/files/svgs/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_wc_workflow.py b/tests/test_wc_workflow.py index 5711170..29dcd5c 100644 --- a/tests/test_wc_workflow.py +++ b/tests/test_wc_workflow.py @@ -20,31 +20,29 @@ def pprinter(): @pytest.fixture(params=config_test_files) -def config_case(request): +def config_paths(request): config_path = Path(request.param) - return ( - config_path, - (config_path.parent.parent / "data" / config_path.name).with_suffix(".txt"), - ) + return { + "yml": config_path, + "txt": (config_path.parent.parent / "data" / config_path.name).with_suffix(".txt"), + "svg": (config_path.parent.parent / "svgs" / config_path.name).with_suffix(".svg"), + } -def test_parse_config_file(config_case, pprinter): - config_path, reference_path = config_case - reference_str = reference_path.read_text() - test_str = pprinter.format(Workflow.from_yaml(config_path)) +def test_parse_config_file(config_paths, pprinter): + reference_str = config_paths["txt"].read_text() + test_str = pprinter.format(Workflow.from_yaml(config_paths["yml"])) if test_str != reference_str: - new_path = Path(reference_path).with_suffix(".new.txt") + new_path = Path(config_paths["txt"]).with_suffix(".new.txt") new_path.write_text(test_str) msg = f"Workflow graph doesn't match serialized data. New graph string dumped to {new_path}." raise ValueError(msg) @pytest.mark.skip(reason="don't run it each time, uncomment to regenerate serilaized data") -def test_serialize_workflow(config_case, pprinter): - config_path, reference_path = config_case - reference_path.write_text(pprinter.format(Workflow.from_yaml(config_path))) +def test_serialize_workflow(config_paths, pprinter): + config_paths["txt"].write_text(pprinter.format(Workflow.from_yaml(config_paths["yml"]))) -def test_vizgraph(config_case): - config_path, _ = config_case - VizGraph.from_yaml(config_path).draw() +def test_vizgraph(config_paths): + VizGraph.from_yaml(config_paths["yml"]).draw(file_path=config_paths["svg"])