diff --git a/tests/test___main__.py b/tests/test___main__.py index b655580d..a1d29684 100644 --- a/tests/test___main__.py +++ b/tests/test___main__.py @@ -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]) diff --git a/tests/test_action.py b/tests/test_action.py index 02a44284..bb068496 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -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 @@ -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 @@ -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) @@ -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"] @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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 diff --git a/tests/test_dependency.py b/tests/test_dependency.py index 3aaf2b03..0ca97334 100644 --- a/tests/test_dependency.py +++ b/tests/test_dependency.py @@ -3,6 +3,7 @@ import sys import tempfile import uuid +from sys import executable import pytest @@ -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(): diff --git a/tests/test_task.py b/tests/test_task.py index 735f4d40..85a6d49b 100644 --- a/tests/test_task.py +++ b/tests/test_task.py @@ -2,6 +2,7 @@ import tempfile from io import StringIO from pathlib import Path, PurePath +from sys import executable import pytest @@ -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) diff --git a/tests/test_tools.py b/tests/test_tools.py index b98e5678..20e38278 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -1,6 +1,7 @@ import os import datetime import operator +from sys import executable import pytest @@ -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 @@ -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