Skip to content

Commit

Permalink
test.model.test_base: add test for add and del atomicity of `Cons…
Browse files Browse the repository at this point in the history
…trainedList`
  • Loading branch information
jkhsjdhjs committed Aug 29, 2023
1 parent 917a35d commit 5ee39dc
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/model/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,3 +1114,28 @@ def del_hook(itm: int, list_: List[int]) -> None:
self.assertEqual(existing_items, [1, 2, 3, 4, 10, 11])
check_list.pop()
self.assertEqual(c_list, check_list)

def test_atomicity(self) -> None:
def hook(itm: int, _list: List[int]) -> None:
if itm > 2:
raise ValueError

c_list: model.ConstrainedList[int] = model.ConstrainedList([], item_add_hook=hook)
with self.assertRaises(ValueError):
c_list = model.ConstrainedList([1, 2, 3], item_add_hook=hook)
self.assertEqual(c_list, [])
with self.assertRaises(ValueError):
c_list.extend([1, 2, 3])
self.assertEqual(c_list, [])
c_list.extend([1, 2])
self.assertEqual(c_list, [1, 2])

c_list = model.ConstrainedList([1, 2, 3], item_del_hook=hook)
with self.assertRaises(ValueError):
del c_list[0:3]
self.assertEqual(c_list, [1, 2, 3])
with self.assertRaises(ValueError):
c_list.clear()
self.assertEqual(c_list, [1, 2, 3])
del c_list[0:2]
self.assertEqual(c_list, [3])

0 comments on commit 5ee39dc

Please sign in to comment.