From: Christian Heller Date: Fri, 12 Jul 2024 04:02:39 +0000 (+0200) Subject: Rename decorators for clearer meaning. X-Git-Url: https://plomlompom.com/repos/te"st.html?a=commitdiff_plain;h=e64ccf3686818c19c8acb78dfb2aab2a34c37e50;p=plomtask Rename decorators for clearer meaning. --- diff --git a/tests/utils.py b/tests/utils.py index a03de94..9f7bf7e 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -31,17 +31,17 @@ class TestCaseAugmented(TestCase): default_init_kwargs: dict[str, Any] = {} @staticmethod - def _within_checked_class(f: Callable[..., None]) -> Callable[..., None]: + def _run_if_checked_class(f: Callable[..., None]) -> Callable[..., None]: def wrapper(self: TestCase) -> None: if hasattr(self, 'checked_class'): f(self) return wrapper @classmethod - def _on_versioned_attributes(cls, - f: Callable[..., None] - ) -> Callable[..., None]: - @cls._within_checked_class + def _run_on_versioned_attributes(cls, + f: Callable[..., None] + ) -> Callable[..., None]: + @cls._run_if_checked_class def wrapper(self: TestCase) -> None: assert isinstance(self, TestCaseAugmented) for attr_name in self.checked_class.to_save_versioned(): @@ -62,7 +62,7 @@ class TestCaseSansDB(TestCaseAugmented): legal_ids = [1, 5] illegal_ids = [0] - @TestCaseAugmented._within_checked_class + @TestCaseAugmented._run_if_checked_class def test_id_validation(self) -> None: """Test .id_ validation/setting.""" for id_ in self.illegal_ids: @@ -72,7 +72,7 @@ class TestCaseSansDB(TestCaseAugmented): obj = self._make_from_defaults(id_) self.assertEqual(obj.id_, id_) - @TestCaseAugmented._on_versioned_attributes + @TestCaseAugmented._run_on_versioned_attributes def test_versioned_set(self, _: Any, __: str, @@ -111,7 +111,7 @@ class TestCaseSansDB(TestCaseAugmented): attr.set(to_set[1]) self.assertEqual(timesorted_vals, expected) - @TestCaseAugmented._on_versioned_attributes + @TestCaseAugmented._run_on_versioned_attributes def test_versioned_newest(self, _: Any, __: str, @@ -130,7 +130,7 @@ class TestCaseSansDB(TestCaseAugmented): attr.set(default) self.assertEqual(attr.newest, default) - @TestCaseAugmented._on_versioned_attributes + @TestCaseAugmented._run_on_versioned_attributes def test_versioned_at(self, _: Any, __: str, @@ -213,7 +213,7 @@ class TestCaseWithDB(TestCaseAugmented): hashes_db_found = [hash(x) for x in db_found] self.assertEqual(sorted(hashes_content), sorted(hashes_db_found)) - @TestCaseAugmented._on_versioned_attributes + @TestCaseAugmented._run_on_versioned_attributes def test_saving_versioned_attributes(self, owner: Any, attr_name: str, @@ -254,7 +254,7 @@ class TestCaseWithDB(TestCaseAugmented): attr_vals_saved = retrieve_attr_vals(attr) self.assertEqual(to_set, attr_vals_saved) - @TestCaseAugmented._within_checked_class + @TestCaseAugmented._run_if_checked_class def test_saving_and_caching(self) -> None: """Test effects of .cache() and .save().""" id1 = self.default_ids[0] @@ -289,7 +289,7 @@ class TestCaseWithDB(TestCaseAugmented): with self.assertRaises(HandledException): obj1.save(self.db_conn) - @TestCaseAugmented._within_checked_class + @TestCaseAugmented._run_if_checked_class def test_by_id(self) -> None: """Test .by_id().""" id1, id2, _ = self.default_ids @@ -305,7 +305,7 @@ class TestCaseWithDB(TestCaseAugmented): obj2.save(self.db_conn) self.assertEqual(obj2, self.checked_class.by_id(self.db_conn, id2)) - @TestCaseAugmented._within_checked_class + @TestCaseAugmented._run_if_checked_class def test_by_id_or_create(self) -> None: """Test .by_id_or_create.""" # check .by_id_or_create fails if wrong class @@ -328,7 +328,7 @@ class TestCaseWithDB(TestCaseAugmented): self.checked_class.by_id(self.db_conn, item.id_) self.assertEqual(self.checked_class(item.id_), item) - @TestCaseAugmented._within_checked_class + @TestCaseAugmented._run_if_checked_class def test_from_table_row(self) -> None: """Test .from_table_row() properly reads in class directly from DB.""" id_ = self.default_ids[0] @@ -352,7 +352,7 @@ class TestCaseWithDB(TestCaseAugmented): self.assertEqual({retrieved.id_: retrieved}, self.checked_class.get_cache()) - @TestCaseAugmented._on_versioned_attributes + @TestCaseAugmented._run_on_versioned_attributes def test_versioned_history_from_row(self, owner: Any, _: str, @@ -375,7 +375,7 @@ class TestCaseWithDB(TestCaseAugmented): for timestamp, value in attr.history.items(): self.assertEqual(value, loaded_attr.history[timestamp]) - @TestCaseAugmented._within_checked_class + @TestCaseAugmented._run_if_checked_class def test_all(self) -> None: """Test .all() and its relation to cache and savings.""" id1, id2, id3 = self.default_ids @@ -393,7 +393,7 @@ class TestCaseWithDB(TestCaseAugmented): self.assertEqual(sorted(self.checked_class.all(self.db_conn)), sorted([item1, item2, item3])) - @TestCaseAugmented._within_checked_class + @TestCaseAugmented._run_if_checked_class def test_singularity(self) -> None: """Test pointers made for single object keep pointing to it.""" id1 = self.default_ids[0] @@ -405,7 +405,7 @@ class TestCaseWithDB(TestCaseAugmented): retrieved = self.checked_class.by_id(self.db_conn, id1) self.assertEqual(new_attr, getattr(retrieved, attr_name)) - @TestCaseAugmented._on_versioned_attributes + @TestCaseAugmented._run_on_versioned_attributes def test_versioned_singularity(self, owner: Any, attr_name: str, @@ -421,7 +421,7 @@ class TestCaseWithDB(TestCaseAugmented): attr_retrieved = getattr(retrieved, attr_name) self.assertEqual(attr.history, attr_retrieved.history) - @TestCaseAugmented._within_checked_class + @TestCaseAugmented._run_if_checked_class def test_remove(self) -> None: """Test .remove() effects on DB and cache.""" id_ = self.default_ids[0]