def test_open_local_or_remote_file__directory(tmpdir): """ Test the `open_local_or_remote_file` raises a ValueError for a given `Link` to a directory. """ link = Link(path_to_url(tmpdir.strpath)) session = Session() with pytest.raises(ValueError, match="Cannot open directory for read"): with open_local_or_remote_file(link, session): pass # pragma: no cover
def test_editable_package(runner): """ piptools can compile an editable """ fake_package_dir = os.path.join(TEST_DATA_PATH, "small_fake_package") fake_package_dir = path_to_url(fake_package_dir) with open("requirements.in", "w") as req_in: req_in.write("-e " + fake_package_dir) # require editable fake package out = runner.invoke(cli, ["-n"]) assert out.exit_code == 0 assert fake_package_dir in out.output assert "six==1.10.0" in out.output
def test_allow_unsafe_option(runner, option, expected): """ Unsafe packages are printed as expected with and without --allow-unsafe. """ with open("requirements.in", "w") as req_in: req_in.write(path_to_url(os.path.join(TEST_DATA_PATH, "small_fake_package"))) out = runner.invoke(cli, [option] if option else []) assert expected in out.output assert out.exit_code == 0
def test_generate_hashes_with_editable(pip_conf, runner): small_fake_package_dir = os.path.join(PACKAGES_PATH, "small_fake_with_deps") small_fake_package_url = path_to_url(small_fake_package_dir) with open("requirements.in", "w") as fp: fp.write("-e {}\n".format(small_fake_package_url)) out = runner.invoke(cli, ["--generate-hashes"]) expected = ("-e {}\n" "small-fake-a==0.1 \\\n" " --hash=sha256:5e6071ee6e4c59e0d0408d366f" "e9b66781d2cf01be9a6e19a2433bb3c5336330\n" "small-fake-b==0.1 \\\n" " --hash=sha256:acdba8f8b8a816213c30d5310c" "3fe296c0107b16ed452062f7f994a5672e3b3f\n" ).format(small_fake_package_url) assert out.exit_code == 0 assert expected in out.stderr
def test_generate_hashes_with_editable(runner): small_fake_package_dir = os.path.join(TEST_DATA_PATH, "small_fake_package") small_fake_package_url = path_to_url(small_fake_package_dir) with open("requirements.in", "w") as fp: fp.write("-e {}\n".format(small_fake_package_url)) fp.write("pytz==2017.2\n") out = runner.invoke( cli, ["--generate-hashes", "--index-url", PyPIRepository.DEFAULT_INDEX_URL]) expected = ("-e {}\n" "pytz==2017.2 \\\n" " --hash=sha256:d1d6729c85acea542367138286" "8627129432fba9a89ecbb248d8d1c7a9f01c67 \\\n" " --hash=sha256:f5c056e8f62d45ba8215e5cb8f" "50dfccb198b4b9fbea8500674f3443e4689589\n" ).format(small_fake_package_url) assert out.exit_code == 0 assert expected in out.output
def test_generate_hashes_with_editable(runner): small_fake_package_dir = os.path.join(TEST_DATA_PATH, "small_fake_package") small_fake_package_url = path_to_url(small_fake_package_dir) with open("requirements.in", "w") as fp: fp.write("-e {}\n".format(small_fake_package_url)) fp.write("pytz==2017.2\n") out = runner.invoke( cli, ["--generate-hashes", "--index-url", PyPIRepository.DEFAULT_INDEX_URL] ) expected = ( "-e {}\n" "pytz==2017.2 \\\n" " --hash=sha256:d1d6729c85acea542367138286" "8627129432fba9a89ecbb248d8d1c7a9f01c67 \\\n" " --hash=sha256:f5c056e8f62d45ba8215e5cb8f" "50dfccb198b4b9fbea8500674f3443e4689589\n" ).format(small_fake_package_url) assert out.exit_code == 0 assert expected in out.output
def test_locally_available_editable_package_is_not_archived_in_cache_dir(tmpdir): """ piptools will not create an archive for a locally available editable requirement """ cache_dir = tmpdir.mkdir('cache_dir') fake_package_dir = os.path.join(os.path.split(__file__)[0], 'test_data', 'small_fake_package') fake_package_dir = path_to_url(fake_package_dir) with mock.patch('piptools.repositories.pypi.CACHE_DIR', new=str(cache_dir)): runner = CliRunner() with runner.isolated_filesystem(): with open('requirements.in', 'w') as req_in: req_in.write('-e ' + fake_package_dir) # require editable fake package out = runner.invoke(cli, ['-n']) assert out.exit_code == 0 assert fake_package_dir in out.output assert 'six==1.10.0' in out.output # we should not find any archived file in {cache_dir}/pkgs assert not os.listdir(os.path.join(str(cache_dir), 'pkgs'))
def test_locally_available_editable_package_is_not_archived_in_cache_dir( pip_conf, tmpdir, runner): """ piptools will not create an archive for a locally available editable requirement """ cache_dir = tmpdir.mkdir("cache_dir") fake_package_dir = os.path.join(PACKAGES_PATH, "small_fake_with_deps") fake_package_dir = path_to_url(fake_package_dir) with open("requirements.in", "w") as req_in: req_in.write("-e " + fake_package_dir) # require editable fake package out = runner.invoke(cli, ["-n", "--rebuild", "--cache-dir", str(cache_dir)]) assert out.exit_code == 0 assert fake_package_dir in out.stderr assert "small-fake-a==0.1" in out.stderr # we should not find any archived file in {cache_dir}/pkgs assert not os.listdir(os.path.join(str(cache_dir), "pkgs"))
def test_locally_available_editable_package_is_not_archived_in_cache_dir( tmpdir, runner ): """ piptools will not create an archive for a locally available editable requirement """ cache_dir = tmpdir.mkdir("cache_dir") fake_package_dir = os.path.join(TEST_DATA_PATH, "small_fake_package") fake_package_dir = path_to_url(fake_package_dir) with mock.patch("piptools.repositories.pypi.CACHE_DIR", new=str(cache_dir)): with open("requirements.in", "w") as req_in: req_in.write("-e " + fake_package_dir) # require editable fake package out = runner.invoke(cli, ["-n"]) assert out.exit_code == 0 assert fake_package_dir in out.output assert "six==1.10.0" in out.output # we should not find any archived file in {cache_dir}/pkgs assert not os.listdir(os.path.join(str(cache_dir), "pkgs"))
def test_locally_available_editable_package_is_not_archived_in_cache_dir( tmpdir, runner ): """ piptools will not create an archive for a locally available editable requirement """ cache_dir = tmpdir.mkdir("cache_dir") fake_package_dir = os.path.join(TEST_DATA_PATH, "small_fake_package") fake_package_dir = path_to_url(fake_package_dir) with mock.patch("piptools.repositories.pypi.CACHE_DIR", new=str(cache_dir)): with open("requirements.in", "w") as req_in: req_in.write("-e " + fake_package_dir) # require editable fake package out = runner.invoke(cli, ["-n"]) assert out.exit_code == 0 assert fake_package_dir in out.output assert "six==1.10.0" in out.output # we should not find any archived file in {cache_dir}/pkgs assert not os.listdir(os.path.join(str(cache_dir), "pkgs"))
def test_url_package(runner, line, dependency, generate_hashes): with open("requirements.in", "w") as req_in: req_in.write(line) out = runner.invoke(cli, ["-n", "--rebuild"] + (["--generate-hashes"] if generate_hashes else [])) assert out.exit_code == 0 assert dependency in out.stderr @mark.parametrize( ("line", "dependency", "rewritten_line"), [ # file:// wheel URL ( path_to_url( os.path.join(MINIMAL_WHEELS_PATH, "small_fake_with_deps-0.1-py2.py3-none-any.whl")), "\nsmall-fake-a==0.1", None, ), # file:// directory ( path_to_url(os.path.join(PACKAGES_PATH, "small_fake_with_deps")), "\nsmall-fake-a==0.1", None, ), # bare path # will be rewritten to file:// URL ( os.path.join(MINIMAL_WHEELS_PATH, "small_fake_with_deps-0.1-py2.py3-none-any.whl"),
"\nclick==", None, ), # wheel URL ( "https://files.pythonhosted.org/packages/06/96/" "89872db07ae70770fba97205b0737c17ef013d0d1c790" "899c16bb8bac419/pip_tools-3.6.1-py2.py3-none-any.whl", "\nclick==", None, ), # file:// wheel URL ( path_to_url( os.path.join( MINIMAL_WHEELS_PATH, "small_fake_with_deps-0.1-py2.py3-none-any.whl" ) ), "\nsix==", None, ), # file:// directory ( path_to_url(os.path.join(TEST_DATA_PATH, "small_fake_package")), "\nsix==", None, ), # bare path # will be rewritten to file:// URL ( os.path.join(
"\nclick==", None, ), # wheel URL ( "https://files.pythonhosted.org/packages/06/96/" "89872db07ae70770fba97205b0737c17ef013d0d1c790" "899c16bb8bac419/pip_tools-3.6.1-py2.py3-none-any.whl", "\nclick==", None, ), # file:// wheel URL ( path_to_url( os.path.join( TEST_DATA_PATH, "minimal_wheels/small_fake_with_deps-0.1-py2.py3-none-any.whl", ) ), "\nsix==", None, ), # file:// directory ( path_to_url(os.path.join(TEST_DATA_PATH, "small_fake_package")), "\nsix==", None, ), # bare path # will be rewritten to file:// URL ( os.path.join(