From ff080abe550af90a8445332058434743ee7529c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernardas=20Ali=C5=A1auskas?= Date: Wed, 7 Oct 2020 15:37:44 +0700 Subject: add list command which lists tasks (#21) * add list command which lists tasks * refactor list argument as a flag add tests and readme for --list flag * more tests * Update tests/test_taskipy.py Co-authored-by: Roy Sommer * refactor listing to taskrunner fix tests and cli to handle --list following arguments cases Co-authored-by: Roy Sommer --- tests/test_taskipy.py | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'tests/test_taskipy.py') diff --git a/tests/test_taskipy.py b/tests/test_taskipy.py index 37b322d..3389de6 100644 --- a/tests/test_taskipy.py +++ b/tests/test_taskipy.py @@ -28,13 +28,11 @@ class TaskipyTestCase(unittest.TestCase): def run_task(self, task: str, args: List[str] = None, cwd=os.curdir) -> Tuple[int, str, str]: proc = self.start_taskipy_process(task, args=args, cwd=cwd) stdout, stderr = proc.communicate() - - return proc.returncode, str(stdout), str(stderr) + return proc.returncode, stdout.decode(), str(stderr) def start_taskipy_process(self, task: str, args: List[str] = None, cwd=os.curdir) -> subprocess.Popen: executable_path = path.abspath('task') args = args or [] - return subprocess.Popen([executable_path, task] + args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd) def create_test_dir_from_fixture(self, fixture_name: str): @@ -179,6 +177,44 @@ class PassArgumentsTestCase(TaskipyTestCase): self.assertEqual(exit_code, 0) +class ListTasksTestCase(TaskipyTestCase): + + def test_running_task_list(self): + cwd = self.create_test_dir_from_fixture('project_with_tasks_to_list') + exit_code, stdout, _ = self.run_task('--list', cwd=cwd) + + expected = "\n".join([ + "one echo first task", + "two echo second task", + "three echo third task", + ]) + self.maxDiff = None + self.assertEqual(expected, stdout.strip()) + self.assertEqual(exit_code, 0) + + def test_running_task_list_before_name(self): + cwd = self.create_test_dir_from_fixture('project_with_tasks_to_list') + # anything following the flag should be ignored + exit_code, stdout, _ = self.run_task('--list', ['one'], cwd=cwd) + expected = "\n".join([ + "one echo first task", + "two echo second task", + "three echo third task", + ]) + self.maxDiff = None + self.assertEqual(expected, stdout.strip()) + self.assertEqual(exit_code, 0) + + def test_running_task_list_with_arg(self): + cwd = self.create_test_dir_from_fixture('project_with_tasks_to_list') + # when --list follows after task name it should be passed as an argument + exit_code, stdout, _ = self.run_task('one', ['--list'], cwd=cwd) + expected = "first task --list" + self.maxDiff = None + self.assertEqual(expected, stdout.strip()) + self.assertEqual(exit_code, 0) + + class TaskRunFailTestCase(TaskipyTestCase): def test_exiting_with_code_127_and_printing_if_task_not_found(self): cwd = self.create_test_dir_from_fixture('project_with_pyproject_and_tasks') -- cgit v1.2.3