From ec3a6c1435e88cb36443973fc4a3677c838b8aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Sat, 27 Aug 2022 14:06:52 +0200 Subject: [PATCH] test(installer): use locked version of vcs dependency without reference (branch, tag, rev) instead of latest Requires: python-poetry/poetry-core#449 --- .../with-vcs-dependency-without-ref.test | 34 +++++++++++++++++ tests/installation/test_installer.py | 38 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 tests/installation/fixtures/with-vcs-dependency-without-ref.test diff --git a/tests/installation/fixtures/with-vcs-dependency-without-ref.test b/tests/installation/fixtures/with-vcs-dependency-without-ref.test new file mode 100644 index 00000000000..16521bdea50 --- /dev/null +++ b/tests/installation/fixtures/with-vcs-dependency-without-ref.test @@ -0,0 +1,34 @@ +[[package]] +name = "demo" +version = "0.1.2" +description = "" +category = "main" +optional = false +python-versions = "*" +develop = false + +[package.dependencies] +pendulum = ">=1.4.4" + +[package.source] +type = "git" +url = "/~https://github.com/demo/demo.git" +reference = "HEAD" +resolved_reference = "123456" + +[[package]] +name = "pendulum" +version = "1.4.4" +description = "" +category = "main" +optional = false +python-versions = "*" + +[metadata] +python-versions = "*" +lock-version = "1.1" +content-hash = "123456789" + +[metadata.files] +demo = [] +pendulum = [] diff --git a/tests/installation/test_installer.py b/tests/installation/test_installer.py index 9e4cd2e8ec3..1b8938d4dfb 100644 --- a/tests/installation/test_installer.py +++ b/tests/installation/test_installer.py @@ -2516,3 +2516,41 @@ def test_installer_should_use_the_locked_version_of_git_dependencies_with_extras source_reference="master", source_resolved_reference=expected_reference, ) + + +@pytest.mark.parametrize("is_locked", [False, True]) +def test_installer_should_use_the_locked_version_of_git_dependencies_without_reference( + installer: Installer, + locker: Locker, + package: ProjectPackage, + repo: Repository, + is_locked: bool, +): + """ + If there is no explicit reference (branch or tag or rev) in pyproject.toml, + HEAD is used. + """ + if is_locked: + locker.locked(True) + locker.mock_lock_data(fixture("with-vcs-dependency-without-ref")) + expected_reference = "123456" + else: + expected_reference = MOCK_DEFAULT_GIT_REVISION + + package.add_dependency( + Factory.create_dependency("demo", {"git": "/~https://github.com/demo/demo.git"}) + ) + + repo.add_package(get_package("pendulum", "1.4.4")) + + installer.run() + + assert len(installer.executor.installations) == 2 + assert installer.executor.installations[-1] == Package( + "demo", + "0.1.2", + source_type="git", + source_url="/~https://github.com/demo/demo.git", + source_reference="HEAD", + source_resolved_reference=expected_reference, + )