mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
Merge pull request #561 from kennethreitz/break-windows
stole @jacebrowning's tests (modified)
This commit is contained in:
+14
-1
@@ -269,6 +269,18 @@ def ensure_pipfile(validate=True):
|
||||
# Import requirements.txt.
|
||||
import_requirements()
|
||||
|
||||
# Warn the user of side-effects.
|
||||
click.echo(
|
||||
u'{0}: Your {1} now contains pinned versions, if your {2} did. \n'
|
||||
'We recommend updating your {1} to specify the {3} version, instead.'
|
||||
''.format(
|
||||
crayons.red('Warning', bold=True),
|
||||
crayons.white('Pipfile', bold=True),
|
||||
crayons.white('requirements.txt', bold=True),
|
||||
crayons.white('"*"', bold=True)
|
||||
)
|
||||
)
|
||||
|
||||
else:
|
||||
puts(crayons.white(u'Creating a Pipfile for this project…', bold=True), err=True)
|
||||
|
||||
@@ -289,6 +301,7 @@ def ensure_pipfile(validate=True):
|
||||
|
||||
|
||||
def find_a_system_python(python):
|
||||
"""Finds a system python, given a version (e.g. 2.7 / 3.6), or a full path."""
|
||||
if python.startswith('py'):
|
||||
return system_which(python)
|
||||
elif os.path.isabs(python):
|
||||
@@ -398,7 +411,7 @@ def ensure_project(three=None, python=None, validate=True, system=False, warn=Tr
|
||||
|
||||
path_to_python = which('python')
|
||||
|
||||
if project.required_python_version not in python_version(path_to_python):
|
||||
if project.required_python_version not in (python_version(path_to_python) or ''):
|
||||
puts(
|
||||
'{0}: Your Pipfile requires {1} {2}, '
|
||||
'but you are using {3} ({4}).'.format(
|
||||
|
||||
+1
-2
@@ -29,7 +29,6 @@ def python_version(path_to_python):
|
||||
try:
|
||||
TEMPLATE = 'Python {}.{}.{}'
|
||||
c = delegator.run([path_to_python, '--version'], block=False)
|
||||
assert c.return_code == 0
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
@@ -56,7 +55,7 @@ class HackedPythonVersion(object):
|
||||
|
||||
def __enter__(self):
|
||||
if self.python:
|
||||
os.environ['PIP_PYTHON_VERSION'] = self.python
|
||||
os.environ['PIP_PYTHON_VERSION'] = str(self.python)
|
||||
|
||||
def __exit__(self, *args):
|
||||
# Restore original Python version information.
|
||||
|
||||
@@ -4,19 +4,32 @@ import shutil
|
||||
from mock import patch, Mock, PropertyMock
|
||||
|
||||
import delegator
|
||||
import toml
|
||||
from pipenv.patched import contoml
|
||||
|
||||
from pipenv.cli import (
|
||||
ensure_proper_casing,
|
||||
pip_install, pip_download
|
||||
pip_install, pip_download, find_a_system_python
|
||||
)
|
||||
|
||||
FULL_PYTHON_PATH = 'C:\\Python36-x64\\python.exe'
|
||||
|
||||
class TestPipenvWindows():
|
||||
|
||||
def test_existience(self):
|
||||
assert True
|
||||
|
||||
def test_cli_with_custom_python_path(self):
|
||||
delegator.run('mkdir custom_python')
|
||||
os.chdir('custom_python')
|
||||
|
||||
c = delegator.run('pipenv install --python={0}'.format(FULL_PYTHON_PATH))
|
||||
|
||||
# Debugging, if it fails.
|
||||
print(c.out)
|
||||
print(c.err)
|
||||
|
||||
assert c.return_code == 0
|
||||
|
||||
def test_cli_usage(self):
|
||||
delegator.run('mkdir test_project')
|
||||
os.chdir('test_project')
|
||||
@@ -187,7 +200,7 @@ class TestPipenvWindows():
|
||||
"PyTEST = \"*\"\n")
|
||||
|
||||
# Load test Pipfile.
|
||||
p = toml.loads(pfile_test)
|
||||
p = contoml.loads(pfile_test)
|
||||
|
||||
assert 'DjAnGO' in p['packages']
|
||||
assert 'PyTEST' in p['dev-packages']
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import delegator
|
||||
|
||||
from pipenv.utils import python_version
|
||||
|
||||
|
||||
FULL_PYTHON_PATH = 'C:\\Python36-x64\\python.exe'
|
||||
|
||||
|
||||
class TestUtilsWindows():
|
||||
|
||||
def test_python_version_from_full_path(self):
|
||||
print(delegator.run('{0} --version'.format(FULL_PYTHON_PATH)).out)
|
||||
|
||||
assert python_version(FULL_PYTHON_PATH) == "3.6.1"
|
||||
+16
-9
@@ -138,15 +138,16 @@ class TestUtils:
|
||||
|
||||
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'}
|
||||
}}
|
||||
'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']
|
||||
@@ -154,3 +155,9 @@ class TestUtils:
|
||||
assert list(split_dict['dev-packages'].keys()) == ['Django']
|
||||
assert 'click' in split_dict['dev-packages-vcs']
|
||||
assert 'crayons' in split_dict['dev-packages-vcs']
|
||||
|
||||
def test_python_version_from_bad_path(self):
|
||||
assert pipenv.utils.python_version("/fake/path") is None
|
||||
|
||||
def test_python_version_from_non_python(self):
|
||||
assert pipenv.utils.python_version("/dev/null") is None
|
||||
|
||||
Reference in New Issue
Block a user