From: Christian Heller Date: Fri, 17 May 2024 22:59:49 +0000 (+0200) Subject: Refactor tests. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7B%20deck_id%20%7D%7D/%7Broute%7D?a=commitdiff_plain;h=5afb47e3aaed921997d11abf88a81602700639f3;p=plomtask Refactor tests. --- diff --git a/tests/conditions.py b/tests/conditions.py index 45c3df7..37a97a5 100644 --- a/tests/conditions.py +++ b/tests/conditions.py @@ -9,16 +9,8 @@ from plomtask.exceptions import HandledException class TestsSansDB(TestCaseSansDB): """Tests requiring no DB setup.""" checked_class = Condition - - def test_Condition_id_setting(self) -> None: - """Test .id_ being set and its legal range being enforced.""" - self.check_id_setting() - - def test_Condition_versioned_defaults(self) -> None: - """Test defaults of VersionedAttributes.""" - self.check_versioned_defaults({ - 'title': 'UNNAMED', - 'description': ''}) + do_id_test = True + versioned_defaults_to_test = {'title': 'UNNAMED', 'description': ''} class TestsWithDB(TestCaseWithDB): diff --git a/tests/processes.py b/tests/processes.py index 9e769c1..160442b 100644 --- a/tests/processes.py +++ b/tests/processes.py @@ -9,26 +9,16 @@ from plomtask.todos import Todo class TestsSansDB(TestCaseSansDB): """Module tests not requiring DB setup.""" checked_class = Process - - def test_Process_id_setting(self) -> None: - """Test .id_ being set and its legal range being enforced.""" - self.check_id_setting() - - def test_Process_versioned_defaults(self) -> None: - """Test defaults of VersionedAttributes.""" - self.check_versioned_defaults({ - 'title': 'UNNAMED', - 'description': '', - 'effort': 1.0}) + do_id_test = True + versioned_defaults_to_test = {'title': 'UNNAMED', 'description': '', + 'effort': 1.0} class TestsSansDBProcessStep(TestCaseSansDB): """Module tests not requiring DB setup.""" checked_class = ProcessStep - - def test_ProcessStep_id_setting(self) -> None: - """Test .id_ being set and its legal range being enforced.""" - self.check_id_setting(2, 3, 4) + do_id_test = True + default_init_args = [2, 3, 4] class TestsWithDB(TestCaseWithDB): diff --git a/tests/utils.py b/tests/utils.py index c1a22b6..69037cc 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -18,18 +18,25 @@ from plomtask.exceptions import NotFoundException, HandledException class TestCaseSansDB(TestCase): """Tests requiring no DB setup.""" checked_class: Any + do_id_test: bool = False + default_init_args: list[Any] = [] + versioned_defaults_to_test: dict[str, str | float] = {} - def check_id_setting(self, *args: Any) -> None: + def test_id_setting(self) -> None: """Test .id_ being set and its legal range being enforced.""" + if not self.do_id_test: + return with self.assertRaises(HandledException): - self.checked_class(0, *args) - obj = self.checked_class(5, *args) + self.checked_class(0, *self.default_init_args) + obj = self.checked_class(5, *self.default_init_args) self.assertEqual(obj.id_, 5) - def check_versioned_defaults(self, attrs: dict[str, Any]) -> None: + def test_versioned_defaults(self) -> None: """Test defaults of VersionedAttributes.""" - obj = self.checked_class(None) - for k, v in attrs.items(): + if len(self.versioned_defaults_to_test) == 0: + return + obj = self.checked_class(1, *self.default_init_args) + for k, v in self.versioned_defaults_to_test.items(): self.assertEqual(getattr(obj, k).newest, v)