Skip to content

Commit

Permalink
Use executable from sys module instead of hardcoded python
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzymadness authored and schettino72 committed Aug 26, 2017
1 parent 40c9043 commit 0c518d6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
4 changes: 3 additions & 1 deletion tests/test___main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import subprocess
from sys import executable


def test_execute(depfile_name):
assert 0 == subprocess.call(['python', '-m', 'doit', 'list',
assert 0 == subprocess.call([executable, '-m', 'doit', 'list',
'--db-file', depfile_name])
29 changes: 15 additions & 14 deletions tests/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from io import StringIO, BytesIO
from threading import Thread
import time
from sys import executable

import pytest
from mock import Mock
Expand All @@ -18,7 +19,7 @@

#path to test folder
TEST_PATH = os.path.dirname(__file__)
PROGRAM = "python %s/sample_process.py" % TEST_PATH
PROGRAM = "%s %s/sample_process.py" % (executable, TEST_PATH)


@pytest.fixture
Expand Down Expand Up @@ -103,14 +104,14 @@ def test_invalid_param_stdout(self):

def test_changePath(self, tmpdir):
path = tmpdir.mkdir("foo")
command = 'python -c "import os; print(os.getcwd())"'
command = '%s -c "import os; print(os.getcwd())"' % executable
my_action = action.CmdAction(command, cwd=path.strpath)
my_action.execute()
assert path + os.linesep == my_action.out, repr(my_action.out)

def test_noPathSet(self, tmpdir):
path = tmpdir.mkdir("foo")
command = 'python -c "import os; print(os.getcwd())"'
command = '%s -c "import os; print(os.getcwd())"' % executable
my_action = action.CmdAction(command)
my_action.execute()
assert path.strpath + os.linesep != my_action.out, repr(my_action.out)
Expand Down Expand Up @@ -157,7 +158,7 @@ def test_noCaptureStdout(self, tmpfile):
class TestCmdExpandAction(object):

def test_task_meta_reference(self):
cmd = "python %s/myecho.py" % TEST_PATH
cmd = "%s %s/myecho.py" % (executable, TEST_PATH)
cmd += " %(dependencies)s - %(changed)s - %(targets)s"
dependencies = ["data/dependency1", "data/dependency2", ":dep_on_task"]
targets = ["data/target", "data/targetXXX"]
Expand All @@ -171,7 +172,7 @@ def test_task_meta_reference(self):
assert targets == got[2].split(), got[2]

def test_task_options(self):
cmd = "python %s/myecho.py" % TEST_PATH
cmd = "%s %s/myecho.py" % (executable, TEST_PATH)
cmd += " %(opt1)s - %(opt2)s"
task = FakeTask([],[],[],{'opt1':'3', 'opt2':'abc def'})
my_action = action.CmdAction(cmd, task)
Expand All @@ -180,7 +181,7 @@ def test_task_options(self):
assert "3 - abc def" == got

def test_task_pos_arg(self):
cmd = "python %s/myecho.py" % TEST_PATH
cmd = "%s %s/myecho.py" % (executable, TEST_PATH)
cmd += " %(pos)s"
task = FakeTask([],[],[],{}, 'pos', ['hi', 'there'])
my_action = action.CmdAction(cmd, task)
Expand All @@ -191,7 +192,7 @@ def test_task_pos_arg(self):
def test_task_pos_arg_None(self):
# pos_arg_val is None when the task is not specified from
# command line but executed because it is a task_dep
cmd = "python %s/myecho.py" % TEST_PATH
cmd = "%s %s/myecho.py" % (executable, TEST_PATH)
cmd += " %(pos)s"
task = FakeTask([],[],[],{}, 'pos', None)
my_action = action.CmdAction(cmd, task)
Expand All @@ -201,7 +202,7 @@ def test_task_pos_arg_None(self):

def test_callable_return_command_str(self):
def get_cmd(opt1, opt2):
cmd = "python %s/myecho.py" % TEST_PATH
cmd = "%s %s/myecho.py" % (executable, TEST_PATH)
return cmd + " %s - %s" % (opt1, opt2)
task = FakeTask([],[],[],{'opt1':'3', 'opt2':'abc def'})
my_action = action.CmdAction(get_cmd, task)
Expand All @@ -211,7 +212,7 @@ def get_cmd(opt1, opt2):

def test_callable_tuple_return_command_str(self):
def get_cmd(opt1, opt2):
cmd = "python %s/myecho.py" % TEST_PATH
cmd = "%s %s/myecho.py" % (executable, TEST_PATH)
return cmd + " %s - %s" % (opt1, opt2)
task = FakeTask([],[],[],{'opt1':'3'})
my_action = action.CmdAction((get_cmd, [], {'opt2':'abc def'}), task)
Expand All @@ -227,19 +228,19 @@ def get_cmd(blabla): pass
assert isinstance(got, TaskError)

def test_string_list_cant_be_expanded(self):
cmd = ["python", "%s/myecho.py" % TEST_PATH]
cmd = [executable, "%s/myecho.py" % TEST_PATH]
task = FakeTask([],[],[], {})
my_action = action.CmdAction(cmd, task)
assert cmd == my_action.expand_action()

def test_list_can_contain_path(self):
cmd = ["python", PurePath(TEST_PATH), Path("myecho.py")]
cmd = [executable, PurePath(TEST_PATH), Path("myecho.py")]
task = FakeTask([], [], [], {})
my_action = action.CmdAction(cmd, task)
assert ["python", TEST_PATH, "myecho.py"] == my_action.expand_action()
assert [executable, TEST_PATH, "myecho.py"] == my_action.expand_action()

def test_list_should_contain_strings_or_paths(self):
cmd = ["python", PurePath(TEST_PATH), 42, Path("myecho.py")]
cmd = [executable, PurePath(TEST_PATH), 42, Path("myecho.py")]
task = FakeTask([], [], [], {})
my_action = action.CmdAction(cmd, task)
assert pytest.raises(action.InvalidTask, my_action.expand_action)
Expand Down Expand Up @@ -357,7 +358,7 @@ def test_unbuffered_env(self, monkeypatch):
class TestCmdSaveOuput(object):
def test_success(self):
TEST_PATH = os.path.dirname(__file__)
PROGRAM = "python %s/sample_process.py" % TEST_PATH
PROGRAM = "%s %s/sample_process.py" % (executable, TEST_PATH)
my_action = action.CmdAction(PROGRAM + " x1 x2", save_out='out')
my_action.execute()
assert {'out': 'x1'} == my_action.values
Expand Down
3 changes: 2 additions & 1 deletion tests/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import tempfile
import uuid
from sys import executable

import pytest

Expand All @@ -16,7 +17,7 @@

#path to test folder
TEST_PATH = os.path.dirname(__file__)
PROGRAM = "python %s/sample_process.py" % TEST_PATH
PROGRAM = "%s %s/sample_process.py" % (executable, TEST_PATH)


def test_unicode_md5():
Expand Down
3 changes: 2 additions & 1 deletion tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import tempfile
from io import StringIO
from pathlib import Path, PurePath
from sys import executable

import pytest

Expand All @@ -12,7 +13,7 @@

#path to test folder
TEST_PATH = os.path.dirname(__file__)
PROGRAM = "python %s/sample_process.py" % TEST_PATH
PROGRAM = "%s %s/sample_process.py" % (executable, TEST_PATH)



Expand Down
7 changes: 4 additions & 3 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import datetime
import operator
from sys import executable

import pytest

Expand Down Expand Up @@ -216,7 +217,7 @@ def test_multiple_checks(self):
class TestLongRunning(object):
def test_success(self):
TEST_PATH = os.path.dirname(__file__)
PROGRAM = "python %s/sample_process.py" % TEST_PATH
PROGRAM = "%s %s/sample_process.py" % (executable, TEST_PATH)
my_action = tools.LongRunning(PROGRAM + " please fail")
got = my_action.execute()
assert got is None
Expand All @@ -235,14 +236,14 @@ def wait(self):
class TestInteractive(object):
def test_fail(self):
TEST_PATH = os.path.dirname(__file__)
PROGRAM = "python %s/sample_process.py" % TEST_PATH
PROGRAM = "%s %s/sample_process.py" % (executable, TEST_PATH)
my_action = tools.Interactive(PROGRAM + " please fail")
got = my_action.execute()
assert isinstance(got, exceptions.TaskFailed)

def test_success(self):
TEST_PATH = os.path.dirname(__file__)
PROGRAM = "python %s/sample_process.py" % TEST_PATH
PROGRAM = "%s %s/sample_process.py" % (executable, TEST_PATH)
my_action = tools.Interactive(PROGRAM + " ok")
got = my_action.execute()
assert got is None
Expand Down

0 comments on commit 0c518d6

Please sign in to comment.