mcltspice/tests/test_runner.py
Ryan Malloy 9c252606f7 Fix SameFileError in batch sweeps; guard self-copy in runner
run_parameter_sweep/run_monte_carlo write each variant .cir into a work_dir,
then call run_netlist with that same work_dir -- which tried to shutil.copy2
the file onto itself (SameFileError), so every batch run failed before
simulating. Add _safe_copy() that skips when src and dst resolve to the same
path, used at all four staging-copy sites in run_simulation/run_netlist.

Caught by headless claude-cli testing of the batch tools (no batch test
existed). Adds test_runner.py (_safe_copy unit tests) and a TestBatchSweeps
integration class.
2026-06-21 22:24:24 -06:00

28 lines
930 B
Python

"""Unit tests for runner helpers (no LTspice needed)."""
from mcltspice.runner import _safe_copy
class TestSafeCopy:
def test_skips_same_file(self, tmp_path):
# Copying a file onto itself must not raise (was SameFileError in batch runs).
f = tmp_path / "a.cir"
f.write_text("hello")
_safe_copy(f, f)
assert f.read_text() == "hello"
def test_skips_same_file_via_unnormalized_path(self, tmp_path):
# Same file referenced through a "." segment -> resolve() equal -> skip.
f = tmp_path / "a.cir"
f.write_text("x")
alias = tmp_path / "." / "a.cir"
_safe_copy(f, alias) # must not raise
assert f.read_text() == "x"
def test_copies_distinct_files(self, tmp_path):
src = tmp_path / "a.cir"
src.write_text("data")
dst = tmp_path / "b.cir"
_safe_copy(src, dst)
assert dst.read_text() == "data"