mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
Converted some tests from legacy to the new test suite. I've also added a new mark for tests that use 'pipenv run'
This commit is contained in:
@@ -17,122 +17,6 @@ os.environ['PIPENV_IGNORE_VIRTUALENVS'] = 'True'
|
||||
|
||||
class TestPipenv():
|
||||
|
||||
def test_requirements_to_pipfile(self):
|
||||
delegator.run('mkdir test_requirements_to_pip')
|
||||
os.chdir('test_requirements_to_pip')
|
||||
|
||||
os.environ['PIPENV_VENV_IN_PROJECT'] = '1'
|
||||
os.environ['PIPENV_MAX_DEPTH'] = '1'
|
||||
|
||||
with open('requirements.txt', 'w') as f:
|
||||
f.write('requests[socks]==2.18.1\n'
|
||||
'git+https://github.com/kennethreitz/records.git@v0.5.0#egg=records\n'
|
||||
'-e git+https://github.com/kennethreitz/tablib.git@v0.11.5#egg=tablib\n'
|
||||
'six==1.10.0\n')
|
||||
|
||||
assert delegator.run('pipenv --python python').return_code == 0
|
||||
print(delegator.run('pipenv lock').err)
|
||||
assert delegator.run('pipenv lock').return_code == 0
|
||||
|
||||
pipfile_output = delegator.run('cat Pipfile').out
|
||||
lockfile_output = delegator.run('cat Pipfile.lock').out
|
||||
|
||||
# Ensure extras work.
|
||||
assert 'socks' in pipfile_output
|
||||
assert 'pysocks' in lockfile_output
|
||||
|
||||
# Ensure vcs dependencies work.
|
||||
assert 'records' in pipfile_output
|
||||
assert '"git": "https://github.com/kennethreitz/records.git"' in lockfile_output
|
||||
|
||||
# Ensure editable packages work.
|
||||
assert 'ref = "v0.11.5"' in pipfile_output
|
||||
assert '"editable": true' in lockfile_output
|
||||
|
||||
# Ensure BAD_PACKAGES aren't copied into Pipfile from requirements.txt.
|
||||
assert 'six = "==1.10.0"' not in pipfile_output
|
||||
|
||||
os.chdir('..')
|
||||
delegator.run('rm -fr test_requirements_to_pip')
|
||||
del os.environ['PIPENV_MAX_DEPTH']
|
||||
|
||||
def test_timeout_long(self):
|
||||
delegator.run('mkdir test_timeout_long')
|
||||
os.chdir('test_timeout_long')
|
||||
|
||||
os.environ['PIPENV_VENV_IN_PROJECT'] = '1'
|
||||
os.environ['PIPENV_TIMEOUT'] = '60'
|
||||
|
||||
assert delegator.run('touch Pipfile').return_code == 0
|
||||
|
||||
assert delegator.run('pipenv --python python').return_code == 0
|
||||
|
||||
os.chdir('..')
|
||||
delegator.run('rm -fr test_timeout_long')
|
||||
del os.environ['PIPENV_TIMEOUT']
|
||||
|
||||
def test_timeout_short(self):
|
||||
delegator.run('mkdir test_timeout_short')
|
||||
os.chdir('test_timeout_short')
|
||||
|
||||
os.environ['PIPENV_VENV_IN_PROJECT'] = '1'
|
||||
os.environ['PIPENV_TIMEOUT'] = '1'
|
||||
|
||||
assert delegator.run('touch Pipfile').return_code == 0
|
||||
|
||||
assert delegator.run('pipenv --python python').return_code == 1
|
||||
|
||||
os.chdir('..')
|
||||
delegator.run('rm -fr test_timeout_short')
|
||||
del os.environ['PIPENV_TIMEOUT']
|
||||
|
||||
def test_pipenv_run(self):
|
||||
working_dir = 'test_pipenv_run'
|
||||
delegator.run('mkdir {0}'.format(working_dir))
|
||||
os.chdir(working_dir)
|
||||
|
||||
# Build the environment.
|
||||
os.environ['PIPENV_VENV_IN_PROJECT'] = '1'
|
||||
delegator.run('touch Pipfile')
|
||||
|
||||
# Install packages for test.
|
||||
# print(delegator.run('pipenv install pep8').err)
|
||||
assert delegator.run('pipenv install pep8').return_code == 0
|
||||
assert delegator.run('pipenv install pytest').return_code == 0
|
||||
|
||||
# Run test commands.
|
||||
assert delegator.run('pipenv run python -c \'print("test")\'').return_code == 0
|
||||
assert delegator.run('pipenv run pep8 --version').return_code == 0
|
||||
assert delegator.run('pipenv run pytest --version').return_code == 0
|
||||
|
||||
os.chdir('..')
|
||||
delegator.run('rm -fr {0}'.format(working_dir))
|
||||
|
||||
@pytest.mark.parametrize('shell, extension', [
|
||||
('/bin/bash', ''),
|
||||
('/bin/fish', '.fish'),
|
||||
('/bin/csh', '.csh'),
|
||||
('/bin/unknown', '')]
|
||||
)
|
||||
def test_activate_virtualenv(self, shell, extension):
|
||||
orig_shell = os.environ['SHELL']
|
||||
os.environ['SHELL'] = shell
|
||||
|
||||
# Get standard activation command for bash
|
||||
command = activate_virtualenv()
|
||||
|
||||
# Return environment to initial shell config.
|
||||
os.environ['SHELL'] = orig_shell
|
||||
|
||||
venv = Project().virtualenv_location
|
||||
assert command == 'source {0}/bin/activate{1}'.format(venv, extension)
|
||||
|
||||
def test_activate_virtualenv_no_source(self):
|
||||
command = activate_virtualenv(source=False)
|
||||
venv = Project().virtualenv_location
|
||||
|
||||
assert command == '{0}/bin/activate'.format(venv)
|
||||
|
||||
@patch('pipenv.project.Project.sources', new_callable=PropertyMock)
|
||||
@patch('delegator.run')
|
||||
def test_pip_install_should_try_every_possible_source(self, mocked_delegator, mocked_sources):
|
||||
|
||||
+39
-2
@@ -7,6 +7,7 @@ import pytest
|
||||
|
||||
from pipenv.vendor import toml
|
||||
from pipenv.vendor import delegator
|
||||
from pipenv.project import Project
|
||||
|
||||
os.environ['PIPENV_DONT_USE_PYENV'] = '1'
|
||||
|
||||
@@ -170,8 +171,9 @@ class TestPipenv:
|
||||
assert 'urllib3' in p.lockfile['default']
|
||||
assert 'certifi' in p.lockfile['default']
|
||||
|
||||
@pytest.mark.install
|
||||
@pytest.mark.dev
|
||||
@pytest.mark.run
|
||||
@pytest.mark.install
|
||||
def test_basic_dev_install(self):
|
||||
with PipenvInstance() as p:
|
||||
c = p.pipenv('install requests --dev')
|
||||
@@ -186,6 +188,7 @@ class TestPipenv:
|
||||
c = p.pipenv('run python -m requests.help')
|
||||
assert c.return_code == 0
|
||||
|
||||
@pytest.mark.run
|
||||
@pytest.mark.uninstall
|
||||
def test_uninstall(self):
|
||||
with PipenvInstance() as p:
|
||||
@@ -251,6 +254,7 @@ class TestPipenv:
|
||||
assert 'urllib3' in p.lockfile['default']
|
||||
assert 'certifi' in p.lockfile['default']
|
||||
|
||||
@pytest.mark.run
|
||||
@pytest.mark.install
|
||||
def test_multiprocess_bug_and_install(self):
|
||||
os.environ['PIPENV_MAX_SUBPROCESS'] = '2'
|
||||
@@ -309,6 +313,7 @@ tpfd = "*"
|
||||
c = p.pipenv('run python -c "import requests; import idna; import certifi; import records; import tpfd; import parse;"')
|
||||
assert c.return_code == 0
|
||||
|
||||
@pytest.mark.run
|
||||
@pytest.mark.markers
|
||||
@pytest.mark.install
|
||||
def test_package_environment_markers(self):
|
||||
@@ -330,6 +335,7 @@ requests = {version = "*", markers="os_name=='splashwear'"}
|
||||
c = p.pipenv('run python -c "import requests;"')
|
||||
assert c.return_code == 1
|
||||
|
||||
@pytest.mark.run
|
||||
@pytest.mark.alt
|
||||
@pytest.mark.install
|
||||
def test_specific_package_environment_markers(self):
|
||||
@@ -351,6 +357,7 @@ requests = {version = "*", os_name = "== 'splashwear'"}
|
||||
c = p.pipenv('run python -c "import requests;"')
|
||||
assert c.return_code == 1
|
||||
|
||||
@pytest.mark.run
|
||||
@pytest.mark.alt
|
||||
@pytest.mark.install
|
||||
def test_alternative_version_specifier(self):
|
||||
@@ -393,6 +400,7 @@ requests = {version = "*"}
|
||||
|
||||
del os.environ['PIPENV_VENV_IN_PROJECT']
|
||||
|
||||
@pytest.mark.run
|
||||
@pytest.mark.dotenv
|
||||
def test_env(self):
|
||||
with PipenvInstance(pipfile=False) as p:
|
||||
@@ -484,4 +492,33 @@ requests = {version = "*"}
|
||||
assert 'chardet' in p.lockfile['default']
|
||||
assert 'idna' in p.lockfile['default']
|
||||
assert 'urllib3' in p.lockfile['default']
|
||||
assert 'pysocks' in p.lockfile['default']
|
||||
assert 'pysocks' in p.lockfile['default']
|
||||
|
||||
@pytest.mark.code
|
||||
@pytest.mark.virtualenv
|
||||
@pytest.mark.parametrize('shell, extension', [
|
||||
('/bin/bash', ''),
|
||||
('/bin/fish', '.fish'),
|
||||
('/bin/csh', '.csh'),
|
||||
('/bin/unknown', '')]
|
||||
)
|
||||
def test_activate_virtualenv(self, shell, extension):
|
||||
orig_shell = os.environ['SHELL']
|
||||
os.environ['SHELL'] = shell
|
||||
|
||||
# Get standard activation command for bash
|
||||
command = activate_virtualenv()
|
||||
|
||||
# Return environment to initial shell config.
|
||||
os.environ['SHELL'] = orig_shell
|
||||
|
||||
venv = Project().virtualenv_location
|
||||
assert command == 'source {0}/bin/activate{1}'.format(venv, extension)
|
||||
|
||||
@pytest.mark.code
|
||||
@pytest.mark.virtualenv
|
||||
def test_activate_virtualenv_no_source(self):
|
||||
command = activate_virtualenv(source=False)
|
||||
venv = Project().virtualenv_location
|
||||
|
||||
assert command == '{0}/bin/activate'.format(venv)
|
||||
Reference in New Issue
Block a user