Potentialy speed up tests, decrease network calls"

Signed-off-by: Dan Ryan <dan@danryan.co>
This commit is contained in:
Dan Ryan
2018-11-22 13:32:34 -05:00
parent 28485b6356
commit 66e9822d8a
7 changed files with 36 additions and 54 deletions
+6
View File
@@ -16,3 +16,9 @@
[submodule "tests/test_artifacts/git/pyinstaller"]
path = tests/test_artifacts/git/pyinstaller
url = https://github.com/pyinstaller/pyinstaller.git
[submodule "tests/test_artifacts/git/jinja2"]
path = tests/test_artifacts/git/jinja2
url = git@github.com:pallets/jinja.git
[submodule "tests/test_artifacts/git/flask"]
path = tests/test_artifacts/git/flask
url = git@github.com:pallets/flask.git
+3 -3
View File
@@ -290,7 +290,7 @@ class FileRequirement(object):
if self.path and not self.uri:
self._uri_scheme = "path"
return pip_shims.shims.path_to_url(os.path.abspath(self.path))
elif self.req and getattr(self.req, "url"):
elif getattr(self, "req", None) and getattr(self.req, "url"):
return self.req.url
@name.default
@@ -321,7 +321,7 @@ class FileRequirement(object):
if self.extras:
line = "{0}[{1}]".format(line, ",".join(self.extras))
_ireq = pip_shims.shims.install_req_from_line(line)
if self.req:
if getattr(self, "req", None):
_ireq.req = copy.deepcopy(self.req)
else:
if self.extras:
@@ -710,7 +710,7 @@ class VCSRequirement(FileRequirement):
def get_name(self):
return (
self.link.egg_fragment or self.req.name
if self.req
if getattr(self, "req", None)
else super(VCSRequirement, self).get_name()
)
+12 -27
View File
@@ -338,7 +338,7 @@ six = {{path = "./artifacts/{}"}}
@pytest.mark.files
@pytest.mark.install
@pytest.mark.run
def test_multiple_editable_packages_should_not_race(PipenvInstance, pypi, tmpdir, testsroot):
def test_multiple_editable_packages_should_not_race(PipenvInstance, pypi, testsroot):
"""Test for a race condition that can occur when installing multiple 'editable' packages at
once, and which causes some of them to not be importable.
@@ -347,40 +347,25 @@ def test_multiple_editable_packages_should_not_race(PipenvInstance, pypi, tmpdir
So this test locally installs packages from tarballs that have already been committed in
the local `pypi` dir to avoid using VCS packages.
"""
pkgs = {
"requests-2.19.1": "requests/requests-2.19.1.tar.gz",
"Flask-0.12.2": "flask/Flask-0.12.2.tar.gz",
"six-1.11.0": "six/six-1.11.0.tar.gz",
"Jinja2-2.10": "jinja2/Jinja2-2.10.tar.gz",
}
pkgs = ["requests", "flask", "six", "jinja2"]
pipfile_string = """
[dev-packages]
pipfile_string="""
[packages]
"""
# Unzip tarballs to known location, and update Pipfile template.
for pkg_name, file_name in pkgs.items():
source_path = str(Path(testsroot, "pypi", file_name))
unzip_path = str(Path(tmpdir.strpath, pkg_name))
import tarfile
with tarfile.open(source_path, "r:gz") as tgz:
tgz.extractall(path=tmpdir.strpath)
pipfile_string += "'{0}' = {{path = '{1}', editable = true}}\n".format(pkg_name, unzip_path)
with PipenvInstance(pypi=pypi, chdir=True) as p:
for pkg_name in pkgs:
source_path = p._pipfile.get_fixture_path("git/{0}".format(pkg_name)).as_posix()
pipfile_string += '"{0}" = {{path = "{1}", editable = true}}\n'.format(pkg_name, source_path)
with open(p.pipfile_path, 'w') as f:
f.write(pipfile_string.strip())
c = p.pipenv('install')
assert c.return_code == 0
c = p.pipenv('run python -c "import requests"')
assert c.return_code == 0
c = p.pipenv('run python -c "import flask"')
assert c.return_code == 0
c = p.pipenv('run python -c "import six"')
assert c.return_code == 0
c = p.pipenv('run python -c "import jinja2"')
assert c.return_code == 0
c = p.pipenv('run python -c "import requests, flask, six, jinja2"')
assert c.return_code == 0, c.err
+13 -24
View File
@@ -63,9 +63,10 @@ def test_ssh_vcs_install(PipenvInstance, pip_src_dir, pypi):
@pytest.mark.needs_internet
@flaky
def test_urls_work(PipenvInstance, pypi, pip_src_dir):
with PipenvInstance(pypi=pypi) as p:
with PipenvInstance(pypi=pypi, chdir=True) as p:
path = p._pipfile.get_fixture_path("django/3.4.x.zip")
c = p.pipenv(
"install https://github.com/divio/django-cms/archive/release/3.4.x.zip"
"install {0}".format(path.as_uri())
)
assert c.return_code == 0
@@ -187,27 +188,14 @@ six = "*"
@pytest.mark.needs_internet
def test_install_local_vcs_not_in_lockfile(PipenvInstance, pip_src_dir):
with PipenvInstance(chdir=True) as p:
six_path = os.path.join(p.path, "six")
c = delegator.run(
"git clone https://github.com/benjaminp/six.git {0}".format(six_path)
)
assert c.return_code == 0
c = p.pipenv("install -e ./six")
# six_path = os.path.join(p.path, "six")
six_path = p._pipfile.get_fixture_path("git/six").as_posix()
requests_uri = p._pipfile.get_fixture_path("git/requests").as_uri()
c = p.pipenv("install -e {0}".format(six_path))
assert c.return_code == 0
six_key = list(p.pipfile["packages"].keys())[0]
c = p.pipenv(
"install -e git+https://github.com/requests/requests.git#egg=requests"
)
assert c.return_code == 0
c = p.pipenv("lock")
assert c.return_code == 0
assert "requests" in p.pipfile["packages"]
assert "requests" in p.lockfile["default"]
# This is the hash of ./six
assert six_key in p.pipfile["packages"]
assert six_key in p.lockfile["default"]
# The hash isn't a hash anymore, its actually the name of the package (we now resolve this)
assert "six" in p.pipfile["packages"]
# we don't need the rest of the test anymore, this just works on its own
assert six_key == "six"
@pytest.mark.vcs
@@ -247,6 +235,7 @@ def test_vcs_entry_supersedes_non_vcs(PipenvInstance, pip_src_dir):
the resolution graph of non-editable vcs dependencies.
"""
with PipenvInstance(chdir=True) as p:
pyinstaller_path = p._pipfile.get_fixture_path("git/pyinstaller")
with open(p.pipfile_path, "w") as f:
f.write(
"""
@@ -257,8 +246,8 @@ name = "pypi"
[packages]
PyUpdater = "*"
PyInstaller = {ref = "develop", git = "https://github.com/pyinstaller/pyinstaller.git"}
""".strip()
PyInstaller = {{ref = "develop", git = "{0}"}}
""".format(pyinstaller_path.as_uri()).strip()
)
p.pipenv("install")
installed_packages = ["PyUpdater", "PyInstaller"]
@@ -268,7 +257,7 @@ PyInstaller = {ref = "develop", git = "https://github.com/pyinstaller/pyinstalle
assert p.lockfile["default"]["pyinstaller"].get("ref") is not None
assert (
p.lockfile["default"]["pyinstaller"]["git"]
== "https://github.com/pyinstaller/pyinstaller.git"
== pyinstaller_path.as_uri()
)
Binary file not shown.