home · contact · privacy
Refactor tests.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 17 May 2024 22:59:49 +0000 (00:59 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 17 May 2024 22:59:49 +0000 (00:59 +0200)
tests/conditions.py
tests/processes.py
tests/utils.py

index 45c3df7cfff43fe0f365216e7b6555d9299fefb0..37a97a5c91a4dcf6a25f26b2110b77e33c91519a 100644 (file)
@@ -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):
index 9e769c1e3da6acafa81b3d529d040aba4a5c5251..160442b287a08733ac6c4546ec77e696216ca4f7 100644 (file)
@@ -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):
index c1a22b64fb56c9c4fd566245ce047c1d7fff428d..69037cc8b5d628a8da68e4d3f40921b3d80f2c7c 100644 (file)
@@ -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)