def get_factory(self): """Retrieve the wrapped factory.Factory subclass.""" if self.factory is None: # Must be a module path self.factory = utils.import_object(self.factory_module, self.factory_name) return self.factory
def get_factory(self): """Retrieve the factory.Factory subclass. Its value is cached in the 'factory' attribute, and retrieved through the factory_getter callable. """ if self.factory is None: factory_class = utils.import_object( self.module_name, self.factory_name) self.factory = factory_class return self.factory
def get_factory(self): """Retrieve the factory.Factory subclass. Its value is cached in the 'factory' attribute, and retrieved through the factory_getter callable. """ if self.factory is None: factory_class = utils.import_object(self.module_name, self.factory_name) self.factory = factory_class return self.factory
def test_datetime(self): imported = utils.import_object('datetime', 'date') import datetime d = datetime.date self.assertEqual(d, imported)
def test_invalid_module(self): with self.assertRaises(ImportError): utils.import_object('this-is-an-invalid-module', '__name__')
def test_unknown_attribute(self): with self.assertRaises(AttributeError): utils.import_object('datetime', 'foo')