def test_load_object_with_module(self): object_id = __name__ obj = tobiko.load_object(object_id) self.assertIs(sys.modules[object_id], obj) _loader = self.manager.get_loader(object_id) self.assertEqual(_loader.id, object_id) self.assertTrue(_loader.is_module) self.assertIs(_loader.get(), obj) self.assertIs(_loader, self.manager.get_loader(object_id))
def test_load_object_with_none(self): object_id = '.'.join([__name__, 'SOME_NONE']) obj = tobiko.load_object(object_id) self.assertIsNone(obj) _loader = self.manager.get_loader(object_id) self.assertEqual(_loader.id, object_id) self.assertFalse(_loader.is_module) self.assertIs(_loader.get(), obj) self.assertIs(_loader, self.manager.get_loader(object_id))
def get_fixture_class(obj): '''Get fixture class''' if isinstance(obj, six.string_types): obj = tobiko.load_object(obj) if not inspect.isclass(obj): obj = type(obj) assert issubclass(obj, fixtures.Fixture) return obj
def test_load_object_with_class_method(self): object_id = '.'.join([SomeClass.__module__, SomeClass.__name__, SomeClass.some_method.__name__]) obj = tobiko.load_object(object_id) self.assertEqual(SomeClass.some_method, obj) _loader = self.manager.get_loader(object_id) self.assertEqual(_loader.id, object_id) self.assertFalse(_loader.is_module) self.assertIs(_loader.get(), obj) self.assertIs(_loader, self.manager.get_loader(object_id))
def test_load_object_with_class(self): object_id = '.'.join([SomeClass.__module__, SomeClass.__name__]) obj = tobiko.load_object(object_id) self.assertIs(SomeClass, obj)
def get_name_and_object(obj): '''Get (name, obj) tuple identified by given :param obj:''' if isinstance(obj, six.string_types): return obj, tobiko.load_object(obj) else: return get_object_name(obj), obj