def test_get_registered_class_returns_registered_class(self): # for backwards compatibility. You can (and should) just access # your registry like a normal dictionary. lc = Registry() TestClass = self.get_test_class("ABC") lc.register(TestClass) self.assertEqual(lc.get_registered_class("ABC"), TestClass)
def test_raises_already_registered_when_key_has_already_been_registered(self): test_class_one = self.get_test_class("ABC") test_class_two = type('TestClassTwo', (object, ), {'key': "ABC"}) lc = Registry() lc.register(test_class_one) with self.assertRaises(AlreadyRegistered) as e: lc.register(test_class_two) self.assertEqual("Key 'ABC' has already been registered as 'TestClass'.", str(e.exception))
def test_registry_allows_customizable_key_name(self): lc = Registry(key_name='obj_code') TestClass = type('TestClass', (object, ), {'obj_code': "code1"}) lc.register(TestClass) self.assertEqual(lc["code1"], TestClass)
def test_register_adds_item_to_collection(self): lc = Registry() TestClass = self.get_test_class("ABC") lc.register(TestClass) self.assertEqual(lc["ABC"], TestClass)