Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions mkconcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,14 @@ def cleanup_script_files():
with open(outdir+"/src/concore_oport.m","w") as fcopy: fcopy.write(fsource.read())
fsource.close()

fsource = open(CONCOREPATH+"/concore_literal_eval.m")
with open(outdir+"/src/concore_literal_eval.m","w") as fcopy: fcopy.write(fsource.read())
fsource.close()

fsource = open(CONCOREPATH+"/concore_literal_serialize.m")
with open(outdir+"/src/concore_literal_serialize.m","w") as fcopy: fcopy.write(fsource.read())
fsource.close()

if concoretype=="docker":
fsource = open(CONCOREPATH+"/import_concoredocker.m")
else:
Expand Down
28 changes: 28 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,34 @@ def test_inspect_invalid_graphml_exits_nonzero(self):
self.assertEqual(result.exit_code, 1)
self.assertIn("Not a valid GraphML file", result.output)

def test_build_command_m_node_copies_literal_helpers(self):
with self.runner.isolated_filesystem(temp_dir=self.temp_dir):
result = self.runner.invoke(cli, ["init", "test-project"])
self.assertEqual(result.exit_code, 0)

Path("test-project/src/script.py").rename("test-project/src/script.m")
workflow_path = Path("test-project/workflow.graphml")
content = workflow_path.read_text()
workflow_path.write_text(content.replace("N1:script.py", "N1:script.m"))

result = self.runner.invoke(
cli,
[
"build",
"test-project/workflow.graphml",
"--source",
"test-project/src",
"--output",
"out",
"--type",
"posix",
],
)
self.assertEqual(result.exit_code, 0)
# concore_read.m / concore_write.m call these helpers
self.assertTrue(Path("out/src/concore_literal_eval.m").exists())
self.assertTrue(Path("out/src/concore_literal_serialize.m").exists())

def test_watch_file_instead_of_dir_exits_nonzero(self):
with self.runner.isolated_filesystem(temp_dir=self.temp_dir):
Path("notes.txt").write_text("hi")
Expand Down
67 changes: 67 additions & 0 deletions tests/test_mkconcore_matlab_runtime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import re
import subprocess
import sys
from pathlib import Path

import pytest

REPO = Path(__file__).resolve().parents[1]

# The script that copies src/concore_*.m into each node folder, per target type.
BUILD_SCRIPT = {"posix": "build", "windows": "build.bat", "docker": "build"}

# A call such as concore_literal_eval(x) in the body of a .m file.
CALL = re.compile(r"\b(concore_\w+)\s*\(")


@pytest.fixture(params=sorted(BUILD_SCRIPT))
def generated_study(request, tmp_path):
"""Generate demo/sampleM.graphml (MATLAB/Octave nodes) for one target type."""
out = tmp_path / "out"
subprocess.run(
[
sys.executable,
"mkconcore.py",
"demo/sampleM.graphml",
"demo",
str(out),
request.param,
],
cwd=REPO,
check=True,
capture_output=True,
)
return request.param, out


def _called_concore_functions(path):
body = "\n".join(
line
for line in path.read_text().splitlines()
if not line.lstrip().startswith(("%", "#"))
)
return set(CALL.findall(body))


def test_every_concore_function_called_by_a_copied_file_is_copied(generated_study):
target, out = generated_study
src = out / "src"
# concore_read.m and concore_write.m depend on these two (#648)
for helper in ("concore_literal_eval.m", "concore_literal_serialize.m"):
assert (src / helper).exists(), f"{target}: {helper} not copied into src/"

runtime_files = sorted(src.glob("concore_*.m")) + [src / "import_concore.m"]

missing = {
f"{path.name} calls {name}"
for path in runtime_files
for name in _called_concore_functions(path)
if not (src / f"{name}.m").exists()
}
assert not missing, f"{target}: not copied into src/: {sorted(missing)}"


def test_build_script_copies_all_concore_m_files_into_the_node(generated_study):
target, out = generated_study
# The wildcard is what carries every file above from src/ into the node folder.
assert "concore_*.m" in (out / BUILD_SCRIPT[target]).read_text()