def test_install_with_cert(): ca_path = "path/to/cert.pem" pool = Pool() default = LegacyRepository("default", "https://foo.bar", cert=Path(ca_path)) pool.add_repository(default, default=True) null_env = NullEnv() installer = PipInstaller(null_env, NullIO(), pool) foo = Package("foo", "0.0.0") foo.source_type = "legacy" foo.source_reference = default._name foo.source_url = default._url installer.install(foo) assert len(null_env.executed) == 1 cmd = null_env.executed[0] assert "--cert" in cmd cert_index = cmd.index("--cert") # Need to do the str(Path()) bit because Windows paths get modified by Path assert cmd[cert_index + 1] == str(Path(ca_path))
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
def test_requirement(installer): 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
def test_install_with_non_pypi_default_repository(pool, installer): 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") 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)
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") package.source_type = "git" package.source_url = "https://github.com/demo/namespace-package-one.git" package.source_reference = "master" package.develop = True # we do this here because the virtual env might not be usable if failure case is triggered pth_file_candidate = tmp_venv.site_packages / "{}-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
def package_git(): package = Package("demo", "1.0.0") package.source_type = "git" package.source_url = "[email protected]:demo/demo.git" package.source_reference = "master" return package
def test_self_update_should_install_all_necessary_elements( app, http, mocker, environ, tmp_dir): os.environ["POETRY_HOME"] = tmp_dir command = app.find("self update") version = Version.parse(__version__).next_minor.text mocker.patch( "poetry.repositories.pypi_repository.PyPiRepository.find_packages", return_value=[Package("poetry", version)], ) mocker.patch.object(command, "_check_recommended_installation", return_value=None) mocker.patch.object(command, "_get_release_name", return_value="poetry-{}-darwin".format(version)) mocker.patch("subprocess.check_output", return_value=b"Python 3.8.2") http.register_uri( "GET", command.BASE_URL + "/{}/poetry-{}-darwin.sha256sum".format(version, version), body=FIXTURES.joinpath("poetry-1.0.5-darwin.sha256sum").read_bytes(), ) http.register_uri( "GET", command.BASE_URL + "/{}/poetry-{}-darwin.tar.gz".format(version, version), body=FIXTURES.joinpath("poetry-1.0.5-darwin.tar.gz").read_bytes(), ) tester = CommandTester(command) tester.execute() bin_ = Path(tmp_dir).joinpath("bin") lib = Path(tmp_dir).joinpath("lib") assert bin_.exists() script = bin_.joinpath("poetry") assert script.exists() expected_script = """\ # -*- coding: utf-8 -*- import glob import sys import os lib = os.path.normpath(os.path.join(os.path.realpath(__file__), "../..", "lib")) vendors = os.path.join(lib, "poetry", "_vendor") current_vendors = os.path.join( vendors, "py{}".format(".".join(str(v) for v in sys.version_info[:2])) ) sys.path.insert(0, lib) sys.path.insert(0, current_vendors) if __name__ == "__main__": from poetry.console import main main() """ if not WINDOWS: expected_script = "#!/usr/bin/env python\n" + expected_script assert expected_script == script.read_text() if WINDOWS: bat = bin_.joinpath("poetry.bat") expected_bat = '@echo off\r\npython "{}" %*\r\n'.format( str(script).replace(os.environ.get("USERPROFILE", ""), "%USERPROFILE%")) assert bat.exists() with bat.open(newline="") as f: assert expected_bat == f.read() assert lib.exists() assert lib.joinpath("poetry").exists()