def test_registered_items_are_stored_separately_by_registry(self): class RegistryOne(Registry): """A registry distinct from the base `Registry`.""" class RegistryTwo(Registry): """A registry distinct from the base `Registry`.""" name = self.getUniqueString() Registry.register_item(name, sentinel.item) RegistryOne.register_item(name, sentinel.item_in_one) RegistryTwo.register_item(name, sentinel.item_in_two) # Items stored in separate registries are stored separately; # names do not clash between registries. self.assertEqual(sentinel.item, Registry.get_item(name)) self.assertEqual(sentinel.item_in_one, RegistryOne.get_item(name)) self.assertEqual(sentinel.item_in_two, RegistryTwo.get_item(name))
def test_get_item_returns_None_default(self): self.assertIsNone(Registry.get_item("resource"))
def test_get_item_returns_default_if_value_not_present(self): self.assertEqual(sentinel.default, Registry.get_item("resource", sentinel.default))
def test_get_item(self): Registry.register_item("resource", sentinel.resource) self.assertEqual(sentinel.resource, Registry.get_item("resource"))
def test_register_and_unregister_item(self): name = self.getUniqueString() Registry.register_item(name, sentinel.item) Registry.unregister_item(name) self.assertIsNone(Registry.get_item(name)) self.assertNotIn(name, Registry)
def test_register_and_get_item(self): name = self.getUniqueString() item = self.getUniqueString() Registry.register_item(name, item) self.assertEqual(item, Registry.get_item(name))