Skip to content

Commit

Permalink
Add tests for git sha wheel caching
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Nov 2, 2019
1 parent 448303a commit ab65900
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
41 changes: 39 additions & 2 deletions tests/functional/test_install_vcs_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down Expand Up @@ -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
17 changes: 16 additions & 1 deletion tests/unit/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit ab65900

Please sign in to comment.