From c37a0143f3c04f604e4e627ff4a2799ae3eff5b6 Mon Sep 17 00:00:00 2001 From: Nate Prewitt Date: Tue, 28 Feb 2017 10:35:08 -0700 Subject: [PATCH] test internal pipfile/lock representations and new utils --- tests/test_project.py | 53 +++++++++++++++++++++++++++++++++++++++++++ tests/test_utils.py | 31 +++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/tests/test_project.py b/tests/test_project.py index c191f91f..f5a78e43 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -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') diff --git a/tests/test_utils.py b/tests/test_utils.py index fca2eae4..0f3a2d81 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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']