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():
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:
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,
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,
attr.set(default)
self.assertEqual(attr.newest, default)
- @TestCaseAugmented._on_versioned_attributes
+ @TestCaseAugmented._run_on_versioned_attributes
def test_versioned_at(self,
_: Any,
__: str,
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,
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]
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
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
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]
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,
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
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]
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,
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]