diff --git a/tests/functional/test_install_vcs_git.py b/tests/functional/test_install_vcs_git.py index e19745bb8a2..f4c56eb5373 100644 --- a/tests/functional/test_install_vcs_git.py +++ b/tests/functional/test_install_vcs_git.py @@ -67,7 +67,7 @@ def _github_checkout(url_path, temp_dir, rev=None, egg=None, scheme=None): return local_url -def _make_version_pkg_url(path, rev=None): +def _make_version_pkg_url(path, rev=None, name="version_pkg"): """ Return a "git+file://" URL to the version_pkg test package. @@ -78,7 +78,7 @@ def _make_version_pkg_url(path, rev=None): """ file_url = _test_path_to_file_url(path) url_rev = '' if rev is None else '@{}'.format(rev) - url = 'git+{}{}#egg=version_pkg'.format(file_url, url_rev) + url = 'git+{}{}#egg={}'.format(file_url, url_rev, name) return url @@ -476,3 +476,40 @@ def test_check_submodule_addition(script): script.venv / 'src/version-pkg/testpkg/static/testfile2' in update_result.files_created ) + + +def test_install_git_branch_not_cached(script, with_wheel): + """ + Installing git urls with a branch revision does not cause wheel caching. + """ + PKG = "gitbranchnotcached" + repo_dir = _create_test_package(script, name=PKG) + url = _make_version_pkg_url(repo_dir, rev="master", name=PKG) + result = script.pip("install", url, "--only-binary=:all:") + assert "Successfully built {}".format(PKG) in result.stdout, result.stdout + script.pip("uninstall", "-y", PKG) + # build occurs on the second install too because it is not cached + result = script.pip("install", url) + assert ( + "Successfully built {}".format(PKG) in result.stdout + ), result.stdout + + +def test_install_git_sha_cached(script, with_wheel): + """ + Installing git urls with a sha revision does cause wheel caching. + """ + PKG = "gitshacached" + repo_dir = _create_test_package(script, name=PKG) + commit = script.run( + 'git', 'rev-parse', 'HEAD', cwd=repo_dir + ).stdout.strip() + url = _make_version_pkg_url(repo_dir, rev=commit, name=PKG) + result = script.pip("install", url) + assert "Successfully built {}".format(PKG) in result.stdout, result.stdout + script.pip("uninstall", "-y", PKG) + # build does not occur on the second install too because it is cached + result = script.pip("install", url) + assert ( + "Successfully built {}".format(PKG) not in result.stdout + ), result.stdout diff --git a/tests/unit/test_wheel.py b/tests/unit/test_wheel.py index 05413f9074e..fc3a7ddb382 100644 --- a/tests/unit/test_wheel.py +++ b/tests/unit/test_wheel.py @@ -20,7 +20,7 @@ MissingCallableSuffix, _raise_for_invalid_entrypoint, ) -from tests.lib import DATA_DIR, assert_paths_equal +from tests.lib import DATA_DIR, _create_test_package, assert_paths_equal class ReqMock: @@ -166,6 +166,21 @@ def check_binary_allowed(req): assert should_cache is expected +def test_should_cache_git_sha(script, tmpdir): + repo_path = _create_test_package(script, name="mypkg") + commit = script.run( + "git", "rev-parse", "HEAD", cwd=repo_path + ).stdout.strip() + # a link referencing a sha should be cached + url = "git+https://g.c/o/r@" + commit + "#egg=mypkg" + req = ReqMock(link=Link(url), source_dir=repo_path) + assert wheel.should_cache(req, check_binary_allowed=lambda r: True) + # a link not referencing a sha should not be cached + url = "git+https://g.c/o/r@master#egg=mypkg" + req = ReqMock(link=Link(url), source_dir=repo_path) + assert not wheel.should_cache(req, check_binary_allowed=lambda r: True) + + def test_format_command_result__INFO(caplog): caplog.set_level(logging.INFO) actual = wheel.format_command_result(