コード例 #1
0
def test_install_with_non_pypi_default_repository(pool: Pool,
                                                  installer: PipInstaller):
    default = LegacyRepository("default", "https://default.com")
    another = LegacyRepository("another", "https://another.com")

    pool.add_repository(default, default=True)
    pool.add_repository(another)

    foo = Package(
        "foo",
        "0.0.0",
        source_type="legacy",
        source_reference=default.name,
        source_url=default.url,
    )
    bar = Package(
        "bar",
        "0.1.0",
        source_type="legacy",
        source_reference=another.name,
        source_url=another.url,
    )

    installer.install(foo)
    installer.install(bar)
コード例 #2
0
def test_install_with_trusted_host(config: Config):
    config.merge({"certificates": {"default": {"cert": False}}})

    default = LegacyRepository("default", "https://foo.bar")
    pool = Pool()
    pool.add_repository(default, default=True)

    null_env = NullEnv()

    installer = PipInstaller(null_env, NullIO(), pool)

    foo = Package(
        "foo",
        "0.0.0",
        source_type="legacy",
        source_reference=default.name,
        source_url=default.url,
    )

    installer.install(foo)

    assert len(null_env.executed) == 1
    cmd = null_env.executed[0]
    assert "--trusted-host" in cmd
    cert_index = cmd.index("--trusted-host")
    assert cmd[cert_index + 1] == "foo.bar"
コード例 #3
0
def test_install_with_certs(mocker: MockerFixture, key: str, option: str):
    client_path = "path/to/client.pem"
    mocker.patch(
        "poetry.utils.authenticator.Authenticator.get_certs_for_url",
        return_value={key: client_path},
    )

    default = LegacyRepository("default", "https://foo.bar")
    pool = Pool()
    pool.add_repository(default, default=True)

    null_env = NullEnv()

    installer = PipInstaller(null_env, NullIO(), pool)

    foo = Package(
        "foo",
        "0.0.0",
        source_type="legacy",
        source_reference=default.name,
        source_url=default.url,
    )

    installer.install(foo)

    assert len(null_env.executed) == 1
    cmd = null_env.executed[0]
    assert f"--{option}" in cmd
    cert_index = cmd.index(f"--{option}")
    # Need to do the str(Path()) bit because Windows paths get modified by Path
    assert cmd[cert_index + 1] == str(Path(client_path))
コード例 #4
0
ファイル: test_pip_installer.py プロジェクト: yosmoc/poetry
def test_install_with_client_cert():
    client_path = "path/to/client.pem"
    pool = Pool()

    default = LegacyRepository("default",
                               "https://foo.bar",
                               client_cert=Path(client_path))

    pool.add_repository(default, default=True)

    null_env = NullEnv()

    installer = PipInstaller(null_env, NullIO(), pool)

    foo = Package(
        "foo",
        "0.0.0",
        source_type="legacy",
        source_reference=default.name,
        source_url=default.url,
    )

    installer.install(foo)

    assert len(null_env.executed) == 1
    cmd = null_env.executed[0]
    assert "--client-cert" in cmd
    cert_index = cmd.index("--client-cert")
    # Need to do the str(Path()) bit because Windows paths get modified by Path
    assert cmd[cert_index + 1] == str(Path(client_path))
コード例 #5
0
def test_requirement_source_type_url():
    installer = PipInstaller(NullEnv(), NullIO(), Pool())

    foo = Package("foo", "0.0.0")
    foo.source_type = "url"
    foo.source_url = "https://somehwere.com/releases/foo-1.0.0.tar.gz"

    result = installer.requirement(foo, formatted=True)
    expected = "{}#egg={}".format(foo.source_url, foo.name)

    assert expected == result
コード例 #6
0
def test_requirement_source_type_url():
    installer = PipInstaller(NullEnv(), NullIO(), Pool())

    foo = Package(
        "foo",
        "0.0.0",
        source_type="url",
        source_url="https://somewhere.com/releases/foo-1.0.0.tar.gz",
    )

    result = installer.requirement(foo, formatted=True)
    expected = f"{foo.source_url}#egg={foo.name}"

    assert result == expected
コード例 #7
0
def test_requirement_git_develop_false(installer: PipInstaller,
                                       package_git: Package):
    package_git.develop = False
    result = installer.requirement(package_git)
    expected = "[email protected]:demo/demo.git@master#egg=demo"

    assert expected == result
コード例 #8
0
def test_requirement_git_develop_true(installer: PipInstaller,
                                      package_git: Package):
    package_git.develop = True
    result = installer.requirement(package_git)
    expected = ["-e", "[email protected]:demo/demo.git@master#egg=demo"]

    assert result == expected
コード例 #9
0
def test_requirement():
    installer = PipInstaller(NullEnv(), NullIO(), Pool())

    package = Package("ipython", "7.5.0")
    package.hashes = [
        "md5:dbdc53e3918f28fa335a173432402a00",
        "e840810029224b56cd0d9e7719dc3b39cf84d577f8ac686547c8ba7a06eeab26",
    ]

    result = installer.requirement(package, formatted=True)
    expected = (
        "ipython==7.5.0 "
        "--hash md5:dbdc53e3918f28fa335a173432402a00 "
        "--hash sha256:e840810029224b56cd0d9e7719dc3b39cf84d577f8ac686547c8ba7a06eeab26"
        "\n")

    assert expected == result
