aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2020-06-14 17:06:23 -0500
committerGitHub <noreply@github.com>2020-06-15 01:06:23 +0300
commit89500fba9009efedd42b7a3b5e5197f12419d8a4 (patch)
treea4e66649642efc15e6e7073241b03b0ebeea9b44 /tests
parentUpdate ADVANCED_FEATURES.md (diff)
downloadtaskipy2-89500fba9009efedd42b7a3b5e5197f12419d8a4.zip
Refactor taskipy into Task, PyProject, and TaskRunner (#15)
* Run `poetry update` * Sort test imports & convert unused f strings to strings There were some f strings that weren't interpolating anything. * Create custom exceptions * Refactor taskipi package into task, pyproject, and task_runner * Add docstrings & types to task & task_runner. Also, a small refactoring of __bail_on_first_fail() in task_runner.py. * Remove docstrings * Add MissingTaskipySettingsSectionError * Make path & items in PyProject private * Check runner is string rather than catching AttributeError * Add default exception case to cli * Add exit_code class variable to exceptions * Change PyProject to take in the file_path This also converts the instance variables to be private and has __load_toml_file convert the file_path to a Path if it is a str. We also no longer store the file_path since __load_toml_file is the only place it is needed so it is just passed in. * Task now builds the commands & takes in args + project I think args could possibly be moved over to commands since that is the only place it is used and that would reduce the amount of things we are passing in to Task. commands would just have to be converted to a method instead of a property then. * TaskRunner only runs the commands now with the project passed in Instead of putting the commands together, that is now delegated to Task. The run_commands_and_bail_on_first_fail method is now gone as that is what `run` does now. Furthermore, the instance variables of TaskRunner are private now. A single instance of the TaskRunner can now run many tasks now, since it is not tied to any particular task. * Update cli to use updated TaskRunner The pyproject.toml path is now passed in with the command name and args being passed to `run`. * Use single quotes * Extract pre_task & post_task to use __find_hooks They are basically the same method, with a one word difference.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_taskipy.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/tests/test_taskipy.py b/tests/test_taskipy.py
index 78c2e10..5733006 100644
--- a/tests/test_taskipy.py
+++ b/tests/test_taskipy.py
@@ -1,14 +1,20 @@
import os
-import unittest
-import subprocess
import random
-import time
import signal
-import psutil # type: ignore
+import subprocess
+import time
+import unittest
import warnings
from os import path
from typing import List, Tuple
-from tests.utils.project import TempProjectDir, GenerateProjectFromFixture, GenerateProjectWithPyProjectToml
+
+import psutil # type: ignore
+
+from tests.utils.project import (
+ GenerateProjectFromFixture,
+ GenerateProjectWithPyProjectToml,
+ TempProjectDir
+)
class TaskipyTestCase(unittest.TestCase):
@@ -134,7 +140,7 @@ class PassArgumentsTestCase(TaskipyTestCase):
cwd = self.create_test_dir_from_fixture('project_with_tasks_that_accept_arguments')
exit_code, stdout, _ = self.run_task('echo_named', args=['-h'], cwd=cwd)
- self.assertSubstr(f'got a named argument -h', stdout)
+ self.assertSubstr('got a named argument -h', stdout)
self.assertEqual(exit_code, 0)
def test_running_task_with_multiple_arguments(self):
@@ -142,7 +148,7 @@ class PassArgumentsTestCase(TaskipyTestCase):
args = ['one', 'two', 'three', 'four', 'five']
exit_code, stdout, _ = self.run_task('echo_args_count', args=args, cwd=cwd)
- self.assertSubstr(f'the argument count is 5', stdout)
+ self.assertSubstr('the argument count is 5', stdout)
self.assertEqual(exit_code, 0)
def test_running_task_with_arguments_with_spaces(self):
@@ -159,7 +165,7 @@ class PassArgumentsTestCase(TaskipyTestCase):
some_random_number = random.randint(1, 1000)
exit_code, stdout, _ = self.run_task('echo_on_prehook', args=[f'{some_random_number}'], cwd=cwd)
- self.assertSubstr(f'the number in prehook is', stdout)
+ self.assertSubstr('the number in prehook is', stdout)
self.assertNotSubstr(f'the number in prehook is {some_random_number}', stdout)
self.assertEqual(exit_code, 0)
@@ -168,7 +174,7 @@ class PassArgumentsTestCase(TaskipyTestCase):
some_random_number = random.randint(1, 1000)
exit_code, stdout, _ = self.run_task('echo_on_posthook', args=[f'{some_random_number}'], cwd=cwd)
- self.assertSubstr(f'the number in posthook is', stdout)
+ self.assertSubstr('the number in posthook is', stdout)
self.assertNotSubstr(f'the number in posthook is {some_random_number}', stdout)
self.assertEqual(exit_code, 0)