1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00
pip/tests/lib/local_repos.py
Jon Dufresne 943af79f26 Run mypy on the tests directory
The tests are a large consumer of the pip API (both the internal API and
otherwise). By running mypy on tests, we help to:

1. Ensure the internal API is consistent with regards to typing

2. Ensure the tests are representative of real life scenarios as the API
   are used correctly.

3. Helps to recognize unnecessary tests that simply pass junk data to
   functions which can be caught by the type checker.

4. Make sure test support code in tests/lib/ is correct and consistent.
   This is especially important when refactoring such code. For example, if
   we were to replace tests/lib/path.py with pathlib.

As a first start, untyped defs are allowed. All existing typing issues
have been resolved. Overtime, we can chip away at untyped defs and
eventually remove the configuration option for stricter type checking of
tests.

The following changes were made to help make mypy pass:

Remove unused record_callback argument from make_wheel() in tests.
Unused since its introduction in
6d8a58f7e1.

Replace toml with tomli_w in tests/functional/test_pep517.py. Unlike the
toml package, tomli_w contains inline typing annotations.

Remove unnecessary make_no_network_finder(). Unnecessary since
bab1e4f8a1 where the _get_pages method was
removed.
2021-08-22 09:57:26 -06:00

64 lines
1.9 KiB
Python

import os
import subprocess
import urllib.request
from pip._internal.utils.misc import hide_url
from pip._internal.vcs import vcs
from tests.lib import path_to_url
from tests.lib.path import Path
def _create_svn_initools_repo(initools_dir):
"""
Create the SVN INITools repo.
"""
directory = os.path.dirname(initools_dir)
subprocess.check_call("svnadmin create INITools".split(), cwd=directory)
filename, _ = urllib.request.urlretrieve(
"http://bitbucket.org/hltbra/pip-initools-dump/raw/8b55c908a320/"
"INITools_modified.dump"
)
with open(filename) as dump:
subprocess.check_call(
["svnadmin", "load", initools_dir],
stdin=dump,
stdout=subprocess.DEVNULL,
)
os.remove(filename)
def local_checkout(
remote_repo: str,
temp_path: Path,
) -> str:
"""
:param temp_path: the return value of the tmpdir fixture, which is a
temp directory Path object unique to each test function invocation,
created as a sub directory of the base temp directory.
"""
assert "+" in remote_repo
vcs_name = remote_repo.split("+", 1)[0]
repository_name = os.path.basename(remote_repo)
directory = temp_path.joinpath("cache")
repo_url_path = os.path.join(directory, repository_name)
assert not os.path.exists(repo_url_path)
if not os.path.exists(directory):
os.mkdir(directory)
if vcs_name == "svn":
assert repository_name == "INITools"
_create_svn_initools_repo(repo_url_path)
repo_url_path = os.path.join(repo_url_path, "trunk")
else:
vcs_backend = vcs.get_backend(vcs_name)
assert vcs_backend is not None
vcs_backend.obtain(repo_url_path, url=hide_url(remote_repo))
return "{}+{}".format(vcs_name, path_to_url(repo_url_path))
def local_repo(remote_repo, temp_path):
return local_checkout(remote_repo, temp_path).split("+", 1)[1]