Skip to content

Commit 0ce7c19

Browse files
dionhaefnerclaude
andcommitted
test(sdk): cover local-dependency staging helpers
Add direct unit tests for _split_local_dependency and _stage_local_dependency (file branch, name-collision counter, extras parsing) plus a conda-without-env-file case, and drop an unreachable defensive branch in _split_local_dependency. Raises patch coverage on the requirement-handling fixes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent eefc8b2 commit 0ce7c19

2 files changed

Lines changed: 66 additions & 3 deletions

File tree

tesseract_core/sdk/engine.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,8 @@ def _split_local_dependency(line: str) -> tuple[str, str]:
154154
Returns a ``(path, extras)`` tuple where ``extras`` includes the surrounding
155155
brackets (e.g. ``"[extra]"``) or is empty if none are present.
156156
"""
157+
# This pattern matches any non-empty string, so a match is always found.
157158
match = re.match(r"^(?P<path>.+?)(?P<extras>\[[^\]]*\])?\s*\Z", line.strip())
158-
if match is None:
159-
# Should not happen for a non-empty line, but fall back to the raw path.
160-
return line.strip(), ""
161159
return match.group("path"), match.group("extras") or ""
162160

163161

tests/sdk_tests/test_engine.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,71 @@ def test_parse_requirements(tmpdir):
742742
]
743743

744744

745+
def test_prepare_build_context_conda_no_env_file(tmp_path_factory):
746+
"""Conda provider without an environment file does not error at staging."""
747+
src_dir = tmp_path_factory.mktemp("src")
748+
(src_dir / "tesseract_api.py").touch()
749+
build_dir = tmp_path_factory.mktemp("build")
750+
751+
config = TesseractConfig(
752+
name="foobar",
753+
build_config=TesseractBuildConfig(requirements={"provider": "conda"}),
754+
)
755+
engine.prepare_build_context(src_dir, build_dir, config)
756+
assert (build_dir / "Dockerfile").exists()
757+
758+
759+
@pytest.mark.parametrize(
760+
"line, expected",
761+
[
762+
("./mylocaldep", ("./mylocaldep", "")),
763+
("./mylocaldep[extra]", ("./mylocaldep", "[extra]")),
764+
("../../pkg[a,b]", ("../../pkg", "[a,b]")),
765+
("/abs/path", ("/abs/path", "")),
766+
("./a[b] ", ("./a", "[b]")),
767+
],
768+
)
769+
def test_split_local_dependency(line, expected):
770+
assert engine._split_local_dependency(line) == expected
771+
772+
773+
def test_stage_local_dependency_file(tmp_path):
774+
"""A local file dependency (e.g. a wheel) is copied, not tree-copied."""
775+
src_dir = tmp_path / "src"
776+
src_dir.mkdir()
777+
(src_dir / "mypkg-1.0-py3-none-any.whl").write_text("wheel contents")
778+
local_requirements = tmp_path / "local_requirements"
779+
local_requirements.mkdir()
780+
781+
spec = engine._stage_local_dependency(
782+
"./mypkg-1.0-py3-none-any.whl", "", src_dir, local_requirements
783+
)
784+
staged = local_requirements / "mypkg-1.0-py3-none-any.whl"
785+
assert spec == "./local_requirements/mypkg-1.0-py3-none-any.whl"
786+
assert staged.is_file()
787+
assert staged.read_text() == "wheel contents"
788+
789+
790+
def test_stage_local_dependency_name_collision(tmp_path):
791+
"""Two dependencies resolving to the same basename get distinct staged names."""
792+
src_dir = tmp_path / "src"
793+
(src_dir / "a" / "mypkg").mkdir(parents=True)
794+
(src_dir / "b" / "mypkg").mkdir(parents=True)
795+
local_requirements = tmp_path / "local_requirements"
796+
local_requirements.mkdir()
797+
798+
spec_a = engine._stage_local_dependency(
799+
"./a/mypkg", "", src_dir, local_requirements
800+
)
801+
spec_b = engine._stage_local_dependency(
802+
"./b/mypkg", "", src_dir, local_requirements
803+
)
804+
assert spec_a == "./local_requirements/mypkg"
805+
assert spec_b == "./local_requirements/mypkg_1"
806+
assert (local_requirements / "mypkg").is_dir()
807+
assert (local_requirements / "mypkg_1").is_dir()
808+
809+
745810
@pytest.mark.parametrize(
746811
"spec, expected",
747812
[

0 commit comments

Comments
 (0)