From bee20e02558a229d4fe7fab6f83777a74a5f088d Mon Sep 17 00:00:00 2001 From: Erin O'Connell Date: Mon, 25 Sep 2017 02:40:00 -0600 Subject: [PATCH] migrated some more tests from legacy --- tests/test_legacy.py | 26 -------------------------- tests/test_pipenv.py | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/tests/test_legacy.py b/tests/test_legacy.py index f0611375..20a3706e 100644 --- a/tests/test_legacy.py +++ b/tests/test_legacy.py @@ -116,29 +116,3 @@ class TestPipenv(): 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') - - pip_str = ("[packages]\n" - "requests = \"==2.14.0\"\n" - "flask = \"==0.12.2\"\n\n" - "[dev-packages]\n" - "pytest = \"==3.1.1\"\n") - - req_list = ("requests==2.14.0", "flask==0.12.2", "pytest==3.1.1") - - # Build the environment. - os.environ['PIPENV_VENV_IN_PROJECT'] = '1' - assert delegator.run('echo \'{0}\' > Pipfile'.format(pip_str)).return_code == 0 - - # 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('..') - delegator.run('rm -fr test_pipenv_requirements') diff --git a/tests/test_pipenv.py b/tests/test_pipenv.py index 38c54247..f2125bf4 100644 --- a/tests/test_pipenv.py +++ b/tests/test_pipenv.py @@ -386,12 +386,14 @@ requests = {version = "*"} @pytest.mark.bad @pytest.mark.install def test_bad_packages(self): + with PipenvInstance() as p: c = p.pipenv('install NotAPackage') assert c.return_code > 0 @pytest.mark.dotvenv def test_venv_in_project(self): + os.environ['PIPENV_VENV_IN_PROJECT'] = '1' with PipenvInstance() as p: c = p.pipenv('install requests') @@ -404,6 +406,7 @@ requests = {version = "*"} @pytest.mark.run @pytest.mark.dotenv def test_env(self): + with PipenvInstance(pipfile=False) as p: with open('.env', 'w') as f: f.write('HELLO=WORLD') @@ -416,6 +419,7 @@ requests = {version = "*"} @pytest.mark.install @pytest.mark.skip(reason="this doesn't work on windows") def test_e_dot(self): + with PipenvInstance() as p: path = os.path.abspath(os.path.sep.join([os.path.dirname(__file__), '..'])) c = p.pipenv('install -e \'{0}\' --dev'.format(path)) @@ -431,6 +435,7 @@ requests = {version = "*"} @pytest.mark.install @pytest.mark.skip(reason="this doesn't work on travis") def test_code_import_manual(self): + with PipenvInstance() as p: with PipenvInstance(chdir=True) as p: @@ -444,6 +449,7 @@ requests = {version = "*"} @pytest.mark.check @pytest.mark.unused def test_check_unused(self): + with PipenvInstance() as p: with PipenvInstance(chdir=True) as p: @@ -459,6 +465,7 @@ requests = {version = "*"} @pytest.mark.check @pytest.mark.style def test_flake8(self): + with PipenvInstance() as p: with PipenvInstance(chdir=True) as p: @@ -472,13 +479,18 @@ requests = {version = "*"} @pytest.mark.install @pytest.mark.requirements def test_requirements_to_pipfile(self): - with PipenvInstance(pipfile=False) as p: + + with PipenvInstance(pipfile=False, chdir=True) as p: # Write a requirements file with open('requirements.txt', 'w') as f: f.write('requests[socks]==2.18.1\n') c = p.pipenv('install') + assert c.return_code == 0 + print(c.out) + print(c.err) + print(delegator.run('ls -l').out) # assert stuff in pipfile assert 'requests' in p.pipfile['packages'] @@ -501,6 +513,7 @@ requests = {version = "*"} ) @pytest.mark.skip(reason="this doesn't work on app veyor") def test_activate_virtualenv(self, shell, extension): + orig_shell = os.environ['SHELL'] os.environ['SHELL'] = shell @@ -519,4 +532,26 @@ requests = {version = "*"} command = activate_virtualenv(source=False) venv = Project().virtualenv_location - assert command == '{0}/bin/activate'.format(venv) \ No newline at end of file + assert command == '{0}/bin/activate'.format(venv) + + @pytest.mark.lock + @pytest.mark.requirements + def test_lock_requirements_file(self): + + with PipenvInstance() as p: + with open(p.pipfile_path, 'w') as f: + contents = """ +[packages] +requests = "==2.14.0" +flask = "==0.12.2" +[dev-packages] +pytest = "==3.1.1" + """.strip() + f.write(contents) + + req_list = ("requests==2.14.0", "flask==0.12.2", "pytest==3.1.1") + + c = p.pipenv('lock -r') + assert c.return_code == 0 + for req in req_list: + assert req in c.out \ No newline at end of file