Sort items before comparison

Signed-off-by: Dan Ryan <dan@danryan.co>
This commit is contained in:
Dan Ryan
2018-04-17 01:27:28 -04:00
parent 7a8d01edc3
commit 31a4a75c98
+11 -55
View File
@@ -2,16 +2,13 @@
import pytest
import os
from pipenv.project import Project
import unittest
@pytest.mark.project
@pytest.mark.sources
def test_get_cached_source(PipenvInstance, pypi):
@pytest.mark.parametrize('lock_first', [True, False])
def test_get_source(PipenvInstance, pypi, lock_first):
with PipenvInstance(pypi=pypi, chdir=True) as p:
# Make sure unparseable packages don't wind up in the pipfile
# Escape $ for shell input
with open(p.pipfile_path, 'w') as f:
contents = """
[[source]]
@@ -31,8 +28,11 @@ six = {{version = "*", index = "pypi"}}
[dev-packages]
""".format(os.environ['PIPENV_TEST_INDEX']).strip()
f.write(contents)
c = p.pipenv('lock')
assert c.return_code == 0
if lock_first:
# force source to be cached
c = p.pipenv('lock')
assert c.return_code == 0
project = Project()
sources = [
['pypi', 'https://pypi.python.org/simple'],
@@ -45,51 +45,7 @@ six = {{version = "*", index = "pypi"}}
source = source[0]
assert source['name'] == name
assert source['url'] == url
assert unittest.assertDictEqual(source, project.get_source(name=name))
assert unittest.assertDictEqual(source, project.get_source(url=url))
assert unittest.assertDictEqual(source, project.find_source(name))
assert unittest.assertDictEqual(source, project.find_source(url))
@pytest.mark.project
@pytest.mark.sources
def test_get_uncached_source(PipenvInstance, pypi):
with PipenvInstance(pypi=pypi, chdir=True) as p:
# Make sure unparseable packages don't wind up in the pipfile
# Escape $ for shell input
with open(p.pipfile_path, 'w') as f:
contents = """
[[source]]
url = "{0}"
verify_ssl = false
name = "testindex"
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = "true"
name = "pypi"
[packages]
pytz = "*"
six = {{version = "*", index = "pypi"}}
[dev-packages]
""".format(os.environ['PIPENV_TEST_INDEX']).strip()
f.write(contents)
project = Project()
sources = [
['pypi', 'https://pypi.python.org/simple'],
['testindex', os.environ.get('PIPENV_TEST_INDEX')]
]
for src in sources:
name, url = src
source = [s for s in project.pipfile_sources if s.get('name') == name]
assert source
source = source[0]
assert source['name'] == name
assert source['url'] == url
assert unittest.assertDictEqual(source, project.get_source(name=name))
assert unittest.assertDictEqual(source, project.get_source(url=url))
assert unittest.assertDictEqual(source, project.find_source(name))
assert unittest.assertDictEqual(source, project.find_source(url))
assert sorted(source.items()) == sorted(project.get_source(name=name).items())
assert sorted(source.items()) == sorted(project.get_source(url=url).items())
assert sorted(source.items()) == sorted(project.find_source(name).items())
assert sorted(source.items()) == sorted(project.find_source(url).items())