예제 #1
0
 def test_getitem(self) -> None:
     sut = EventHandlingSetList(lambda _: None, lambda _: None)
     sut.append(1, 2, 3)
     self.assertEqual(1, sut[0])
     self.assertEqual(2, sut[1])
     self.assertEqual(3, sut[2])
     with self.assertRaises(IndexError):
         sut[3]
예제 #2
0
    def test_with_handler(self):
        reference = []

        def addition_handler(added_value):
            reference.append(added_value)

        def removal_handler(removed_value):
            reference.remove(removed_value)

        sut = EventHandlingSetList(addition_handler, removal_handler)

        value = 'A valuable value'

        sut.append(value)
        self.assertCountEqual([value], sut)
        self.assertEquals([value], reference)

        newvalue = 'A even more valuable value'

        sut.replace([newvalue])
        self.assertCountEqual([newvalue], sut)
        self.assertEquals([newvalue], reference)

        sut.remove(newvalue)
        self.assertCountEqual([], sut)
        self.assertEquals([], reference)
예제 #3
0
 def test_append(self):
     added = []
     removal_handler = Mock()
     sut = EventHandlingSetList(lambda value: added.append(value), removal_handler)
     sut.append(3)
     sut.append(2)
     sut.append(1)
     # Append an already appended value again, and assert that it was ignored.
     sut.append(1)
     self.assertSequenceEqual([3, 2, 1], sut)
     self.assertSequenceEqual([3, 2, 1], added)
     removal_handler.assert_not_called()
예제 #4
0
 def test_set_like_functionality(self) -> None:
     sut = EventHandlingSetList(lambda _: None, lambda _: None)
     # Ensure duplicates are skipped.
     sut.append(1, 2, 3, 1, 2, 3, 1, 2, 3)
     # Ensure skipped duplicates do not affect further new values.
     sut.append(1, 2, 3, 4, 5, 6, 7, 8, 9)
     self.assertSequenceEqual([1, 2, 3, 4, 5, 6, 7, 8, 9], sut)
예제 #5
0
 def test_clear(self):
     added = []
     removed = []
     sut = EventHandlingSetList(lambda value: added.append(value), lambda value: removed.append(value))
     sut.append(1, 2, 3)
     sut.clear()
     self.assertSequenceEqual([], sut)
     self.assertSequenceEqual([1, 2, 3], added)
     self.assertSequenceEqual([1, 2, 3], removed)
예제 #6
0
 def test_replace(self):
     added = []
     removed = []
     sut = EventHandlingSetList(lambda value: added.append(value), lambda value: removed.append(value))
     sut.append(1, 2, 3)
     sut.replace(4, 5, 6)
     self.assertSequenceEqual([4, 5, 6], sut)
     self.assertSequenceEqual([1, 2, 3, 4, 5, 6], added)
     self.assertSequenceEqual([1, 2, 3], removed)
예제 #7
0
 def test_remove(self) -> None:
     added = []
     removed = []
     sut = EventHandlingSetList(lambda value: added.append(value),
                                lambda value: removed.append(value))
     sut.append(1, 2, 3, 4)
     sut.remove(4, 2)
     self.assertSequenceEqual([1, 3], sut)
     self.assertSequenceEqual([1, 2, 3, 4], added)
     self.assertSequenceEqual([4, 2], removed)
예제 #8
0
 def test_iter(self) -> None:
     sut = EventHandlingSetList(lambda _: None, lambda _: None)
     sut.append(1, 2, 3)
     # list() gets all items through __iter__ and stores them in the same order.
     self.assertSequenceEqual([1, 2, 3], list(sut))
예제 #9
0
 def test_len(self) -> None:
     sut = EventHandlingSetList(lambda _: None, lambda _: None)
     sut.append(1, 2, 3)
     self.assertEqual(3, len(sut))
예제 #10
0
 def test_list(self) -> None:
     sut = EventHandlingSetList(lambda _: None, lambda _: None)
     sut.append(1, 2, 3)
     self.assertEqual([1, 2, 3], sut.list)
예제 #11
0
 def test_list(self):
     sut = EventHandlingSetList(lambda _: None, lambda _: None)
     value = 'Some value'
     sut.append(value)
     self.assertEquals([value], sut.list)