Adapt tests

This commit is contained in:
q0w 2022-06-23 18:30:06 +03:00
parent 3662f5e0df
commit c8c88ce520
13 changed files with 126 additions and 113 deletions

View File

@ -86,7 +86,7 @@ def pytest_addoption(parser: Parser) -> None:
)
def pytest_collection_modifyitems(config: Config, items: List[pytest.Item]) -> None:
def pytest_collection_modifyitems(config: Config, items: List[pytest.Function]) -> None:
for item in items:
if not hasattr(item, "module"): # e.g.: DoctestTextfile
continue
@ -112,8 +112,7 @@ def pytest_collection_modifyitems(config: Config, items: List[pytest.Item]) -> N
if item.get_closest_marker("incompatible_with_sysconfig") and _USE_SYSCONFIG:
item.add_marker(pytest.mark.skip("Incompatible with sysconfig"))
# "Item" has no attribute "module"
module_file = item.module.__file__ # type: ignore[attr-defined]
module_file = item.module.__file__
module_path = os.path.relpath(
module_file, os.path.commonprefix([__file__, module_file])
)
@ -130,7 +129,7 @@ def pytest_collection_modifyitems(config: Config, items: List[pytest.Item]) -> N
# We don't want to allow using the script resource if this is a
# unit test, as unit tests should not need all that heavy lifting
if set(getattr(item, "funcargnames", [])) & {"script"}:
if "script" in item.fixturenames:
raise RuntimeError(
"Cannot use the ``script`` funcarg in a unit test: "
"(filename = {}, item = {})".format(module_path, item)

View File

@ -174,7 +174,7 @@ def test_freeze_editable_not_vcs(script: PipTestEnvironment) -> None:
"""
Test an editable install that is not version controlled.
"""
pkg_path = _create_test_package(script)
pkg_path = _create_test_package(script.scratch_path)
# Rename the .git directory so the directory is no longer recognized
# as a VCS directory.
os.rename(os.path.join(pkg_path, ".git"), os.path.join(pkg_path, ".bak"))
@ -201,7 +201,7 @@ def test_freeze_editable_git_with_no_remote(
"""
Test an editable Git install with no remote url.
"""
pkg_path = _create_test_package(script)
pkg_path = _create_test_package(script.scratch_path)
script.pip("install", "-e", pkg_path)
result = script.pip("freeze")
@ -225,7 +225,7 @@ def test_freeze_editable_git_with_no_remote(
def test_freeze_svn(script: PipTestEnvironment) -> None:
"""Test freezing a svn checkout"""
checkout_path = _create_test_package(script, vcs="svn")
checkout_path = _create_test_package(script.scratch_path, vcs="svn")
# Install with develop
script.run("python", "setup.py", "develop", cwd=checkout_path, expect_stderr=True)
@ -250,7 +250,7 @@ def test_freeze_exclude_editable(script: PipTestEnvironment) -> None:
Test excluding editable from freezing list.
"""
# Returns path to a generated package called "version_pkg"
pkg_version = _create_test_package(script)
pkg_version = _create_test_package(script.scratch_path)
result = script.run(
"git",
@ -283,7 +283,7 @@ def test_freeze_git_clone(script: PipTestEnvironment) -> None:
Test freezing a Git clone.
"""
# Returns path to a generated package called "version_pkg"
pkg_version = _create_test_package(script)
pkg_version = _create_test_package(script.scratch_path)
result = script.run(
"git",
@ -343,7 +343,7 @@ def test_freeze_git_clone_srcdir(script: PipTestEnvironment) -> None:
relative to setup.py.
"""
# Returns path to a generated package called "version_pkg"
pkg_version = _create_test_package_with_srcdir(script)
pkg_version = _create_test_package_with_srcdir(script.scratch_path)
result = script.run(
"git",
@ -378,7 +378,7 @@ def test_freeze_mercurial_clone_srcdir(script: PipTestEnvironment) -> None:
relative to setup.py.
"""
# Returns path to a generated package called "version_pkg"
pkg_version = _create_test_package_with_srcdir(script, vcs="hg")
pkg_version = _create_test_package_with_srcdir(script.scratch_path, vcs="hg")
result = script.run("hg", "clone", os.fspath(pkg_version), "pip-test-package")
repo_dir = script.scratch_path / "pip-test-package"
@ -399,7 +399,7 @@ def test_freeze_git_remote(script: PipTestEnvironment) -> None:
Test freezing a Git clone.
"""
# Returns path to a generated package called "version_pkg"
pkg_version = _create_test_package(script)
pkg_version = _create_test_package(script.scratch_path)
result = script.run(
"git",
@ -483,7 +483,7 @@ def test_freeze_mercurial_clone(script: PipTestEnvironment) -> None:
"""
# Returns path to a generated package called "version_pkg"
pkg_version = _create_test_package(script, vcs="hg")
pkg_version = _create_test_package(script.scratch_path, vcs="hg")
result = script.run(
"hg",
@ -517,7 +517,7 @@ def test_freeze_bazaar_clone(script: PipTestEnvironment) -> None:
"""
try:
checkout_path = _create_test_package(script, vcs="bazaar")
checkout_path = _create_test_package(script.scratch_path, vcs="bazaar")
except OSError as e:
pytest.fail(f"Invoking `bzr` failed: {e}")
@ -549,7 +549,7 @@ def test_freeze_nested_vcs(
) -> None:
"""Test VCS can be correctly freezed when resides inside another VCS repo."""
# Create Python package.
pkg_path = _create_test_package(script, vcs=inner_vcs)
pkg_path = _create_test_package(script.scratch_path, vcs=inner_vcs)
# Create outer repo to clone into.
root_path = script.scratch_path.joinpath("test_freeze_nested_vcs")
@ -1011,7 +1011,7 @@ def test_freeze_pep610_editable(script: PipTestEnvironment) -> None:
Test that a package installed with a direct_url.json with editable=true
is correctly frozeon as editable.
"""
pkg_path = _create_test_package(script, name="testpkg")
pkg_path = _create_test_package(script.scratch_path, name="testpkg")
result = script.pip("install", pkg_path)
direct_url_path = get_created_direct_url_path(result, "testpkg")
assert direct_url_path

View File

@ -345,15 +345,15 @@ def test_basic_install_editable_from_svn(script: PipTestEnvironment) -> None:
"""
Test checking out from svn.
"""
checkout_path = _create_test_package(script)
repo_url = _create_svn_repo(script, checkout_path)
checkout_path = _create_test_package(script.scratch_path)
repo_url = _create_svn_repo(script.scratch_path, checkout_path)
result = script.pip("install", "-e", "svn+" + repo_url + "#egg=version-pkg")
result.assert_installed("version-pkg", with_files=[".svn"])
def _test_install_editable_from_git(script: PipTestEnvironment) -> None:
"""Test cloning from Git."""
pkg_path = _create_test_package(script, name="testpackage", vcs="git")
pkg_path = _create_test_package(script.scratch_path, name="testpackage", vcs="git")
args = [
"install",
"-e",
@ -433,7 +433,7 @@ def test_install_editable_uninstalls_existing_from_path(
@need_mercurial
def test_basic_install_editable_from_hg(script: PipTestEnvironment) -> None:
"""Test cloning and hg+file install from Mercurial."""
pkg_path = _create_test_package(script, name="testpackage", vcs="hg")
pkg_path = _create_test_package(script.scratch_path, name="testpackage", vcs="hg")
url = f"hg+{pkg_path.as_uri()}#egg=testpackage"
assert url.startswith("hg+file")
args = ["install", "-e", url]
@ -446,7 +446,7 @@ def test_vcs_url_final_slash_normalization(script: PipTestEnvironment) -> None:
"""
Test that presence or absence of final slash in VCS URL is normalized.
"""
pkg_path = _create_test_package(script, name="testpackage", vcs="hg")
pkg_path = _create_test_package(script.scratch_path, name="testpackage", vcs="hg")
args = [
"install",
"-e",
@ -459,7 +459,9 @@ def test_vcs_url_final_slash_normalization(script: PipTestEnvironment) -> None:
@need_bzr
def test_install_editable_from_bazaar(script: PipTestEnvironment) -> None:
"""Test checking out from Bazaar."""
pkg_path = _create_test_package(script, name="testpackage", vcs="bazaar")
pkg_path = _create_test_package(
script.scratch_path, name="testpackage", vcs="bazaar"
)
args = [
"install",
"-e",

View File

@ -13,7 +13,7 @@ def test_install_find_links_no_direct_url(script: PipTestEnvironment) -> None:
@pytest.mark.usefixtures("with_wheel")
def test_install_vcs_editable_no_direct_url(script: PipTestEnvironment) -> None:
pkg_path = _create_test_package(script, name="testpkg")
pkg_path = _create_test_package(script.scratch_path, name="testpkg")
args = ["install", "-e", f"git+{pkg_path.as_uri()}#egg=testpkg"]
result = script.pip(*args)
# legacy editable installs do not generate .dist-info,
@ -23,7 +23,7 @@ def test_install_vcs_editable_no_direct_url(script: PipTestEnvironment) -> None:
@pytest.mark.usefixtures("with_wheel")
def test_install_vcs_non_editable_direct_url(script: PipTestEnvironment) -> None:
pkg_path = _create_test_package(script, name="testpkg")
pkg_path = _create_test_package(script.scratch_path, name="testpkg")
url = pkg_path.as_uri()
args = ["install", f"git+{url}#egg=testpkg"]
result = script.pip(*args)
@ -57,7 +57,7 @@ def test_install_vcs_constraint_direct_url(script: PipTestEnvironment) -> None:
@pytest.mark.usefixtures("with_wheel")
def test_install_vcs_constraint_direct_file_url(script: PipTestEnvironment) -> None:
pkg_path = _create_test_package(script, name="testpkg")
pkg_path = _create_test_package(script.scratch_path, name="testpkg")
url = pkg_path.as_uri()
constraints_file = script.scratch_path / "constraints.txt"
constraints_file.write_text(f"git+{url}#egg=testpkg")

View File

@ -145,7 +145,7 @@ def test_git_install_again_after_changes(script: PipTestEnvironment) -> None:
logged on the update: "Did not find branch or tag ..., assuming ref or
revision."
"""
version_pkg_path = _create_test_package(script)
version_pkg_path = _create_test_package(script.scratch_path)
version = _install_version_pkg(script, version_pkg_path)
assert version == "0.1"
@ -161,7 +161,7 @@ def test_git_install_branch_again_after_branch_changes(
Test installing a branch again after the branch is updated in the remote
repository.
"""
version_pkg_path = _create_test_package(script)
version_pkg_path = _create_test_package(script.scratch_path)
version = _install_version_pkg(script, version_pkg_path, rev="master")
assert version == "0.1"
@ -203,7 +203,7 @@ def test_git_with_sha1_revisions(script: PipTestEnvironment) -> None:
"""
Git backend should be able to install from SHA1 revisions
"""
version_pkg_path = _create_test_package(script)
version_pkg_path = _create_test_package(script.scratch_path)
_change_test_package_version(script, version_pkg_path)
sha1 = script.run(
"git",
@ -219,7 +219,7 @@ def test_git_with_short_sha1_revisions(script: PipTestEnvironment) -> None:
"""
Git backend should be able to install from SHA1 revisions
"""
version_pkg_path = _create_test_package(script)
version_pkg_path = _create_test_package(script.scratch_path)
_change_test_package_version(script, version_pkg_path)
sha1 = script.run(
"git",
@ -235,7 +235,7 @@ def test_git_with_branch_name_as_revision(script: PipTestEnvironment) -> None:
"""
Git backend should be able to install from branch names
"""
version_pkg_path = _create_test_package(script)
version_pkg_path = _create_test_package(script.scratch_path)
branch = "test_branch"
script.run("git", "checkout", "-b", branch, cwd=version_pkg_path)
_change_test_package_version(script, version_pkg_path)
@ -247,7 +247,7 @@ def test_git_with_tag_name_as_revision(script: PipTestEnvironment) -> None:
"""
Git backend should be able to install from tag names
"""
version_pkg_path = _create_test_package(script)
version_pkg_path = _create_test_package(script.scratch_path)
script.run("git", "tag", "test_tag", cwd=version_pkg_path)
_change_test_package_version(script, version_pkg_path)
version = _install_version_pkg(script, version_pkg_path, rev="test_tag")
@ -265,7 +265,7 @@ def test_git_install_ref(script: PipTestEnvironment) -> None:
"""
The Git backend should be able to install a ref with the first install.
"""
version_pkg_path = _create_test_package(script)
version_pkg_path = _create_test_package(script.scratch_path)
_add_ref(script, version_pkg_path, "refs/foo/bar")
_change_test_package_version(script, version_pkg_path)
@ -282,7 +282,7 @@ def test_git_install_then_install_ref(script: PipTestEnvironment) -> None:
The Git backend should be able to install a ref after a package has
already been installed.
"""
version_pkg_path = _create_test_package(script)
version_pkg_path = _create_test_package(script.scratch_path)
_add_ref(script, version_pkg_path, "refs/foo/bar")
_change_test_package_version(script, version_pkg_path)
@ -431,7 +431,7 @@ def test_git_with_ambiguous_revs(script: PipTestEnvironment) -> None:
"""
Test git with two "names" (tag/branch) pointing to the same commit
"""
version_pkg_path = _create_test_package(script)
version_pkg_path = _create_test_package(script.scratch_path)
version_pkg_url = _make_version_pkg_url(version_pkg_path, rev="0.1")
script.run("git", "tag", "0.1", cwd=version_pkg_path)
result = script.pip("install", "-e", version_pkg_url)
@ -445,7 +445,7 @@ def test_editable__no_revision(script: PipTestEnvironment) -> None:
"""
Test a basic install in editable mode specifying no revision.
"""
version_pkg_path = _create_test_package(script)
version_pkg_path = _create_test_package(script.scratch_path)
_install_version_pkg_only(script, version_pkg_path)
branch = _get_editable_branch(script, "version-pkg")
@ -460,7 +460,7 @@ def test_editable__branch_with_sha_same_as_default(script: PipTestEnvironment) -
Test installing in editable mode a branch whose sha matches the sha
of the default branch, but is different from the default branch.
"""
version_pkg_path = _create_test_package(script)
version_pkg_path = _create_test_package(script.scratch_path)
# Create a second branch with the same SHA.
script.run("git", "branch", "develop", cwd=version_pkg_path)
_install_version_pkg_only(script, version_pkg_path, rev="develop")
@ -479,7 +479,7 @@ def test_editable__branch_with_sha_different_from_default(
Test installing in editable mode a branch whose sha is different from
the sha of the default branch.
"""
version_pkg_path = _create_test_package(script)
version_pkg_path = _create_test_package(script.scratch_path)
# Create a second branch.
script.run("git", "branch", "develop", cwd=version_pkg_path)
# Add another commit to the master branch to give it a different sha.
@ -500,7 +500,7 @@ def test_editable__non_master_default_branch(script: PipTestEnvironment) -> None
Test the branch you get after an editable install from a remote repo
with a non-master default branch.
"""
version_pkg_path = _create_test_package(script)
version_pkg_path = _create_test_package(script.scratch_path)
# Change the default branch of the remote repo to a name that is
# alphabetically after "master".
script.run("git", "checkout", "-b", "release", cwd=version_pkg_path)
@ -517,7 +517,7 @@ def test_reinstalling_works_with_editable_non_master_branch(
Reinstalling an editable installation should not assume that the "master"
branch exists. See https://github.com/pypa/pip/issues/4448.
"""
version_pkg_path = _create_test_package(script)
version_pkg_path = _create_test_package(script.scratch_path)
# Switch the default branch to something other than 'master'
script.run("git", "branch", "-m", "foobar", cwd=version_pkg_path)
@ -569,7 +569,7 @@ def test_install_git_branch_not_cached(script: PipTestEnvironment) -> None:
Installing git urls with a branch revision does not cause wheel caching.
"""
PKG = "gitbranchnotcached"
repo_dir = _create_test_package(script, name=PKG)
repo_dir = _create_test_package(script.scratch_path, name=PKG)
url = _make_version_pkg_url(repo_dir, rev="master", name=PKG)
result = script.pip("install", url, "--only-binary=:all:")
assert f"Successfully built {PKG}" in result.stdout, result.stdout
@ -585,7 +585,7 @@ def test_install_git_sha_cached(script: PipTestEnvironment) -> None:
Installing git urls with a sha revision does cause wheel caching.
"""
PKG = "gitshacached"
repo_dir = _create_test_package(script, name=PKG)
repo_dir = _create_test_package(script.scratch_path, 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)

View File

@ -736,7 +736,7 @@ def test_list_pep610_editable(script: PipTestEnvironment) -> None:
Test that a package installed with a direct_url.json with editable=true
is correctly listed as editable.
"""
pkg_path = _create_test_package(script, name="testpkg")
pkg_path = _create_test_package(script.scratch_path, name="testpkg")
result = script.pip("install", pkg_path)
direct_url_path = get_created_direct_url_path(result, "testpkg")
assert direct_url_path

View File

@ -221,7 +221,7 @@ def test_is_commit_id_equal(script: PipTestEnvironment) -> None:
"""
Test Git.is_commit_id_equal().
"""
version_pkg_path = os.fspath(_create_test_package(script))
version_pkg_path = os.fspath(_create_test_package(script.scratch_path))
script.run("git", "branch", "branch0.1", cwd=version_pkg_path)
commit = script.run("git", "rev-parse", "HEAD", cwd=version_pkg_path).stdout.strip()
@ -234,7 +234,7 @@ def test_is_commit_id_equal(script: PipTestEnvironment) -> None:
def test_is_immutable_rev_checkout(script: PipTestEnvironment) -> None:
version_pkg_path = os.fspath(_create_test_package(script))
version_pkg_path = os.fspath(_create_test_package(script.scratch_path))
commit = script.run("git", "rev-parse", "HEAD", cwd=version_pkg_path).stdout.strip()
assert Git().is_immutable_rev_checkout(
"git+https://g.c/o/r@" + commit, version_pkg_path
@ -246,7 +246,7 @@ def test_is_immutable_rev_checkout(script: PipTestEnvironment) -> None:
def test_get_repository_root(script: PipTestEnvironment) -> None:
version_pkg_path = _create_test_package(script)
version_pkg_path = _create_test_package(script.scratch_path)
tests_path = version_pkg_path.joinpath("tests")
tests_path.mkdir()

View File

@ -6,7 +6,7 @@ from tests.lib import PipTestEnvironment, _create_test_package, need_mercurial
@need_mercurial
def test_get_repository_root(script: PipTestEnvironment) -> None:
version_pkg_path = _create_test_package(script, vcs="hg")
version_pkg_path = _create_test_package(script.scratch_path, vcs="hg")
tests_path = version_pkg_path.joinpath("tests")
tests_path.mkdir()

View File

@ -13,7 +13,7 @@ def test_get_remote_url__no_remote(script: PipTestEnvironment, tmpdir: Path) ->
repo_path.mkdir()
repo_dir = str(repo_path)
_create_svn_repo(script, repo_dir)
_create_svn_repo(script.scratch_path, repo_dir)
with pytest.raises(RemoteNotFoundError):
Subversion().get_remote_url(repo_dir)
@ -29,7 +29,7 @@ def test_get_remote_url__no_remote_with_setup(
setup.touch()
repo_dir = str(repo_path)
_create_svn_repo(script, repo_dir)
_create_svn_repo(script.scratch_path, repo_dir)
with pytest.raises(RemoteNotFoundError):
Subversion().get_remote_url(repo_dir)

View File

@ -895,50 +895,57 @@ def _git_commit(
def _vcs_add(
script: PipTestEnvironment,
location: pathlib.Path,
version_pkg_path: pathlib.Path,
vcs: str = "git",
) -> pathlib.Path:
if vcs == "git":
script.run("git", "init", cwd=version_pkg_path)
script.run("git", "add", ".", cwd=version_pkg_path)
_git_commit(script, version_pkg_path, message="initial version")
subprocess.check_call(["git", "init"], cwd=os.fspath(version_pkg_path))
subprocess.check_call(["git", "add", "."], cwd=os.fspath(version_pkg_path))
subprocess.check_call(
["git", "commit", "-m", "initial version"], cwd=os.fspath(version_pkg_path)
)
elif vcs == "hg":
script.run("hg", "init", cwd=version_pkg_path)
script.run("hg", "add", ".", cwd=version_pkg_path)
script.run(
"hg",
"commit",
"-q",
"--user",
"pip <distutils-sig@python.org>",
"-m",
"initial version",
cwd=version_pkg_path,
subprocess.check_call(["hg", "init"], cwd=os.fspath(version_pkg_path))
subprocess.check_call(["hg", "add", "."], cwd=os.fspath(version_pkg_path))
subprocess.check_call(
[
"hg",
"commit",
"-q",
"--user",
"pip <distutils-sig@python.org>",
"-m",
"initial version",
],
cwd=os.fspath(version_pkg_path),
)
elif vcs == "svn":
repo_url = _create_svn_repo(script, version_pkg_path)
script.run(
"svn", "checkout", repo_url, "pip-test-package", cwd=script.scratch_path
repo_url = _create_svn_repo(location, version_pkg_path)
subprocess.check_call(
["svn", "checkout", repo_url, "pip-test-package"], cwd=os.fspath(location)
)
checkout_path = script.scratch_path / "pip-test-package"
checkout_path = location / "pip-test-package"
version_pkg_path = checkout_path
elif vcs == "bazaar":
script.run("bzr", "init", cwd=version_pkg_path)
script.run("bzr", "add", ".", cwd=version_pkg_path)
script.run(
"bzr", "whoami", "pip <distutils-sig@python.org>", cwd=version_pkg_path
subprocess.check_call(["bzr", "init"], cwd=os.fspath(version_pkg_path))
subprocess.check_call(["bzr", "add", "."], cwd=os.fspath(version_pkg_path))
subprocess.check_call(
["bzr", "whoami", "pip <distutils-sig@python.org>"],
cwd=os.fspath(version_pkg_path),
)
script.run(
"bzr",
"commit",
"-q",
"--author",
"pip <distutils-sig@python.org>",
"-m",
"initial version",
cwd=version_pkg_path,
subprocess.check_call(
[
"bzr",
"commit",
"-q",
"--author",
"pip <distutils-sig@python.org>",
"-m",
"initial version",
],
cwd=os.fspath(version_pkg_path),
)
else:
raise ValueError(f"Unknown vcs: {vcs}")
@ -995,10 +1002,10 @@ def _create_test_package_with_subdirectory(
def _create_test_package_with_srcdir(
script: PipTestEnvironment, name: str = "version_pkg", vcs: str = "git"
dir_path: pathlib.Path, name: str = "version_pkg", vcs: str = "git"
) -> pathlib.Path:
script.scratch_path.joinpath(name).mkdir()
version_pkg_path = script.scratch_path / name
dir_path.joinpath(name).mkdir()
version_pkg_path = dir_path / name
subdir_path = version_pkg_path.joinpath("subdir")
subdir_path.mkdir()
src_path = subdir_path.joinpath("src")
@ -1021,14 +1028,14 @@ def _create_test_package_with_srcdir(
)
)
)
return _vcs_add(script, version_pkg_path, vcs)
return _vcs_add(dir_path, version_pkg_path, vcs)
def _create_test_package(
script: PipTestEnvironment, name: str = "version_pkg", vcs: str = "git"
dir_path: pathlib.Path, name: str = "version_pkg", vcs: str = "git"
) -> pathlib.Path:
script.scratch_path.joinpath(name).mkdir()
version_pkg_path = script.scratch_path / name
dir_path.joinpath(name).mkdir()
version_pkg_path = dir_path / name
_create_main_file(version_pkg_path, name=name, output="0.1")
version_pkg_path.joinpath("setup.py").write_text(
textwrap.dedent(
@ -1046,20 +1053,24 @@ def _create_test_package(
)
)
)
return _vcs_add(script, version_pkg_path, vcs)
return _vcs_add(dir_path, version_pkg_path, vcs)
def _create_svn_repo(script: PipTestEnvironment, version_pkg_path: StrPath) -> str:
repo_url = script.scratch_path.joinpath("pip-test-package-repo", "trunk").as_uri()
script.run("svnadmin", "create", "pip-test-package-repo", cwd=script.scratch_path)
script.run(
"svn",
"import",
str(version_pkg_path),
repo_url,
"-m",
"Initial import of pip-test-package",
cwd=script.scratch_path,
def _create_svn_repo(repo_path: pathlib.Path, version_pkg_path: StrPath) -> str:
repo_url = repo_path.joinpath("pip-test-package-repo", "trunk").as_uri()
subprocess.check_call(
"svnadmin create pip-test-package-repo".split(), cwd=repo_path
)
subprocess.check_call(
[
"svn",
"import",
os.fspath(version_pkg_path),
repo_url,
"-m",
"Initial import of pip-test-package",
],
cwd=os.fspath(repo_path),
)
return repo_url

View File

@ -1,3 +1,4 @@
import os
from functools import partial
from pathlib import Path
from unittest import mock
@ -8,7 +9,7 @@ from pip._internal.utils.direct_url_helpers import (
direct_url_as_pep440_direct_reference,
direct_url_from_link,
)
from tests.lib import PipTestEnvironment
from pip._internal.vcs.git import Git
def test_as_pep440_requirement_archive() -> None:
@ -110,17 +111,15 @@ def test_from_link_vcs(mock_get_backend_for_scheme: mock.Mock) -> None:
assert direct_url.to_dict()["url"] == "https://g.c/u/p.git"
def test_from_link_vcs_with_source_dir_obtains_commit_id(
script: PipTestEnvironment, tmpdir: Path
) -> None:
def test_from_link_vcs_with_source_dir_obtains_commit_id(tmpdir: Path) -> None:
repo_path = tmpdir / "test-repo"
repo_path.mkdir()
repo_dir = str(repo_path)
script.run("git", "init", cwd=repo_dir)
repo_dir = os.fspath(repo_path)
Git.run_command(["init"], cwd=repo_dir)
(repo_path / "somefile").touch()
script.run("git", "add", ".", cwd=repo_dir)
script.run("git", "commit", "-m", "commit msg", cwd=repo_dir)
commit_id = script.run("git", "rev-parse", "HEAD", cwd=repo_dir).stdout.strip()
Git.run_command(["add", "."], cwd=repo_dir)
Git.run_command(["commit", "-m", "commit msg"], cwd=repo_dir)
commit_id = Git.get_revision(repo_dir)
direct_url = direct_url_from_link(
Link("git+https://g.c/u/p.git"), source_dir=repo_dir
)
@ -129,7 +128,7 @@ def test_from_link_vcs_with_source_dir_obtains_commit_id(
assert direct_url.info.commit_id == commit_id
def test_from_link_vcs_without_source_dir(script: PipTestEnvironment) -> None:
def test_from_link_vcs_without_source_dir() -> None:
direct_url = direct_url_from_link(
Link("git+https://g.c/u/p.git@1"), link_is_in_wheel_cache=True
)

View File

@ -1,5 +1,6 @@
import logging
import os
from pathlib import Path
from typing import Optional, cast
from unittest import mock
@ -9,7 +10,8 @@ from pip._internal import wheel_builder
from pip._internal.models.link import Link
from pip._internal.operations.build.wheel_legacy import format_command_result
from pip._internal.req.req_install import InstallRequirement
from tests.lib import PipTestEnvironment, _create_test_package
from pip._internal.vcs.git import Git
from tests.lib import _create_test_package
@pytest.mark.parametrize(
@ -173,9 +175,9 @@ def test_should_cache(req: ReqMock, expected: bool) -> None:
assert wheel_builder._should_cache(cast(InstallRequirement, req)) is expected
def test_should_cache_git_sha(script: PipTestEnvironment) -> None:
repo_path = os.fspath(_create_test_package(script, name="mypkg"))
commit = script.run("git", "rev-parse", "HEAD", cwd=repo_path).stdout.strip()
def test_should_cache_git_sha(tmpdir: Path) -> None:
repo_path = os.fspath(_create_test_package(tmpdir, name="mypkg"))
commit = Git.get_revision(repo_path)
# a link referencing a sha should be cached
url = "git+https://g.c/o/r@" + commit + "#egg=mypkg"