From 26789d076ecfa731b3819388568c9a0204f86803 Mon Sep 17 00:00:00 2001 From: Erin O'Connell Date: Sun, 3 Sep 2017 09:10:35 -0600 Subject: [PATCH 01/17] Added utils.py tests back in for appveyor --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index da068d23..5fd2b2bc 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -52,3 +52,4 @@ install: test_script: - "pipenv run pytest test_windows" + - "pipenv run pytest tests/test_utils.py" From 49dfcd6b60acc046ffb356e33179371e7e5a55e6 Mon Sep 17 00:00:00 2001 From: Erin O'Connell Date: Sun, 3 Sep 2017 21:29:29 -0600 Subject: [PATCH 02/17] tests_windows and test_utils.py --- appveyor.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 5fd2b2bc..8da49a2f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -51,5 +51,4 @@ install: - "pipenv install --dev" test_script: - - "pipenv run pytest test_windows" - - "pipenv run pytest tests/test_utils.py" + - "pipenv run pytest test_windows/ tests/test_utils.py" From 4e37585a88d87ad959ccd686cbc19a37eccc654e Mon Sep 17 00:00:00 2001 From: Erin O'Connell Date: Sun, 3 Sep 2017 22:38:34 -0600 Subject: [PATCH 03/17] pip install -e . --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 8da49a2f..d31b4036 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -47,7 +47,7 @@ install: # Upgrade to the latest version of pip to avoid it displaying warnings # about it being out of date. - "pip install --disable-pip-version-check --user --upgrade pip" - - "python setup.py develop" + - "pip install -e ." - "pipenv install --dev" test_script: From 44172488b02a3449a907014baf9f6bb30d62fa1d Mon Sep 17 00:00:00 2001 From: Erin O'Connell Date: Sun, 3 Sep 2017 23:10:16 -0600 Subject: [PATCH 04/17] added test_parse_download and a basic test_cli usage --- test_windows/test_basic.py | 59 +++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/test_windows/test_basic.py b/test_windows/test_basic.py index 4c450eee..bab2a1ff 100644 --- a/test_windows/test_basic.py +++ b/test_windows/test_basic.py @@ -1,15 +1,60 @@ +import os + +#from mock import patch, Mock, PropertyMock + +import pytest import delegator +import toml + +from pipenv.cli import (activate_virtualenv, ensure_proper_casing, + parse_download_fname, parse_install_output, pip_install, pip_download) +from pipenv.project import Project -class TestPipenv(): +class TestPipenvWindows(): def test_existience(self): assert True - def test_install(self): - c = delegator.run('pipenv install') - assert c.return_code == 0 + @pytest.mark.parametrize('fname, name, expected', [ + ('functools32-3.2.3-2.zip', 'functools32', '3.2.3'), + ('functools32-3.2.3-blah.zip', 'functools32', '3.2.3-blah'), + ('functools32-3.2.3.zip', 'functools32', '3.2.3'), + ('colorama-0.3.7-py2.py3-none-any.whl', 'colorama', '0.3.7'), + ('colorama-0.3.7-2-py2.py3-none-any.whl', 'colorama', '0.3.7'), + ('click-completion-0.2.1.tar.gz', 'click-completion', '0.2.1'), + ('Twisted-16.5.0.tar.bz2', 'Twisted', '16.5.0'), + ('Twisted-16.1.1-cp27-none-win_amd64.whl', 'twIsteD', '16.1.1'), + ('pdfminer.six-20140915.zip', 'pdfMiner.SIX', '20140915') + ]) + def test_parse_download_fname(self, fname, name, expected): + version = parse_download_fname(fname, name) + assert version == expected - def test_lock(self): - c = delegator.run('pipenv lock') - assert c.return_code == 0 + def test_cli_usage(self): + delegator.run('mkdir test_project') + os.chdir('test_project') + + os.environ['PIPENV_VENV_IN_PROJECT'] = '1' + + assert delegator.run('echo $null >> Pipfile').return_code == 0 + + assert delegator.run('pipenv --python python').return_code == 0 + assert delegator.run('pipenv install Werkzeug').return_code == 0 + assert delegator.run('pipenv install pytest --dev').return_code == 0 + assert delegator.run('pipenv install git+https://github.com/requests/requests.git@v2.18.4#egg=requests').return_code == 0 + assert delegator.run('pipenv lock').return_code == 0 + + # Test uninstalling a package after locking. + assert delegator.run('pipenv uninstall Werkzeug').return_code == 0 + + pipfile_output = delegator.run('cat Pipfile').out + lockfile_output = delegator.run('cat Pipfile.lock').out + + # def test_install(self): + # c = delegator.run('pipenv install') + # assert c.return_code == 0 + + # def test_lock(self): + # c = delegator.run('pipenv lock') + # assert c.return_code == 0 From 0094ccfa12ecb082445e9c53193e7178fc698a9b Mon Sep 17 00:00:00 2001 From: Erin O'Connell Date: Mon, 4 Sep 2017 00:08:39 -0600 Subject: [PATCH 05/17] got test_cli_usage to work on windows! --- test_windows/test_basic.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/test_windows/test_basic.py b/test_windows/test_basic.py index bab2a1ff..133ad237 100644 --- a/test_windows/test_basic.py +++ b/test_windows/test_basic.py @@ -1,4 +1,5 @@ import os +import shutil #from mock import patch, Mock, PropertyMock @@ -37,7 +38,7 @@ class TestPipenvWindows(): os.environ['PIPENV_VENV_IN_PROJECT'] = '1' - assert delegator.run('echo $null >> Pipfile').return_code == 0 + assert delegator.run('copy /y nul Pipfile').return_code == 0 assert delegator.run('pipenv --python python').return_code == 0 assert delegator.run('pipenv install Werkzeug').return_code == 0 @@ -48,8 +49,23 @@ class TestPipenvWindows(): # Test uninstalling a package after locking. assert delegator.run('pipenv uninstall Werkzeug').return_code == 0 - pipfile_output = delegator.run('cat Pipfile').out - lockfile_output = delegator.run('cat Pipfile.lock').out + pipfile_output = delegator.run('type Pipfile').out + lockfile_output = delegator.run('type Pipfile.lock').out + + # Ensure uninstall works. + assert 'Werkzeug' not in pipfile_output + assert 'werkzeug' not in lockfile_output + + # Ensure dev-packages work. + assert 'pytest' in pipfile_output + assert 'pytest' in lockfile_output + + # Ensure vcs dependencies work. + assert 'requests' in pipfile_output + assert '"git": "https://github.com/requests/requests.git"' in lockfile_output + + os.chdir('..') + shutil.rmtree('test_project') # def test_install(self): # c = delegator.run('pipenv install') From 6778cf042e1eb7f26b92bdbf899edd5bac20a8e2 Mon Sep 17 00:00:00 2001 From: Erin O'Connell Date: Mon, 4 Sep 2017 00:27:37 -0600 Subject: [PATCH 06/17] added test_requirements_to_pipfile --- test_windows/test_basic.py | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test_windows/test_basic.py b/test_windows/test_basic.py index 133ad237..4401e98c 100644 --- a/test_windows/test_basic.py +++ b/test_windows/test_basic.py @@ -67,6 +67,45 @@ class TestPipenvWindows(): os.chdir('..') shutil.rmtree('test_project') + 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('type Pipfile').out + lockfile_output = delegator.run('type Pipfile.lock').out + + # Ensure extras work. + assert 'extras = [ "socks",]' in pipfile_output + assert 'pysocks' in lockfile_output + + # Ensure vcs dependencies work. + assert 'packages.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('..') + shutil.rmtree('test_requirements_to_pip') + del os.environ['PIPENV_MAX_DEPTH'] + # def test_install(self): # c = delegator.run('pipenv install') # assert c.return_code == 0 From 3331ec9b076eee67193ce64ae923dd9a56e87dd8 Mon Sep 17 00:00:00 2001 From: Erin O'Connell Date: Mon, 4 Sep 2017 00:28:07 -0600 Subject: [PATCH 07/17] added timeout tests --- test_windows/test_basic.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test_windows/test_basic.py b/test_windows/test_basic.py index 4401e98c..5ae142c0 100644 --- a/test_windows/test_basic.py +++ b/test_windows/test_basic.py @@ -106,6 +106,36 @@ class TestPipenvWindows(): shutil.rmtree('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('copy /y nul Pipfile').return_code == 0 + + assert delegator.run('pipenv --python python').return_code == 0 + + os.chdir('..') + shutil.rmtree('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'] = '0' + + assert delegator.run('copy /y nul Pipfile').return_code == 0 + + assert delegator.run('pipenv --python python').return_code == 1 + + os.chdir('..') + shutil.rmtree('test_timeout_short') + del os.environ['PIPENV_TIMEOUT'] + # def test_install(self): # c = delegator.run('pipenv install') # assert c.return_code == 0 From a01e06cdd20af3fa7979563603acfb069a64ddd8 Mon Sep 17 00:00:00 2001 From: Erin O'Connell Date: Mon, 4 Sep 2017 00:28:36 -0600 Subject: [PATCH 08/17] removed some unused tests --- test_windows/test_basic.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test_windows/test_basic.py b/test_windows/test_basic.py index 5ae142c0..e2c5ed6d 100644 --- a/test_windows/test_basic.py +++ b/test_windows/test_basic.py @@ -135,11 +135,3 @@ class TestPipenvWindows(): os.chdir('..') shutil.rmtree('test_timeout_short') del os.environ['PIPENV_TIMEOUT'] - - # def test_install(self): - # c = delegator.run('pipenv install') - # assert c.return_code == 0 - - # def test_lock(self): - # c = delegator.run('pipenv lock') - # assert c.return_code == 0 From cae5fc0346f63cc9ee17d5f0084f9e98246838a4 Mon Sep 17 00:00:00 2001 From: Erin O'Connell Date: Mon, 4 Sep 2017 00:42:02 -0600 Subject: [PATCH 09/17] flake8 nit picking --- test_windows/test_basic.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test_windows/test_basic.py b/test_windows/test_basic.py index e2c5ed6d..0711d55d 100644 --- a/test_windows/test_basic.py +++ b/test_windows/test_basic.py @@ -1,15 +1,15 @@ import os import shutil -#from mock import patch, Mock, PropertyMock +# from mock import patch, Mock, PropertyMock import pytest import delegator -import toml +# import toml -from pipenv.cli import (activate_virtualenv, ensure_proper_casing, - parse_download_fname, parse_install_output, pip_install, pip_download) -from pipenv.project import Project +# from pipenv.cli import (activate_virtualenv, ensure_proper_casing, +# parse_download_fname, parse_install_output, pip_install, pip_download) +# from pipenv.project import Project class TestPipenvWindows(): From ff539959f354e39b2468b3311acc586d3f0f4761 Mon Sep 17 00:00:00 2001 From: Erin O'Connell Date: Mon, 4 Sep 2017 00:50:14 -0600 Subject: [PATCH 10/17] Revert "flake8 nit picking". This broke some stuff This reverts commit cae5fc0346f63cc9ee17d5f0084f9e98246838a4. --- test_windows/test_basic.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test_windows/test_basic.py b/test_windows/test_basic.py index 0711d55d..e2c5ed6d 100644 --- a/test_windows/test_basic.py +++ b/test_windows/test_basic.py @@ -1,15 +1,15 @@ import os import shutil -# from mock import patch, Mock, PropertyMock +#from mock import patch, Mock, PropertyMock import pytest import delegator -# import toml +import toml -# from pipenv.cli import (activate_virtualenv, ensure_proper_casing, -# parse_download_fname, parse_install_output, pip_install, pip_download) -# from pipenv.project import Project +from pipenv.cli import (activate_virtualenv, ensure_proper_casing, + parse_download_fname, parse_install_output, pip_install, pip_download) +from pipenv.project import Project class TestPipenvWindows(): From d9cae5148c98c0cd133e89036ba150ee87fa451c Mon Sep 17 00:00:00 2001 From: Erin O'Connell Date: Mon, 4 Sep 2017 16:53:36 -0600 Subject: [PATCH 11/17] Ported more tests to windwos --- test_windows/test_basic.py | 85 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/test_windows/test_basic.py b/test_windows/test_basic.py index e2c5ed6d..eb9fa79b 100644 --- a/test_windows/test_basic.py +++ b/test_windows/test_basic.py @@ -135,3 +135,88 @@ class TestPipenvWindows(): os.chdir('..') shutil.rmtree('test_timeout_short') del os.environ['PIPENV_TIMEOUT'] + + def test_pipenv_uninstall(self): + delegator.run('mkdir test_pipenv_uninstall') + os.chdir('test_pipenv_uninstall') + + # Build the environment. + os.environ['PIPENV_VENV_IN_PROJECT'] = '1' + assert delegator.run('copy /y nul Pipfile').return_code == 0 + assert delegator.run('pipenv --python python').return_code == 0 + + # Add entries to Pipfile. + assert delegator.run('pipenv install Werkzeug').return_code == 0 + assert delegator.run('pipenv install pytest --dev').return_code == 0 + + pipfile_output = delegator.run('type Pipfile').out + pipfile_list = pipfile_output.split('\n') + + assert 'Werkzeug = "*"' in pipfile_list + assert 'pytest = "*"' in pipfile_list + assert '[packages]' in pipfile_list + assert '[dev-packages]' in pipfile_list + + # Uninstall from dev-packages, removing TOML section. + assert delegator.run('pipenv uninstall pytest').return_code == 0 + + # Test uninstalling non-existant dependency. + c = delegator.run('pipenv uninstall NotAPackage') + assert c.return_code == 0 + assert 'No package NotAPackage to remove from Pipfile.' in c.out + + pipfile_output = delegator.run('type Pipfile').out + pipfile_list = pipfile_output.split('\n') + + assert 'Werkzeug = "*"' in pipfile_list + assert 'pytest = "*"' not in pipfile_list + assert '[packages]' in pipfile_list + assert '[dev-packages]' not in pipfile_list + + os.chdir('..') + shutil.rmtree('rm -fr test_pipenv_uninstall') + + 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' + + # Install packages for test. + 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('..') + shutil.rmtree(''.format(working_dir)) + + def test_ensure_proper_casing_names(self): + """Ensure proper casing for package names.""" + pfile_test = ("[packages]\n" + "DjAnGO = \"*\"\n" + "flask = \"==0.11\"\n" + "\n\n" + "[dev-packages]\n" + "PyTEST = \"*\"\n") + + # Load test Pipfile. + p = toml.loads(pfile_test) + + assert 'DjAnGO' in p['packages'] + assert 'PyTEST' in p['dev-packages'] + + changed = ensure_proper_casing(p) + + assert 'Django' in p['packages'] + assert 'DjAnGO' not in p['packages'] + + assert 'pytest' in p['dev-packages'] + assert 'PyTEST' not in p['dev-packages'] + + assert changed is True \ No newline at end of file From cfd2b54332ff8ee106978fab6d8340cd182eb9a6 Mon Sep 17 00:00:00 2001 From: Erin O'Connell Date: Mon, 4 Sep 2017 16:59:13 -0600 Subject: [PATCH 12/17] what was I thinking --- test_windows/test_basic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test_windows/test_basic.py b/test_windows/test_basic.py index eb9fa79b..8e7e3cd5 100644 --- a/test_windows/test_basic.py +++ b/test_windows/test_basic.py @@ -174,7 +174,7 @@ class TestPipenvWindows(): assert '[dev-packages]' not in pipfile_list os.chdir('..') - shutil.rmtree('rm -fr test_pipenv_uninstall') + shutil.rmtree('test_pipenv_uninstall') def test_pipenv_run(self): working_dir = 'test_pipenv_run' @@ -194,7 +194,7 @@ class TestPipenvWindows(): assert delegator.run('pipenv run pytest --version').return_code == 0 os.chdir('..') - shutil.rmtree(''.format(working_dir)) + shutil.rmtree(working_dir) def test_ensure_proper_casing_names(self): """Ensure proper casing for package names.""" From 94ccd66163f53c5d1d8191863a67be0dc1e3d89c Mon Sep 17 00:00:00 2001 From: Erin O'Connell Date: Mon, 4 Sep 2017 22:19:07 -0600 Subject: [PATCH 13/17] finished porting test_pipenv to windows --- test_windows/test_basic.py | 158 ++++++++++++++++++++++++++++++++++++- 1 file changed, 156 insertions(+), 2 deletions(-) diff --git a/test_windows/test_basic.py b/test_windows/test_basic.py index 8e7e3cd5..47ea8996 100644 --- a/test_windows/test_basic.py +++ b/test_windows/test_basic.py @@ -1,7 +1,7 @@ import os import shutil -#from mock import patch, Mock, PropertyMock +from mock import patch, Mock, PropertyMock import pytest import delegator @@ -219,4 +219,158 @@ class TestPipenvWindows(): assert 'pytest' in p['dev-packages'] assert 'PyTEST' not in p['dev-packages'] - assert changed is True \ No newline at end of file + assert changed is True + + def test_parse_install_output(self): + """Ensure pip output is parsed properly.""" + install_output = ("Collecting requests\n" + "Using cached requests-2.13.0-py2.py3-none-any.whl\n" + "Successfully downloaded requests-2.13.0\n" + "Collecting honcho\n" + "Using cached honcho-0.7.1.tar.gz\n" + "Successfully downloaded honcho-0.7.1\n" + "Collecting foursquare\n" + "Downloading foursquare-1%212015.4.7.tar.gz\n" + "Saved ./foursquare-1%212015.4.7.tar.gz\n" + "Successfully downloaded foursquare\n" + "Collecting django-debug-toolbar\n" + "Using cached django_debug_toolbar-1.6-py2.py3-none-any.whl\n" + "Collecting sqlparse>=0.2.0 (from django-debug-toolbar)\n" + "Using cached sqlparse-0.2.2-py2.py3-none-any.whl\n") + + names_map = dict(parse_install_output(install_output)) + + # Verify files are added to names map with appropriate project name. + assert 'requests-2.13.0-py2.py3-none-any.whl' in names_map + assert names_map['requests-2.13.0-py2.py3-none-any.whl'] == 'requests' + + # Verify percent-encoded characters are unencoded (%21 -> !). + assert 'foursquare-1!2015.4.7.tar.gz' in names_map + + # Verify multiple dashes in name is parsed correctly. + assert 'django_debug_toolbar-1.6-py2.py3-none-any.whl' in names_map + assert names_map['django_debug_toolbar-1.6-py2.py3-none-any.whl'] == 'django-debug-toolbar' + + @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): + sources = [ + {'url': 'http://dontexistis.in.pypi/simple'}, + {'url': 'http://existis.in.pypi/simple'} + ] + mocked_sources.return_value = sources + first_cmd_return = Mock() + first_cmd_return.return_code = 1 + second_cmd_return = Mock() + second_cmd_return.return_code = 0 + mocked_delegator.side_effect = [first_cmd_return, second_cmd_return] + c = pip_install('package') + assert c.return_code == 0 + + @patch('pipenv.project.Project.sources', new_callable=PropertyMock) + @patch('delegator.run') + def test_pip_install_should_return_the_last_error_if_no_cmd_worked(self, mocked_delegator, mocked_sources): + sources = [ + {'url': 'http://dontexistis.in.pypi/simple'}, + {'url': 'http://dontexistis.in.pypi/simple'} + ] + mocked_sources.return_value = sources + first_cmd_return = Mock() + first_cmd_return.return_code = 1 + second_cmd_return = Mock() + second_cmd_return.return_code = 1 + mocked_delegator.side_effect = [first_cmd_return, second_cmd_return] + c = pip_install('package') + assert c.return_code == 1 + assert c == second_cmd_return + + @patch('pipenv.project.Project.sources', new_callable=PropertyMock) + @patch('delegator.run') + def test_pip_install_should_return_the_first_cmd_that_worked(self, mocked_delegator, mocked_sources): + sources = [ + {'url': 'http://existis.in.pypi/simple'}, + {'url': 'http://existis.in.pypi/simple'} + ] + mocked_sources.return_value = sources + first_cmd_return = Mock() + first_cmd_return.return_code = 0 + second_cmd_return = Mock() + second_cmd_return.return_code = 0 + mocked_delegator.side_effect = [first_cmd_return, second_cmd_return] + c = pip_install('package') + assert c.return_code == 0 + assert c == first_cmd_return + + @patch('pipenv.project.Project.sources', new_callable=PropertyMock) + @patch('delegator.run') + def test_pip_download_should_try_every_possible_source(self, mocked_delegator, mocked_sources): + sources = [ + {'url': 'http://dontexistis.in.pypi/simple'}, + {'url': 'http://existis.in.pypi/simple'} + ] + mocked_sources.return_value = sources + first_cmd_return = Mock() + first_cmd_return.return_code = 1 + second_cmd_return = Mock() + second_cmd_return.return_code = 0 + mocked_delegator.side_effect = [first_cmd_return, second_cmd_return] + c = pip_download('package') + assert c.return_code == 0 + + @patch('pipenv.project.Project.sources', new_callable=PropertyMock) + @patch('delegator.run') + def test_pip_download_should_return_the_last_error_if_no_cmd_worked(self, mocked_delegator, mocked_sources): + sources = [ + {'url': 'http://dontexistis.in.pypi/simple'}, + {'url': 'http://dontexistis.in.pypi/simple'} + ] + mocked_sources.return_value = sources + first_cmd_return = Mock() + first_cmd_return.return_code = 1 + second_cmd_return = Mock() + second_cmd_return.return_code = 1 + mocked_delegator.side_effect = [first_cmd_return, second_cmd_return] + c = pip_download('package') + assert c.return_code == 1 + assert c == second_cmd_return + + @patch('pipenv.project.Project.sources', new_callable=PropertyMock) + @patch('delegator.run') + def test_pip_download_should_return_the_first_cmd_that_worked(self, mocked_delegator, mocked_sources): + sources = [ + {'url': 'http://existis.in.pypi/simple'}, + {'url': 'http://existis.in.pypi/simple'} + ] + mocked_sources.return_value = sources + first_cmd_return = Mock() + first_cmd_return.return_code = 0 + second_cmd_return = Mock() + second_cmd_return.return_code = 0 + mocked_delegator.side_effect = [first_cmd_return, second_cmd_return] + c = pip_download('package') + assert c.return_code == 0 + assert c == first_cmd_return + + def test_lock_requirements_file(self): + delegator.run('mkdir test_pipenv_requirements') + os.chdir('test_pipenv_requirements') + + os.environ['PIPENV_VENV_IN_PROJECT'] = '1' + + assert delegator.run('copy /y nul Pipfile').return_code == 0 + assert delegator.run('pipenv --python python').return_code == 0 + assert delegator.run('pipenv install requests==2.14.0').return_code == 0 + assert delegator.run('pipenv install flask==0.12.2').return_code == 0 + assert delegator.run('pipenv install --dev pytest==3.1.1').return_code == 0 + + req_list = ("requests==2.14.0", "flask==0.12.2", "pytest==3.1.1") + + # Validate requirements.txt. + c = delegator.run('pipenv lock -r') + assert c.return_code == 0 + for req in req_list: + assert req in c.out + + # Cleanup. + os.chdir('..') + shutil.rmtree('test_pipenv_requirements') \ No newline at end of file From 20dd018afee3da4c4d4d815beffb2b302e09d275 Mon Sep 17 00:00:00 2001 From: Erin O'Connell Date: Mon, 4 Sep 2017 22:20:37 -0600 Subject: [PATCH 14/17] renamed test file --- test_windows/{test_basic.py => test_pipenv.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test_windows/{test_basic.py => test_pipenv.py} (100%) diff --git a/test_windows/test_basic.py b/test_windows/test_pipenv.py similarity index 100% rename from test_windows/test_basic.py rename to test_windows/test_pipenv.py From ee57a85d2edcd789862de617d19fc5425a9d0ff2 Mon Sep 17 00:00:00 2001 From: Erin O'Connell Date: Mon, 4 Sep 2017 22:28:36 -0600 Subject: [PATCH 15/17] added project tests --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index d31b4036..19f08589 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -51,4 +51,4 @@ install: - "pipenv install --dev" test_script: - - "pipenv run pytest test_windows/ tests/test_utils.py" + - "pipenv run pytest test_windows/ tests/test_utils.py tests/test_project.py" From f16d46dec728c31dd52b93cc054ca5006d6dd4b0 Mon Sep 17 00:00:00 2001 From: Erin O'Connell Date: Mon, 4 Sep 2017 22:37:53 -0600 Subject: [PATCH 16/17] fixed some flake8 stuff --- test_windows/test_pipenv.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test_windows/test_pipenv.py b/test_windows/test_pipenv.py index 47ea8996..b1877ed5 100644 --- a/test_windows/test_pipenv.py +++ b/test_windows/test_pipenv.py @@ -7,9 +7,8 @@ import pytest import delegator import toml -from pipenv.cli import (activate_virtualenv, ensure_proper_casing, +from pipenv.cli import (ensure_proper_casing, parse_download_fname, parse_install_output, pip_install, pip_download) -from pipenv.project import Project class TestPipenvWindows(): @@ -364,7 +363,7 @@ class TestPipenvWindows(): assert delegator.run('pipenv install --dev pytest==3.1.1').return_code == 0 req_list = ("requests==2.14.0", "flask==0.12.2", "pytest==3.1.1") - + # Validate requirements.txt. c = delegator.run('pipenv lock -r') assert c.return_code == 0 @@ -373,4 +372,4 @@ class TestPipenvWindows(): # Cleanup. os.chdir('..') - shutil.rmtree('test_pipenv_requirements') \ No newline at end of file + shutil.rmtree('test_pipenv_requirements') From 08c3e273bdd9053b4edc0399abfde78be85aa9e5 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Tue, 5 Sep 2017 09:13:35 -0400 Subject: [PATCH 17/17] try this Signed-off-by: Kenneth Reitz --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 19f08589..7b79fe82 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -47,7 +47,7 @@ install: # Upgrade to the latest version of pip to avoid it displaying warnings # about it being out of date. - "pip install --disable-pip-version-check --user --upgrade pip" - - "pip install -e ." + - "pip install -e . --upgrade" - "pipenv install --dev" test_script: