Files
pipenv/tests/integration/test_sync.py
T
Matt Davis 9848862927 Convert test runner to use pypiserver package as standalone process (#5284)
* Check point progress on moving tests to pypiserver.

* Allow other indexes to mimic the pypi json API for package hashes.

* Fix these tests that run on lower python versions only.

* Try adding the pypiserver to the github actions to only run once.

* Expand the scope of fixtures for pypiserver.

* try to accomedate microsoft runner.

* Windows networking troubles.

* Remove running as a background job.

* Try to condtionally invoke different start pypi-server commands

* Try to condtionally invoke different start pypi-server commands

* Try to condtionally invoke different start pypi-server commands

* Try to condtionally invoke different start pypi-server commands

* Try to condtionally invoke different start pypi-server commands

* Try to condtionally invoke different start pypi-server commands

* Try to condtionally invoke different start pypi-server commands

* Try to introduce pypi as the root index because setuptools-scm is not in our pypi artifacts.

* see if the windows tests run faster (and the other tests) by supplying waitress.

* Only use waitress on windows because the others are fast on the default.  Fix requests pollution.

* Supply a suitable Pipfile instead for these two failing tests.

* More requests resolver cross test contamination cleanup.

* remove problematic tests because even on my version of python 3.8.12 this does not work due to AttributeError: 'HTMLParser' object has no attribute 'unescape'

* fix mirror install test.

* Fix Pipfile.

* Fix Pipfile for real

* Fix tests

* Cleanup test naming and more test enhancements.

* Save this optimization for a subsequent PR.

* Cleanup the TemporaryDirectory between tests.

* resolve merge conflict.

* Cleanup path initalization -- it hsould always be a TemporaryDirectory for tests that gets cleanedup.

* Cleanup path initalization -- it hsould always be a TemporaryDirectory for tests that gets cleanedup.

* tableflip on those requests tests that read the setup metadata in reqlib from other tests.

* Update developer documentation for running tests.

* add news fragment.

* Try gunicorn perfoormance for linux/mac

* Only use gunicorn on linux based on the results of last run.
2022-09-05 10:19:12 -04:00

122 lines
3.2 KiB
Python

import json
import os
import pytest
from pipenv.utils.shell import temp_environ
@pytest.mark.lock
@pytest.mark.sync
def test_sync_error_without_lockfile(pipenv_instance_pypi):
with pipenv_instance_pypi(chdir=True) as p:
with open(p.pipfile_path, 'w') as f:
f.write("""
[packages]
""".strip())
c = p.pipenv('sync')
assert c.returncode != 0
assert 'Pipfile.lock not found!' in c.stderr
@pytest.mark.sync
@pytest.mark.lock
def test_mirror_lock_sync(pipenv_instance_private_pypi):
with temp_environ(), pipenv_instance_private_pypi(chdir=True) as p:
mirror_url = os.environ.get('PIPENV_TEST_INDEX')
assert 'pypi.org' not in mirror_url
with open(p.pipfile_path, 'w') as f:
f.write("""
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[packages]
six = "*"
""".strip())
c = p.pipenv(f'lock --pypi-mirror {mirror_url}')
assert c.returncode == 0
c = p.pipenv(f'sync --pypi-mirror {mirror_url}')
assert c.returncode == 0
@pytest.mark.sync
@pytest.mark.lock
def test_sync_should_not_lock(pipenv_instance_pypi):
"""Sync should not touch the lock file, even if Pipfile is changed.
"""
with pipenv_instance_pypi(chdir=True) as p:
with open(p.pipfile_path, 'w') as f:
f.write("""
[packages]
""".strip())
# Perform initial lock.
c = p.pipenv('lock')
assert c.returncode == 0
lockfile_content = p.lockfile
assert lockfile_content
# Make sure sync does not trigger lockfile update.
with open(p.pipfile_path, 'w') as f:
f.write("""
[packages]
six = "*"
""".strip())
c = p.pipenv('sync')
assert c.returncode == 0
assert lockfile_content == p.lockfile
@pytest.mark.sync
@pytest.mark.lock
def test_sync_sequential_detect_errors(pipenv_instance_private_pypi):
with pipenv_instance_private_pypi() as p:
with open(p.pipfile_path, 'w') as f:
contents = """
[packages]
requests = "*"
""".strip()
f.write(contents)
c = p.pipenv('lock')
assert c.returncode == 0
# Force hash mismatch when installing `requests`
lock = p.lockfile
lock['default']['requests']['hashes'] = ['sha256:' + '0' * 64]
with open(p.lockfile_path, 'w') as f:
json.dump(lock, f)
c = p.pipenv('sync --sequential')
assert c.returncode != 0
@pytest.mark.sync
def test_sync_consider_pip_target(pipenv_instance_pypi):
"""
"""
with pipenv_instance_pypi(chdir=True) as p:
with open(p.pipfile_path, 'w') as f:
f.write("""
[packages]
six = "*"
""".strip())
# Perform initial lock.
c = p.pipenv('lock')
assert c.returncode == 0
lockfile_content = p.lockfile
assert lockfile_content
c = p.pipenv('sync')
assert c.returncode == 0
pip_target_dir = 'target_dir'
os.environ['PIP_TARGET'] = pip_target_dir
c = p.pipenv('sync')
assert c.returncode == 0
assert 'six.py' in os.listdir(os.path.join(p.path, pip_target_dir))
os.environ.pop('PIP_TARGET')