aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/pyexiv2.py7
-rw-r--r--unittest/notifying_list.py15
2 files changed, 20 insertions, 2 deletions
diff --git a/src/pyexiv2.py b/src/pyexiv2.py
index 3b1a04a..e72e9d9 100644
--- a/src/pyexiv2.py
+++ b/src/pyexiv2.py
@@ -262,6 +262,9 @@ class ListenerInterface(object):
def extended(self, items):
raise NotImplementedError()
+ def item_inserted(self, index, item):
+ raise NotImplementedError()
+
# TODO: define other methods.
@@ -307,6 +310,10 @@ class NotifyingList(list):
super(NotifyingList, self).extend(items)
self._notify_listeners('extended', items)
+ def insert(self, index, item):
+ super(NotifyingList, self).insert(index, item)
+ self._notify_listeners('item_inserted', index, item)
+
class MetadataTag(object):
diff --git a/unittest/notifying_list.py b/unittest/notifying_list.py
index 1834626..862f45a 100644
--- a/unittest/notifying_list.py
+++ b/unittest/notifying_list.py
@@ -52,6 +52,9 @@ class SimpleListener(ListenerInterface):
def extended(self, items):
self._notify('extended', items)
+ def item_inserted(self, index, item):
+ self._notify('item_inserted', index, item)
+
class TestNotifyingList(unittest.TestCase):
@@ -69,6 +72,7 @@ class TestNotifyingList(unittest.TestCase):
self.failUnlessRaises(NotImplementedError, self.values.__delitem__, 5)
self.failUnlessRaises(NotImplementedError, self.values.append, 17)
self.failUnlessRaises(NotImplementedError, self.values.extend, [11, 22])
+ self.failUnlessRaises(NotImplementedError, self.values.insert, 4, 24)
# TODO: test all operations (insertion, slicing, ...)
def test_one_listener(self):
@@ -86,7 +90,10 @@ class TestNotifyingList(unittest.TestCase):
self.values.extend([11, 22])
self.failUnlessEqual(listener.notifications, 4)
self.failUnlessEqual(listener.last, ('extended', ([11, 22],)))
- # TODO: test all operations (insertion, slicing, ...)
+ self.values.insert(4, 24)
+ self.failUnlessEqual(listener.notifications, 5)
+ self.failUnlessEqual(listener.last, ('item_inserted', (4, 24)))
+ # TODO: test all operations (slicing, ...)
def test_multiple_listeners(self):
# Register a random number of listeners
@@ -109,4 +116,8 @@ class TestNotifyingList(unittest.TestCase):
for listener in listeners:
self.failUnlessEqual(listener.notifications, 4)
self.failUnlessEqual(listener.last, ('extended', ([11, 22],)))
- # TODO: test all operations (insertion, slicing, ...)
+ self.values.insert(4, 24)
+ for listener in listeners:
+ self.failUnlessEqual(listener.notifications, 5)
+ self.failUnlessEqual(listener.last, ('item_inserted', (4, 24)))
+ # TODO: test all operations (slicing, ...)