Skip to content

Commit

Permalink
Adding cd context handling tests and fixing some absolute path issues
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkerz committed May 13, 2019
1 parent a6ba0c8 commit bcdaa26
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
10 changes: 10 additions & 0 deletions tests/data/cd_context/pie_tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os

from pie import *


@task
def cdContext():
with cd('..'):
print(os.getcwd())
print(os.getcwd())
16 changes: 15 additions & 1 deletion tests/test_context_manager.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import os

import pytest


@pytest.mark.parametrize('pie_tasks_path',['venv_context'],indirect=['pie_tasks_path'])
def test_venv_context(pie,pie_tasks_path,pie_mock_cmd):
pie.main(['venvContext'])
cwd=os.getcwd()
first_activate=r'{}\first\Scripts\activate.bat'.format(cwd)
second_activate=r'{}\second\Scripts\activate.bat'.format(cwd)
# TODO: only correct on Windows
assert len(pie_mock_cmd.cmds)==1
assert pie_mock_cmd.cmds[0][0][0]==r'cmd /c "first\Scripts\activate.bat && cmd /c "second\Scripts\activate.bat && blah""'
assert pie_mock_cmd.cmds[0][0][0]==r'cmd /c "{} && cmd /c "{} && blah""'.format(first_activate,second_activate)


@pytest.mark.parametrize('pie_tasks_path',['cd_context'],indirect=['pie_tasks_path'])
def test_cd_context(pie,capsys,pie_tasks_path,pie_mock_cmd):
pie.main(['cdContext'])
cwd=os.getcwd()
assert len(pie_mock_cmd.cmds)==0
out,err=capsys.readouterr()
assert out=='{}\n{}\n'.format(os.path.dirname(cwd),cwd)
6 changes: 5 additions & 1 deletion tests/test_pie_requirements.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import pytest


Expand All @@ -16,7 +18,9 @@ def test_create_venv(pie,capsys,pie_tasks_path,pie_mock_cmd):
# TODO: improve checking, it's possible the wrong venv could be activated and we wouldn't detect it
assert len(pie_mock_cmd.cmds)==3
# TODO: more specific testing for py2/3
assert pie_mock_cmd.cmds[0][0][0]=='python -m virtualenv --system-site-packages ".venv-pie"' or pie_mock_cmd.cmds[0][0][0]=='python -m venv --system-site-packages ".venv-pie"'
venv_path=os.path.join(os.getcwd(),'.venv-pie')

assert pie_mock_cmd.cmds[0][0][0]=='python -m virtualenv --system-site-packages "{}"'.format(venv_path) or pie_mock_cmd.cmds[0][0][0]=='python -m venv --system-site-packages "{}"'.format(venv_path)
assert pie_mock_cmd.cmds[1][0][0].endswith('python -m pip install -U pip"')
assert pie_mock_cmd.cmds[2][0][0].endswith('python -m pip install -r requirements.pie.txt"')

Expand Down

0 comments on commit bcdaa26

Please sign in to comment.