Skip to content

Commit

Permalink
Added test for binary version check
Browse files Browse the repository at this point in the history
  • Loading branch information
gtalarico committed May 12, 2018
1 parent 55a018d commit 8492638
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
4 changes: 2 additions & 2 deletions pipenv_pipes/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def find_binary(envpath):

def get_binary_version(envpath):
""" Returns a string indicating the Python version (Python 3.5.6) """
binpath = find_binary(envpath)
version, code = call_python_version(binpath)
pybinpath = find_binary(envpath)
version, code = call_python_version(pybinpath)
if not code:
return version
else:
Expand Down
5 changes: 3 additions & 2 deletions pipenv_pipes/pipenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def call_pipenv_shell(cwd, envname='pipenv-shell', timeout=None):
return output, code, proc


def call_python_version(binpath):
def call_python_version(pybinpath):
# TODO Rename this module
output, code = PipedPopen([binpath, '-V'])
binpath = os.path.dirname(pybinpath)
output, code = PipedPopen(cmds=['python', '--version'], cwd=binpath)
return output, code
15 changes: 8 additions & 7 deletions tests/integration/test_pipenv.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import pytest # noqa: F401
import os
from subprocess import TimeoutExpired

from pipenv_pipes.pipenv import (
call_pipenv_venv,
call_pipenv_shell,
# call_python_version
# call_pipenv_shell,
)


Expand All @@ -24,19 +24,20 @@ def test_call_pipenv_venv(mock_env_home):
assert code == 0
assert pipenv_home in output

# Debug Venv
# os.system('explorer ' +pipenv_home)

@pytest.mark.skip
def test_call_python_version(mock_env_home, project_names):
""" Tested in test_core + cli """

@pytest.mark.skip
def test_call_pipenv_shell(mock_env_home):
""" This does not guarantee the shell was launched successful,
however it ensure it timed out, which means the command did went through
and it was open for at least 5 seconds which means the shell was most
likely opened """
pipenv_home, mock_projects_dir = mock_env_home
project_name = os.listdir(mock_projects_dir)[0]
project_dir = os.path.join(mock_projects_dir, project_name)
# pipenv_home, mock_projects_dir = mock_env_home
# project_name = os.listdir(mock_projects_dir)[0]
# project_dir = os.path.join(mock_projects_dir, project_name)
# import pdb; pdb.set_trace()
# with pytest.raises(TimeoutExpired):
# import pdb; pdb.set_trace()
Expand Down
18 changes: 17 additions & 1 deletion tests/unit/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import pytest # noqa: F401
import os
from os.path import join
import pathlib

from pipenv_pipes.core import (
find_environments,
read_project_dir_file,
write_project_dir_project_file,
delete_project_dir_file,
find_binary,
get_binary_version,
)


Expand All @@ -33,6 +34,21 @@ def test_find_environments_does_not_exit(self):
with pytest.raises(IOError):
find_environments('/fakedir/')

def test_find_binary(self, mock_env_home, temp_folder):
pipenv_home, mock_projects_dir = mock_env_home
envname = os.listdir(pipenv_home)[0]
envpath = os.path.join(pipenv_home, envname)
binpath = find_binary(envpath)
assert 'python' in binpath
assert envpath in binpath
with pytest.raises(EnvironmentError):
find_binary(temp_folder)

def test_get_python_version(self, mock_env_home, temp_folder):
pipenv_home, mock_projects_dir = mock_env_home
envname = os.listdir(pipenv_home)[0]
envpath = os.path.join(pipenv_home, envname)
assert 'Python' in get_binary_version(envpath)

class TestProjectDirFile():

Expand Down

0 comments on commit 8492638

Please sign in to comment.