aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_taskipy.py
diff options
context:
space:
mode:
authorRoy Sommer <illBeRoy@users.noreply.github.com>2021-05-16 19:58:38 +0300
committerGitHub <noreply@github.com>2021-05-16 19:58:38 +0300
commit7160f5f9628a04d42e4ac9ae77c08fa85b52e66f (patch)
treec2ed82304c6a373b86be0e11568f33d9ce93dcdc /tests/test_taskipy.py
parentRelease version 1.7.0 (diff)
downloadtaskipy2-7160f5f9628a04d42e4ac9ae77c08fa85b52e66f.zip
Allow Declaring Tasks with Descriptions (#35)
adds the ability to declare tasks explicitly, including command and description text
Diffstat (limited to 'tests/test_taskipy.py')
-rw-r--r--tests/test_taskipy.py75
1 files changed, 68 insertions, 7 deletions
diff --git a/tests/test_taskipy.py b/tests/test_taskipy.py
index cac0809..84b767a 100644
--- a/tests/test_taskipy.py
+++ b/tests/test_taskipy.py
@@ -65,6 +65,11 @@ class TaskipyTestCase(unittest.TestCase):
full_string.find(substr_b),
msg=f'Expected \n "{substr_a}"\nto appear before\n "{substr_b}"\nin\n "{full_string}"')
+ def assertTerminalTextEqual(self, expected: str, actual: str):
+ expected_without_ansi_chars = expected.encode('ascii', 'ignore')
+ actual_without_ansi_chars = actual.encode('ascii', 'ignore')
+ self.assertEqual(expected_without_ansi_chars, actual_without_ansi_chars)
+
class RunTaskTestCase(TaskipyTestCase):
def test_running_task(self):
@@ -94,6 +99,7 @@ class RunTaskTestCase(TaskipyTestCase):
self.assertSubstr('hello stderr', stderr)
+
class TaskPrePostHooksTestCase(TaskipyTestCase):
def test_running_pre_task_hook(self):
cwd = self.create_test_dir_from_fixture('project_with_pre_post_task_hooks')
@@ -177,23 +183,23 @@ class PassArgumentsTestCase(TaskipyTestCase):
class ListTasksTestCase(TaskipyTestCase):
project_tasks_output = "\n".join([
- "one echo first task",
- "two echo second task",
- "three echo third task",
+ "one echo first task",
+ "two echo second task",
+ "three echo third task",
])
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)
- self.assertEqual(self.project_tasks_output, stdout.strip())
+ self.assertTerminalTextEqual(self.project_tasks_output, stdout.strip())
self.assertEqual(exit_code, 0)
def test_running_task_list_with_shorthand(self):
cwd = self.create_test_dir_from_fixture('project_with_tasks_to_list')
exit_code, stdout, _ = self.run_task('-l', cwd=cwd)
- self.assertEqual(self.project_tasks_output, stdout.strip())
+ self.assertTerminalTextEqual(self.project_tasks_output, stdout.strip())
self.assertEqual(exit_code, 0)
def test_running_task_list_before_name(self):
@@ -201,7 +207,7 @@ class ListTasksTestCase(TaskipyTestCase):
# anything following the flag should be ignored
exit_code, stdout, _ = self.run_task('--list', ['one'], cwd=cwd)
- self.assertEqual(self.project_tasks_output, stdout.strip())
+ self.assertTerminalTextEqual(self.project_tasks_output, stdout.strip())
self.assertEqual(exit_code, 0)
def test_running_task_list_with_arg(self):
@@ -210,8 +216,63 @@ class ListTasksTestCase(TaskipyTestCase):
exit_code, stdout, _ = self.run_task('one', ['--list'], cwd=cwd)
expected = "first task --list"
- self.assertEqual(expected, stdout.strip())
+ self.assertTerminalTextEqual(expected, stdout.strip())
+ self.assertEqual(exit_code, 0)
+
+
+class TaskDescriptionTestCase(TaskipyTestCase):
+ def test_running_task_with_description(self):
+ py_project_toml = '''
+ [tool.taskipy.tasks]
+ print_age = { cmd = "echo age is 29", help = "prints the age" }
+ '''
+ cwd = self.create_test_dir_with_py_project_toml(py_project_toml)
+ _, stdout, _ = self.run_task('print_age', cwd=cwd)
+
+ self.assertSubstr('age is 29', stdout)
+
+ def test_listing_task_with_description(self):
+ py_project_toml = '''
+ [tool.taskipy.tasks]
+ print_age = { cmd = "echo age is 29", help = "prints the age" }
+ '''
+ cwd = self.create_test_dir_with_py_project_toml(py_project_toml)
+ _, stdout, _ = self.run_task('--list', cwd=cwd)
+
+ self.assertSubstr('prints the age', stdout)
+
+ def test_reject_task_for_not_having_cmd(self):
+ py_project_toml = '''
+ [tool.taskipy.tasks]
+ print_age = { help = "prints the age" }
+ '''
+ cwd = self.create_test_dir_with_py_project_toml(py_project_toml)
+ exit_code, stdout, _ = self.run_task('print_age', cwd=cwd)
+
+ self.assertEqual(exit_code, 1)
+ self.assertSubstr('the task item does not have the "cmd" property', stdout)
+
+ def test_allow_task_to_not_have_help(self):
+ py_project_toml = '''
+ [tool.taskipy.tasks]
+ print_age = { cmd = "echo age is 29" }
+ '''
+ cwd = self.create_test_dir_with_py_project_toml(py_project_toml)
+ exit_code, stdout, _ = self.run_task('print_age', cwd=cwd)
+
self.assertEqual(exit_code, 0)
+ self.assertSubstr('age is 29', stdout)
+
+ def test_reject_task_that_is_not_string_nor_object(self):
+ py_project_toml = '''
+ [tool.taskipy.tasks]
+ print_age = 5
+ '''
+ cwd = self.create_test_dir_with_py_project_toml(py_project_toml)
+ exit_code, stdout, _ = self.run_task('print_age', cwd=cwd)
+
+ self.assertEqual(exit_code, 1)
+ self.assertSubstr('tasks must be strings, or dicts that contain { cmd, help }', stdout)
class TaskRunFailTestCase(TaskipyTestCase):