Commit 06fba7a1 authored by Eliot Berriot's avatar Eliot Berriot

Added psot_register hook

parent d42cc5e5
......@@ -73,10 +73,13 @@ class Registry(OrderedDict):
o = self.prepare_data(obj)
n = self.prepare_name(obj, name)
self[n] = o
self.post_register(obj=0, name=n)
raise ValueError("{0} (type: {0.__class__}) is not a valid value for {1} registry".format(obj, self.__class__))
def post_register(self, obj, name):
def prepare_data(self, obj):
Override this methode if you want to manipulate data before registering it
......@@ -143,5 +143,20 @@ class RegistryTest(unittest.TestCase):
self.assertEqual(r.get('custom_key eliot'), n1)
self.assertEqual(r.get('custom_key alain'), n2)
def test_can_post_register_triggers_correctly(self):
class PostRegisterException(Exception):
class PostRegister(registries.Registry):
def post_register(self, obj, name):
raise PostRegisterException('Post register triggered')
r = PostRegister()
with self.assertRaises(PostRegisterException):
r.register("hello", name="world")
if __name__ == '__main__':
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment