test internal pipfile/lock representations and new utils

This commit is contained in:
Nate Prewitt
2017-02-28 10:35:08 -07:00
parent 86ba5e510d
commit c37a0143f3
2 changed files with 84 additions and 0 deletions
+53
View File
@@ -113,3 +113,56 @@ class TestProject():
assert len(p['packages']) == 1
assert 'dev-packages' not in p
def test_internal_pipfile(self):
proj = pipenv.project.Project()
# Create test space.
delegator.run('mkdir test_internal_pipfile')
with open('test_internal_pipfile/Pipfile', 'w') as f:
f.write('[[source]]\nurl = \'https://pypi.python.org/simple\'\n'
'verify_ssl = true\n\n\n[packages]\n'
'Requests = { extras = [\'socks\'] }\nFlask_Auth = \'*\'\n\n\n'
'[dev-packages]\nclick = \'*\'\nDjango = {git = '
'"https://github.com/django/django.git", ref="1.10"}\n')
proj._pipfile_location = 'test_internal_pipfile/Pipfile'
p = proj._pipfile
# Test package names are normalized as expected.
assert list(p['packages'].keys()) == ['requests', 'flask-auth']
assert list(p['dev-packages'].keys()) == ['click', 'django']
delegator.run('rm -fr test_internal_pipfile')
def test_internal_lockfile(self):
proj = pipenv.project.Project()
# Create test space.
delegator.run('mkdir test_internal_lockfile')
with open('test_internal_lockfile/Pipfile', 'w') as f:
f.write('[[source]]\nurl = \'https://pypi.python.org/simple\'\n'
'verify_ssl = true\n\n\n[packages]\n'
'Requests = { extras = [\'socks\'] }\nFlask_Auth = \'*\'\n\n\n'
'[dev-packages]\nclick = \'*\'\nDjango = {git = '
'"https://github.com/django/django.git", ref="1.10"}\n')
proj._pipfile_location = 'test_internal_lockfile/Pipfile'
lockfile = proj._lockfile
# Verify default section of lockfile.
assert len(lockfile['default'].keys()) == 2
assert 'requests' in lockfile['default']
assert 'flask-auth' in lockfile['default']
# Verify develop section of lockfile.
assert lockfile['develop']['django']['git'] == 'https://github.com/django/django.git'
assert lockfile['develop']['click'] == '*'
# Verify _meta exists.
assert lockfile['_meta']['hash'] == {'sha256': 'ff0b0584610a7091156f32ca7d5adab8f29cb17263c6d63bcab42de2137c4787'}
delegator.run('rm -fr test_internal_lockfile')
+31
View File
@@ -99,3 +99,34 @@ class TestUtils:
])
def test_is_required_version(self, version, specified_ver, expected):
assert pipenv.utils.is_required_version(version, specified_ver) is expected
@pytest.mark.parametrize('entry, expected', [
({'git': 'package.git', 'ref': 'v0.0.1'}, True),
({'hg': 'https://package.com/package', 'ref': 'v1.2.3'}, True),
('*', False),
({'some_value': 5, 'other_value': object()}, False),
('package', False)
])
def test_is_vcs(self, entry, expected):
assert pipenv.utils.is_vcs(entry) is expected
def test_split_vcs(self):
pipfile_dict = {
'packages': {
'requests': {'git': 'https://github.com/kennethreitz/requests.git'},
'Flask': '*'
},
'dev-packages': {
'Django': '==1.10',
'click': {'svn': 'https://svn.notareal.com/click'},
'crayons': {'hg': 'https://hg.alsonotreal.com/crayons'}
}}
split_dict = pipenv.utils.split_vcs(pipfile_dict)
assert list(split_dict['packages'].keys()) == ['Flask']
assert split_dict['packages-vcs'] == {'requests': {'git': 'https://github.com/kennethreitz/requests.git'}}
assert list(split_dict['dev-packages'].keys()) == ['Django']
assert 'click' in split_dict['dev-packages-vcs']
assert 'crayons' in split_dict['dev-packages-vcs']