aboutsummaryrefslogtreecommitdiffstats
path: root/unittest/notifying_list.py
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2009-04-28 19:48:10 +0200
committerOlivier Tilloy <olivier@tilloy.net>2009-04-28 19:48:10 +0200
commit4eb85bd3b88222b9e33c5a76e771fd284c7b0fb5 (patch)
tree874e6681ff20b6ed82e69cd6fcdd9d762cbf0c7b /unittest/notifying_list.py
parent2ef1f72a9b8f7d6ad82ee4afd57612c1f0fdbb0e (diff)
downloadpyexiv2-4eb85bd3b88222b9e33c5a76e771fd284c7b0fb5.tar.gz
Notify on append().
Diffstat (limited to 'unittest/notifying_list.py')
-rw-r--r--unittest/notifying_list.py31
1 files changed, 22 insertions, 9 deletions
diff --git a/unittest/notifying_list.py b/unittest/notifying_list.py
index 05372be..e7b01dd 100644
--- a/unittest/notifying_list.py
+++ b/unittest/notifying_list.py
@@ -33,16 +33,21 @@ class SimpleListener(ListenerInterface):
# Total number of notifications
notifications = 0
- # Last notification: (method_name, *args)
+ # Last notification: (method_name, args)
last = None
- def item_changed(self, index, item):
+ def _notify(self, method_name, *args):
self.notifications += 1
- self.last = ('item_changed', index, item)
+ self.last = (method_name, args)
+
+ def item_changed(self, index, item):
+ self._notify('item_changed', index, item)
def item_deleted(self, index):
- self.notifications += 1
- self.last = ('item_deleted', index)
+ self._notify('item_deleted', index)
+
+ def item_appended(self, item):
+ self._notify('item_appended', item)
class TestNotifyingList(unittest.TestCase):
@@ -59,6 +64,7 @@ class TestNotifyingList(unittest.TestCase):
self.values.register_listener(ListenerInterface())
self.failUnlessRaises(NotImplementedError, self.values.__setitem__, 3, 13)
self.failUnlessRaises(NotImplementedError, self.values.__delitem__, 5)
+ self.failUnlessRaises(NotImplementedError, self.values.append, 17)
# TODO: test all operations (insertion, slicing, ...)
def test_one_listener(self):
@@ -66,10 +72,13 @@ class TestNotifyingList(unittest.TestCase):
self.values.register_listener(listener)
self.values[3] = 13
self.failUnlessEqual(listener.notifications, 1)
- self.failUnlessEqual(listener.last, ('item_changed', 3, 13))
+ self.failUnlessEqual(listener.last, ('item_changed', (3, 13)))
del self.values[5]
self.failUnlessEqual(listener.notifications, 2)
- self.failUnlessEqual(listener.last, ('item_deleted', 5))
+ self.failUnlessEqual(listener.last, ('item_deleted', (5,)))
+ self.values.append(17)
+ self.failUnlessEqual(listener.notifications, 3)
+ self.failUnlessEqual(listener.last, ('item_appended', (17,)))
# TODO: test all operations (insertion, slicing, ...)
def test_multiple_listeners(self):
@@ -80,9 +89,13 @@ class TestNotifyingList(unittest.TestCase):
self.values[3] = 13
for listener in listeners:
self.failUnlessEqual(listener.notifications, 1)
- self.failUnlessEqual(listener.last, ('item_changed', 3, 13))
+ self.failUnlessEqual(listener.last, ('item_changed', (3, 13)))
del self.values[5]
for listener in listeners:
self.failUnlessEqual(listener.notifications, 2)
- self.failUnlessEqual(listener.last, ('item_deleted', 5))
+ self.failUnlessEqual(listener.last, ('item_deleted', (5,)))
+ self.values.append(17)
+ for listener in listeners:
+ self.failUnlessEqual(listener.notifications, 3)
+ self.failUnlessEqual(listener.last, ('item_appended', (17,)))
# TODO: test all operations (insertion, slicing, ...)