def test_list_installed_depends_downgrade_dep(tmp_path, virtualenv_python,
                                              testpkgs):
    (tmp_path / "setup.py").write_text(
        textwrap.dedent("""\
            from setuptools import setup

            setup(name="theproject", install_requires=["pkgc>=0.0.3"])
            """))
    subprocess.check_call([
        virtualenv_python,
        "-m",
        "pip",
        "install",
        "-e",
        str(tmp_path),
        "-f",
        str(testpkgs),
    ])
    assert list_installed_depends(pip_list(virtualenv_python),
                                  "theproject") == {"pkgc"}
    # Change to ask for downgrade of pkgc and try list depends again.
    (tmp_path / "setup.py").write_text(
        textwrap.dedent("""\
            from setuptools import setup

            setup(name="theproject", install_requires=["pkgc<0.0.3"])
            """))
    subprocess.check_call([virtualenv_python, "setup.py", "egg_info"],
                          cwd=str(tmp_path))
    assert list_installed_depends(pip_list(virtualenv_python),
                                  "theproject") == {"pkgc"}
def test_pip_list_extras(virtualenv_python, testpkgs):
    subprocess.check_call([
        virtualenv_python,
        "-m",
        "pip",
        "install",
        "--no-index",
        "-f",
        testpkgs,
        "pkge",
    ])
    installed_dists = pip_list(virtualenv_python)
    assert set(installed_dists.keys()) == {
        "pkga",
        "pkgb",
        "pkgc",
        "pkgd",
        "pkge",
        "pip",
        "wheel",
        "setuptools",
    }
    pkgd_dist = installed_dists["pkgd"]
    assert repr(pkgd_dist.requires) == repr([Requirement("pkga")])
    assert repr(pkgd_dist.extra_requires) == repr({
        "b": [Requirement("pkgb")],
        "c": [Requirement("pkgc")]
    })
    pkge_dist = installed_dists["pkge"]
    assert repr(pkge_dist.requires) == repr([Requirement("pkgd[b,c]")])
def test_list_installed_depends_by_extra(virtualenv_python, testpkgs,
                                         tmp_path):
    (tmp_path / "setup.py").write_text(
        textwrap.dedent("""\
            from setuptools import setup

            setup(
                name="theproject",
                install_requires=["pkga"],
                extras_require={
                    "b": ["pkgb"],
                    "c": ["pkgc"],
                },
            )
            """))
    subprocess.check_call([
        virtualenv_python,
        "-m",
        "pip",
        "install",
        "-e",
        str(tmp_path) + "[b,c]",
        "-f",
        str(testpkgs),
    ])
    installed_dists = pip_list(virtualenv_python)
    assert list_installed_depends_by_extra(installed_dists, "theproject") == {
        None: {"pkga"},
        "b": {"pkgb"},
        "c": {"pkgc"},
    }
def test_list_installed_depends_missing_dep(virtualenv_python, testpkgs):
    subprocess.check_call([
        virtualenv_python, "-m", "pip", "install", "--find-links", testpkgs,
        "pkgb"
    ])
    subprocess.check_call(
        [virtualenv_python, "-m", "pip", "uninstall", "--yes", "pkga"])
    assert list_installed_depends(pip_list(virtualenv_python), "pkgb") == set()
def test_list_installed_depends(to_install, distribution, expected,
                                virtualenv_python, testpkgs):
    subprocess.check_call([
        virtualenv_python,
        "-m",
        "pip",
        "install",
        "--no-index",
        "--find-links",
        testpkgs,
    ] + to_install)
    assert list_installed_depends(pip_list(virtualenv_python),
                                  distribution) == expected
def test_pip_list(virtualenv_python, testpkgs):
    subprocess.check_call([
        virtualenv_python,
        "-m",
        "pip",
        "install",
        "--no-index",
        "-f",
        testpkgs,
        "pkgb",
    ])
    installed_dists = pip_list(virtualenv_python)
    assert set(installed_dists.keys()) == {
        "pkga", "pkgb", "pip", "wheel", "setuptools"
    }
    pkga_dist = installed_dists["pkga"]
    assert pkga_dist.name == "pkga"
    assert pkga_dist.version == "0.0.0"
    # assert pkga_dist.direct_url is None
    pkgb_dist = installed_dists["pkgb"]
    assert pkgb_dist.name == "pkgb"
    assert pkgb_dist.version == "0.0.0"
    assert repr(pkgb_dist.requires) == repr([Requirement("pkga")])
    assert repr(pkgb_dist.requires_dist) == repr([Requirement("pkga<0.0.1")])
def test_list_installed_depends_new_extra(virtualenv_python, testpkgs,
                                          tmp_path):
    (tmp_path / "setup.py").write_text(
        textwrap.dedent("""\
            from setuptools import setup

            setup(
                name="theproject",
                install_requires=[],
            )
            """))
    subprocess.check_call([
        virtualenv_python,
        "-m",
        "pip",
        "install",
        "-e",
        str(tmp_path),
        "-f",
        str(testpkgs),
    ])
    installed_dists = pip_list(virtualenv_python)
    assert list_installed_depends(installed_dists, "theproject",
                                  extras=["a"]) == set()