def test_functional_run_ls(self): """ Functional test that actually subprocesses and runs command. Checks that command either ran successfully or failed as expected so that it can be run on any platform. Other tests will mock the subprocess interaction. """ self.task_config.config["options"] = {"command": "ls -la"} task = Command(self.project_config, self.task_config) # try to run the command and handle the command Exception # if no exception, confirm that we logged # if exception, confirm exception matches expectations try: task() except CommandException: self.assertTrue(any("Return code" in s for s in self.task_log["error"])) self.assertTrue(any("total" in s for s in self.task_log["info"]))
def test_handle_returncode(self): task_config = TaskConfig({"options": {"command": "ls"}}) task = Command(self.project_config, task_config) with self.assertRaises(CommandException): task._handle_returncode(1, BytesIO(b"err"))
def test_init__dict_env(self): task_config = TaskConfig({"options": {"env": {}, "command": "ls"}}) task = Command(self.project_config, task_config) self.assertEqual({}, task.options["env"])
def test_get_env__pass_env_false(self): task_config = TaskConfig({"options": {"pass_env": "False", "command": "ls"}}) task = Command(self.project_config, task_config) self.assertEqual({}, task._get_env())