def test_success(self): my_action = action.CmdAction(PROGRAM) got = my_action.execute() assert got is None
def test_success_noshell(self): my_action = action.CmdAction(PROGRAM.split(), shell=False) got = my_action.execute() assert got is None
def test_callable_invalid(self): def get_cmd(blabla): pass task = FakeTask([],[],[],{'opt1':'3'}) my_action = action.CmdAction(get_cmd, task) got = my_action.execute() assert isinstance(got, TaskError)
def test_success(self): TEST_PATH = os.path.dirname(__file__) PROGRAM = "python %s/sample_process.py" % TEST_PATH my_action = action.CmdAction(PROGRAM + " x1 x2", save_out='out') my_action.execute() assert {'out': six.u('x1')} == my_action.values
def test_repr(self): my_action = action.CmdAction(PROGRAM) expected = "<CmdAction: '%s'>" % PROGRAM assert expected == repr(my_action), repr(my_action)
def test_values(self): # for cmdActions they are emtpy if save_out not specified my_action = action.CmdAction("%s 1 2" % PROGRAM) my_action.execute() assert {} == my_action.values
def test_unicode(self): action_str = PROGRAM + "中文" my_action = action.CmdAction(action_str) assert "Cmd: %s" % action_str == str(my_action)
def test_str(self): my_action = action.CmdAction(PROGRAM) assert "Cmd: %s" % PROGRAM == str(my_action)
def test_success(self): TEST_PATH = os.path.dirname(__file__) 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
def test_env(self): env = os.environ.copy() env['GELKIPWDUZLOVSXE'] = '1' my_action = action.CmdAction("%s check env" % PROGRAM, env=env) got = my_action.execute() assert got is None
def test_list_should_contain_strings_or_paths(self): 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)
def test_list_can_contain_path(self): cmd = [executable, PurePath(TEST_PATH), Path("myecho.py")] task = FakeTask([], [], [], {}) my_action = action.CmdAction(cmd, task) assert [executable, TEST_PATH, "myecho.py"] == my_action.expand_action()
def test_noPathSet(self, tmpdir): path = tmpdir.mkdir("foo") 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)
def test_error(self): my_action = action.CmdAction("%s 1 2 3" % PROGRAM) got = my_action.execute() assert isinstance(got, TaskError)
def test_captureStderr(self): cmd = "%s please fail" % PROGRAM my_action = action.CmdAction(cmd) got = my_action.execute() assert isinstance(got, TaskFailed) assert "err output on failure" == my_action.err, repr(my_action.err)
def test_failure(self): my_action = action.CmdAction("%s please fail" % PROGRAM) got = my_action.execute() assert isinstance(got, TaskFailed)
def test_captureStdout(self): my_action = action.CmdAction("%s hi_stdout hi2" % PROGRAM) my_action.execute() assert "hi_stdout" == my_action.out, repr(my_action.out)
def test_unicode(self): action_str = six.text_type(PROGRAM) + six.u("中文") my_action = action.CmdAction(action_str) assert "Cmd: %s" % action_str == six.text_type(my_action)
def test_string_list_cant_be_expanded(self): cmd = ["python", "%s/myecho.py" % TEST_PATH] task = FakeTask([], [], [], {}) my_action = action.CmdAction(cmd, task) assert cmd == my_action.expand_action()
def test_result(self): my_action = action.CmdAction("%s 1 2" % PROGRAM) my_action.execute() assert "12" == my_action.result
def test_unicode_string(self, tmpfile): my_action = action.CmdAction("") unicode_in = tempfile.TemporaryFile('w+b') unicode_in.write(six.u(" 中文").encode('utf-8')) unicode_in.seek(0) my_action._print_process_output(Mock(), unicode_in, Mock(), tmpfile)
def test_changePath(self, tmpdir): path = tmpdir.mkdir("foo") command = 'python -c "import os; print(os.getcwd())"' my_action = action.CmdAction(command, cwd=path.strpath) my_action.execute() assert path + "\n" == my_action.out, repr(my_action.out)
def task_get_git_version(): return { 'actions': [action.CmdAction('git describe --long', save_out='git_version')] }