File: test_lockfile.py

package info (click to toggle)
pipenv 2024.0.1%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,568 kB
  • sloc: python: 187,163; makefile: 191; javascript: 133; sh: 64
file content (63 lines) | stat: -rw-r--r-- 2,292 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from collections import defaultdict
import json
import pytest

from pipenv.project import Project
from pipenv.utils import requirements


@pytest.fixture
def pypi_lockfile():
    lockfile = defaultdict(dict)
    lockfile["_meta"] = {
        "sources": [
            {
                "name": "pypi",
                "url": "https://pypi.org/simple",
                "verify_ssl": True,
            }
        ]
    }
    yield lockfile


def test_git_branch_contains_slashes(
        pipenv_instance_pypi, pypi_lockfile
):
    pypi_lockfile["default"]["google-api-python-client"] = {
        "git": "https://github.com/thehesiod/google-api-python-client.git@thehesiod/batch-retries2",
        "markers": "python_version >= '3.7'",
        "ref": "03803c21fc13a345e978f32775b2f2fa23c8e706"
    }

    with pipenv_instance_pypi() as p:
        with open(p.lockfile_path, "w") as f:
            json.dump(pypi_lockfile, f)

        project = Project()
        lockfile = project.load_lockfile(expand_env_vars=False)
        deps = lockfile["default"]
        pip_installable_lines = requirements.requirements_from_lockfile(
            deps, include_hashes=False, include_markers=True
        )
        assert pip_installable_lines == ["google-api-python-client@ git+https://github.com/thehesiod/google-api-python-client.git@03803c21fc13a345e978f32775b2f2fa23c8e706"]


def test_git_branch_contains_subdirectory_fragment(pipenv_instance_pypi, pypi_lockfile):
    pypi_lockfile["default"]["pep508_package"] = {
        "git": "https://github.com/techalchemy/test-project.git@master",
        "subdirectory": "parent_folder/pep508-package",
        "ref": "03803c21fc13a345e978f32775b2f2fa23c8e706"
    }

    with pipenv_instance_pypi() as p:
        with open(p.lockfile_path, "w") as f:
            json.dump(pypi_lockfile, f)

        project = Project()
        lockfile = project.load_lockfile(expand_env_vars=False)
        deps = lockfile["default"]
        pip_installable_lines = requirements.requirements_from_lockfile(
            deps, include_hashes=False, include_markers=True
        )
        assert pip_installable_lines == ['pep508_package@ git+https://github.com/techalchemy/test-project.git@03803c21fc13a345e978f32775b2f2fa23c8e706#subdirectory=parent_folder/pep508-package']