diff options
-rw-r--r-- | unittest/notifying_list.py | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/unittest/notifying_list.py b/unittest/notifying_list.py index 17120b5..170c2e3 100644 --- a/unittest/notifying_list.py +++ b/unittest/notifying_list.py @@ -77,7 +77,6 @@ class TestNotifyingList(unittest.TestCase): self.failUnlessRaises(NotImplementedError, self.values.extend, [11, 22]) self.failUnlessRaises(NotImplementedError, self.values.insert, 4, 24) self.failUnlessRaises(NotImplementedError, self.values.pop) - self.failUnlessRaises(NotImplementedError, self.values.pop, 3) # TODO: test all operations (insertion, slicing, ...) def test_multiple_listeners(self): @@ -85,39 +84,71 @@ class TestNotifyingList(unittest.TestCase): listeners = [SimpleListener() for i in xrange(random.randint(3, 20))] for listener in listeners: self.values.register_listener(listener) + self.values[3] = 13 self.failUnlessEqual(self.values, [5, 7, 9, 13, 57, 3, 2]) for listener in listeners: self.failUnlessEqual(listener.notifications, 1) self.failUnlessEqual(listener.last, ('item_changed', (3, 13))) + + self.failUnlessRaises(IndexError, self.values.__setitem__, 9, 27) + self.failUnlessEqual(self.values, [5, 7, 9, 13, 57, 3, 2]) + for listener in listeners: + self.failUnlessEqual(listener.notifications, 1) + self.failUnlessEqual(listener.last, ('item_changed', (3, 13))) + del self.values[5] self.failUnlessEqual(self.values, [5, 7, 9, 13, 57, 2]) for listener in listeners: self.failUnlessEqual(listener.notifications, 2) self.failUnlessEqual(listener.last, ('item_deleted', (5,))) + + self.failUnlessRaises(IndexError, self.values.__delitem__, 9) + self.failUnlessEqual(self.values, [5, 7, 9, 13, 57, 2]) + for listener in listeners: + self.failUnlessEqual(listener.notifications, 2) + self.failUnlessEqual(listener.last, ('item_deleted', (5,))) + self.values.append(17) self.failUnlessEqual(self.values, [5, 7, 9, 13, 57, 2, 17]) for listener in listeners: self.failUnlessEqual(listener.notifications, 3) self.failUnlessEqual(listener.last, ('item_appended', (17,))) + self.values.extend([11, 22]) self.failUnlessEqual(self.values, [5, 7, 9, 13, 57, 2, 17, 11, 22]) for listener in listeners: self.failUnlessEqual(listener.notifications, 4) self.failUnlessEqual(listener.last, ('extended', ([11, 22],))) + + self.failUnlessRaises(TypeError, self.values.extend, 26) + self.failUnlessEqual(self.values, [5, 7, 9, 13, 57, 2, 17, 11, 22]) + for listener in listeners: + self.failUnlessEqual(listener.notifications, 4) + self.failUnlessEqual(listener.last, ('extended', ([11, 22],))) + self.values.insert(4, 24) self.failUnlessEqual(self.values, [5, 7, 9, 13, 24, 57, 2, 17, 11, 22]) for listener in listeners: self.failUnlessEqual(listener.notifications, 5) self.failUnlessEqual(listener.last, ('item_inserted', (4, 24))) + self.values.pop() self.failUnlessEqual(self.values, [5, 7, 9, 13, 24, 57, 2, 17, 11]) for listener in listeners: self.failUnlessEqual(listener.notifications, 6) self.failUnlessEqual(listener.last, ('item_popped', (9,))) + self.values.pop(4) self.failUnlessEqual(self.values, [5, 7, 9, 13, 57, 2, 17, 11]) for listener in listeners: self.failUnlessEqual(listener.notifications, 7) self.failUnlessEqual(listener.last, ('item_popped', (4,))) + + self.failUnlessRaises(IndexError, self.values.pop, 33) + self.failUnlessEqual(self.values, [5, 7, 9, 13, 57, 2, 17, 11]) + for listener in listeners: + self.failUnlessEqual(listener.notifications, 7) + self.failUnlessEqual(listener.last, ('item_popped', (4,))) + # TODO: test all operations (slicing, ...) |