diff --git a/mkconcore.py b/mkconcore.py index a1f44ef..63b9fac 100644 --- a/mkconcore.py +++ b/mkconcore.py @@ -331,6 +331,10 @@ def cleanup_script_files(): edges_text = soup.find_all('edge') nodes_text = soup.find_all('node') +if not nodes_text: + logging.error(f"No nodes found in {GRAPHML_FILE}. Is it a valid GraphML workflow?") + sys.exit(1) + # Store the edges and nodes in a dictionary edge_label_regex = re.compile(r"0x([a-fA-F0-9]+)_(\S+)") edges_dict = dict() diff --git a/tests/test_mkconcore_no_nodes.py b/tests/test_mkconcore_no_nodes.py new file mode 100644 index 0000000..f4ae46c --- /dev/null +++ b/tests/test_mkconcore_no_nodes.py @@ -0,0 +1,32 @@ +import subprocess +import sys +from pathlib import Path + +import pytest + +MKCONCORE = Path(__file__).resolve().parent.parent / "mkconcore.py" + +EMPTY_GRAPH = ( + '\n' + '' + '\n' +) + + +@pytest.mark.parametrize("content", [EMPTY_GRAPH, "this is not xml"]) +def test_mkconcore_fails_when_graph_has_no_nodes(tmp_path, content): + wf = tmp_path / "w.graphml" + wf.write_text(content) + src = tmp_path / "src" + src.mkdir() + out = tmp_path / "out" + + result = subprocess.run( + [sys.executable, str(MKCONCORE), str(wf), str(src), str(out), "posix"], + cwd=tmp_path, + capture_output=True, + text=True, + ) + + assert result.returncode != 0 + assert "No nodes found" in result.stdout + result.stderr