From a3dcc66844b06f0c8e6fbfc716641ec3a1e20e3a Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Tue, 27 Mar 2018 20:11:15 +0800 Subject: [PATCH] Refactor --- pipenv/project.py | 10 ++++- tests/pytest-pypi/pytest_pypi/serve.py | 11 ------ tests/test_pipenv.py | 51 +++++++------------------- 3 files changed, 23 insertions(+), 49 deletions(-) diff --git a/pipenv/project.py b/pipenv/project.py index 4b8d1bb7..7c33fb28 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -566,12 +566,20 @@ class Project(object): if 'source' in self.parsed_pipfile: return self.parsed_pipfile['source'] + elif PIPENV_TEST_INDEX: + return [ + { + u'url': PIPENV_TEST_INDEX, + u'verify_ssl': True, + u'name': u'custom', + } + ] else: return [ { u'url': u'https://pypi.python.org/simple', u'verify_ssl': True, - 'name': 'pypi', + u'name': u'pypi', } ] diff --git a/tests/pytest-pypi/pytest_pypi/serve.py b/tests/pytest-pypi/pytest_pypi/serve.py index 1e9c4d9a..07a92dc0 100644 --- a/tests/pytest-pypi/pytest_pypi/serve.py +++ b/tests/pytest-pypi/pytest_pypi/serve.py @@ -1,5 +1,4 @@ import os -import textwrap import threading import ssl from wsgiref.simple_server import WSGIServer, make_server, WSGIRequestHandler @@ -125,16 +124,6 @@ class Server(object): def join(self, url, allow_fragments=True): return urljoin(self.url, url, allow_fragments=allow_fragments) - def as_source_entry(self, name='custom'): - return textwrap.dedent( - """ - [[source]] - url = "{url}/simple" - verify_ssl = true - name = "{name}" - """.format(url=self.url, name=name), - ).strip() - class SecureServer(Server): port_envvar = 'HTTPBIN_HTTPS_PORT' diff --git a/tests/test_pipenv.py b/tests/test_pipenv.py index 27c89fc1..d68a0ac2 100644 --- a/tests/test_pipenv.py +++ b/tests/test_pipenv.py @@ -308,14 +308,12 @@ class TestPipenv: with PipenvInstance(pypi=pypi) as p: with open(p.pipfile_path, 'w') as f: contents = """ -{source} - [packages] tablib = "*" [dev-packages] records = "*" - """.format(source=pypi.as_source_entry()).strip() + """.strip() f.write(contents) c = p.pipenv('install') assert c.return_code == 0 @@ -334,11 +332,9 @@ records = "*" with PipenvInstance(pypi=pypi) as p: with open(p.pipfile_path, 'w') as f: contents = """ -{source} - [packages] tablib = "*" - """.format(source=pypi.as_source_entry()).strip() + """.strip() f.write(contents) c = p.pipenv('install') assert c.return_code == 0 @@ -511,11 +507,9 @@ setup( with PipenvInstance(pypi=pypi) as p: with open(p.pipfile_path, 'w') as f: contents = """ -{source} - [packages] tablib = "<0.12" - """.format(source=pypi.as_source_entry()).strip() + """.strip() f.write(contents) c = p.pipenv('install') assert c.return_code == 0 @@ -531,13 +525,11 @@ tablib = "<0.12" with PipenvInstance(pypi=pypi) as p: with open(p.pipfile_path, 'w') as f: contents = """ -{source} - [packages] requests = "*" records = "*" tpfd = "*" - """.format(source=pypi.as_source_entry()).strip() + """.strip() f.write(contents) c = p.pipenv('install') @@ -561,13 +553,11 @@ tpfd = "*" with PipenvInstance(pypi=pypi) as p: with open(p.pipfile_path, 'w') as f: contents = """ -{source} - [packages] requests = "*" records = "*" tpfd = "*" - """.format(source=pypi.as_source_entry()).strip() + """.strip() f.write(contents) c = p.pipenv('install --sequential') @@ -611,8 +601,6 @@ tpfd = "*" with PipenvInstance(pypi=pypi) as p: with open(p.pipfile_path, 'w') as f: contents = """ -{source} - [packages] tablib = {version = "*", markers="os_name=='splashwear'"} """.strip() @@ -634,11 +622,9 @@ tablib = {version = "*", markers="os_name=='splashwear'"} with PipenvInstance(pypi=pypi) as p: with open(p.pipfile_path, 'w') as f: contents = """ -{source} - [packages] -requests = {{ version = "*", os_name = "== 'splashwear'" }} - """.format(source=pypi.as_source_entry()).strip() +requests = {version = "*", os_name = "== 'splashwear'"} + """.strip() f.write(contents) c = p.pipenv('install') @@ -658,12 +644,10 @@ requests = {{ version = "*", os_name = "== 'splashwear'" }} with PipenvInstance(pypi=pypi) as p: with open(p.pipfile_path, 'w') as f: contents = """ -{source} - [packages] apscheduler = "*" -funcsigs = {{ version = "*", os_name = "== 'splashwear'" }} - """.format(source=pypi.as_source_entry()).strip() +funcsigs = {version = "*", os_name = "== 'splashwear'"} + """.strip() f.write(contents) c = p.pipenv('install') @@ -684,12 +668,10 @@ funcsigs = {{ version = "*", os_name = "== 'splashwear'" }} with PipenvInstance(pypi=pypi) as p: with open(p.pipfile_path, 'w') as f: contents = """ -{source} - [packages] apscheduler = "*" funcsigs = "*" - """.format(source=pypi.as_source_entry()).strip() + """.strip() f.write(contents) c = p.pipenv('install') @@ -721,11 +703,9 @@ funcsigs = "*" with PipenvInstance(pypi=pypi) as p: with open(p.pipfile_path, 'w') as f: contents = """ -{source} - [packages] -requests = {{version = "*"}} - """.format(source=pypi.as_source_entry()).strip() +requests = {version = "*"} + """.strip() f.write(contents) c = p.pipenv('install') @@ -955,12 +935,11 @@ RandomWords = "*" with PipenvInstance(pypi=pypi) as p: with open(p.pipfile_path, 'w') as f: contents = """ -{source} [packages] requests = "==2.14.0" [dev-packages] flask = "==0.12.2" - """.format(source=pypi.as_source_entry()).strip() + """.strip() f.write(contents) req_list = ("requests==2.14.0") @@ -1040,11 +1019,9 @@ allow_prereleases = true with PipenvInstance(pypi=pypi) as p: with open(p.pipfile_path, 'w') as f: contents = """ -{source} - [packages] maya = "*" - """.format(source=pypi.as_source_entry()).strip() + """.strip() f.write(contents) c = p.pipenv('lock')