コード例 #10
0
def test_install_with_non_pypi_default_repository():
    pool = Pool()

    default = LegacyRepository("default", "https://default.com")
    another = LegacyRepository("another", "https://another.com")

    pool.add_repository(default, default=True)
    pool.add_repository(another)

    installer = PipInstaller(NullEnv(), NullIO(), pool)

    foo = Package("foo", "0.0.0")
    foo.source_type = "legacy"
    foo.source_reference = default._name
    foo.source_url = default._url
    bar = Package("bar", "0.1.0")
    bar.source_type = "legacy"
    bar.source_reference = another._name
    bar.source_url = another._url

    installer.install(foo)
    installer.install(bar)
コード例 #11
0
def test_requirement(installer: PipInstaller):
    package = Package("ipython", "7.5.0")
    package.files = [
        {"file": "foo-0.1.0.tar.gz", "hash": "md5:dbdc53e3918f28fa335a173432402a00"},
        {
            "file": "foo.0.1.0.whl",
            "hash": "e840810029224b56cd0d9e7719dc3b39cf84d577f8ac686547c8ba7a06eeab26",
        },
    ]

    result = installer.requirement(package, formatted=True)
    expected = (
        "ipython==7.5.0 "
        "--hash md5:dbdc53e3918f28fa335a173432402a00 "
        "--hash sha256:e840810029224b56cd0d9e7719dc3b39cf84d577f8ac686547c8ba7a06eeab26"
        "\n"
    )

    assert result == expected
コード例 #12
0
ファイル: test_pip_installer.py プロジェクト: yosmoc/poetry
def test_uninstall_git_package_nspkg_pth_cleanup(mocker, tmp_venv, pool):
    # this test scenario requires a real installation using the pip installer
    installer = PipInstaller(tmp_venv, NullIO(), pool)

    # use a namepspace package
    package = Package(
        "namespace-package-one",
        "1.0.0",
        source_type="git",
        source_url="https://github.com/demo/namespace-package-one.git",
        source_reference="master",
    )

    # we do this here because the virtual env might not be usable if failure case is triggered
    pth_file_candidate = tmp_venv.site_packages.path / "{}-nspkg.pth".format(
        package.name)

    # in order to reproduce the scenario where the git source is removed prior to proper
    # clean up of nspkg.pth file, we need to make sure the fixture is copied and not
    # symlinked into the git src directory
    def copy_only(source, dest):
        if dest.exists():
            dest.unlink()

        if source.is_dir():
            shutil.copytree(str(source), str(dest))
        else:
            shutil.copyfile(str(source), str(dest))

    mocker.patch("tests.helpers.copy_or_symlink", new=copy_only)

    # install package and then remove it
    installer.install(package)
    installer.remove(package)

    assert not Path(pth_file_candidate).exists()

    # any command in the virtual environment should trigger the error message
    output = tmp_venv.run("python", "-m", "site")
    assert "Error processing line 1 of {}".format(
        pth_file_candidate) not in output
コード例 #13
0
def test_uninstall_git_package_nspkg_pth_cleanup(
    mocker: MockerFixture, tmp_venv: VirtualEnv, pool: Pool
):
    # this test scenario requires a real installation using the pip installer
    installer = PipInstaller(tmp_venv, NullIO(), pool)

    # use a namepspace package
    package = Package(
        "namespace-package-one",
        "1.0.0",
        source_type="git",
        source_url="https://github.com/demo/namespace-package-one.git",
        source_reference="master",
    )

    # in order to reproduce the scenario where the git source is removed prior to proper
    # clean up of nspkg.pth file, we need to make sure the fixture is copied and not
    # symlinked into the git src directory
    def copy_only(source: Path, dest: Path) -> None:
        if dest.exists():
            dest.unlink()

        if source.is_dir():
            shutil.copytree(str(source), str(dest))
        else:
            shutil.copyfile(str(source), str(dest))

    mocker.patch("tests.helpers.copy_or_symlink", new=copy_only)

    # install package and then remove it
    installer.install(package)
    installer.remove(package)

    pth_file = f"{package.name}-nspkg.pth"
    assert not tmp_venv.site_packages.exists(pth_file)

    # any command in the virtual environment should trigger the error message
    output = tmp_venv.run("python", "-m", "site")
    assert not re.match(rf"Error processing line 1 of .*{pth_file}", output)
コード例 #14
0
ファイル: test_pip_installer.py プロジェクト: yosmoc/poetry
def installer(pool):
    return PipInstaller(NullEnv(), NullIO(), pool)
コード例 #15
0
ファイル: installer.py プロジェクト: nikmolnar/poetry
 def _get_installer(self) -> BaseInstaller:
     return PipInstaller(self._env, self._io, self._pool)
コード例 #16
0
def installer(pool: Pool) -> PipInstaller:
    return PipInstaller(NullEnv(), NullIO(), pool)
コード例 #17
0
def installer():
    return PipInstaller(NullEnv(), NullIO())