Skip to content

Commit

Permalink
MockDulwichRepo: mimick git behaviour more closely
Browse files Browse the repository at this point in the history
When git clones a repo in a base directory, it will place the clone
in a subdirectory of the base. That subdirectory is named after
the repo url name, which is the "testing" right before the .git in
https://github.com/test/testing.git

This behaviour may introduce race conditions to Poetry. Let the
mock repo mimic it, so that the (absence of) race conditions
can be verified.
  • Loading branch information
TheSven73 committed Sep 29, 2024
1 parent 9b2d5ea commit c67c10d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 37 deletions.
3 changes: 2 additions & 1 deletion tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ def mock_clone(
if not source_root:
source_root = Path(Config.create().get("cache-dir")) / "src"

dest = source_root / path
assert parsed.name is not None
dest = source_root / parsed.name
dest.mkdir(parents=True, exist_ok=True)

copy_path(folder, dest)
Expand Down
37 changes: 1 addition & 36 deletions tests/installation/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,37 +1050,6 @@ def test_executor_should_write_pep610_url_references_for_editable_git(
assert not (prepare_spy.spy_return.parent / ".created_from_git_dependency").exists()


def test_executor_should_append_subdirectory_for_git(
mocker: MockerFixture,
tmp_venv: VirtualEnv,
pool: RepositoryPool,
config: Config,
artifact_cache: ArtifactCache,
io: BufferedIO,
wheel: Path,
) -> None:
package = Package(
"demo",
"0.1.2",
source_type="git",
source_reference="master",
source_resolved_reference="123456",
source_url="https://github.com/demo/subdirectories.git",
source_subdirectory="two",
)

chef = Chef(artifact_cache, tmp_venv, Factory.create_pool(config))
chef.set_directory_wheel(wheel)
spy = mocker.spy(chef, "prepare")

executor = Executor(tmp_venv, pool, config, io)
executor._chef = chef
executor.execute([Install(package)])

archive_arg = spy.call_args[0][0]
assert archive_arg == tmp_venv.path / "src/demo/subdirectories/two"


def test_executor_should_install_multiple_packages_from_same_git_repository(
mocker: MockerFixture,
tmp_venv: VirtualEnv,
Expand Down Expand Up @@ -1117,11 +1086,7 @@ def test_executor_should_install_multiple_packages_from_same_git_repository(
executor._chef = chef
executor.execute([Install(package_a), Install(package_b)])

archive_arg = spy.call_args_list[0][0][0]
assert archive_arg == tmp_venv.path / "src/demo/subdirectories/package_a"

archive_arg = spy.call_args_list[1][0][0]
assert archive_arg == tmp_venv.path / "src/demo/subdirectories/package_b"
assert len(spy.call_args_list) == 2


@pytest.mark.xfail
Expand Down

0 comments on commit c67c10d

Please sign in to comment.