Skip to content

Commit

Permalink
Fix svgs being created in main directory. (#67)
Browse files Browse the repository at this point in the history
Create `svg` files in subdirectory under `tests/files/svgs` instead of top-level directory, and ignore them via `.gitignore`, while syncing the `svgs` directory.
  • Loading branch information
GeigerJ2 authored Dec 17, 2024
1 parent 3520519 commit 9a9c093
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions src/sirocco/vizgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Empty file added tests/files/svgs/.gitkeep
Empty file.
30 changes: 14 additions & 16 deletions tests/test_wc_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

0 comments on commit 9a9c093

Please sign in to comment.