Skip to content

Commit

Permalink
Add tests for workon into project (with and without --here)
Browse files Browse the repository at this point in the history
  • Loading branch information
berdario committed Mar 27, 2018
1 parent d619a45 commit 345617f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pew/pew.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def list_and_exit():
# Check if the virtualenv has an associated project directory and in
# this case, use it as the current working directory.
project_dir = get_project_dir(env)
if project_dir is None or argv[-1] == '--here':
if project_dir is None or argv[-1] == '--here': # TODO: use argparse
project_dir = os.getcwd()

shell(env, cwd=project_dir)
Expand Down
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest

from pew._utils import invoke_pew as invoke
from utils import TemporaryDirectory


@pytest.yield_fixture(scope='session')
Expand Down Expand Up @@ -61,6 +62,12 @@ def env2(workon_home):
yield
invoke('rm', 'env2')

@pytest.yield_fixture()
def env_with_project(workon_home): # TODO: use for test_setproject/test_mkvirtualenv ?
with TemporaryDirectory() as projectdir:
invoke('new', 'env_with_project', '-d', '-a', projectdir)
yield Path(projectdir)
invoke('rm', 'env_with_project')

@pytest.yield_fixture()
def testpackageenv(workon_home):
Expand Down
18 changes: 18 additions & 0 deletions tests/test_workon.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
from pathlib import Path

from pew.pew import _detect_shell
from pew._utils import temp_environ, invoke_pew as invoke
Expand All @@ -8,6 +9,7 @@
import pytest

check_env = [sys.executable, '-c', "import os; print(os.environ['VIRTUAL_ENV'])"]
check_cwd = [sys.executable, '-c', "import pathlib; print(pathlib.Path().absolute())"]

def test_detect_shell():
with temp_environ():
Expand Down Expand Up @@ -63,3 +65,19 @@ def test_no_pew_workon_home(workon_home):
def test_invalid_pew_workon_env_name(workon_home):
with temp_environ():
assert 'Invalid environment' in invoke('workon', '/home/toto').err


@skip_windows(reason='cannot supply stdin to powershell')
def test_workon_project(env_with_project):
project_dir = env_with_project
cmd = '{0} {1} "{2}"'.format(*check_cwd)
out = invoke('workon', 'env_with_project', inp=cmd).out
assert project_dir == Path(out.splitlines()[-1].strip())


@skip_windows(reason='cannot supply stdin to powershell')
def test_workon_project_but_here(env_with_project):
cwd = Path().absolute()
cmd = '{0} {1} "{2}"'.format(*check_cwd)
out = invoke('workon', 'env_with_project', '--here', inp=cmd).out
assert cwd == Path(out.splitlines()[-1].strip())

0 comments on commit 345617f

Please sign in to comment.