Пример #1
0
    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))
Пример #2
0
    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))
Пример #3
0
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
Пример #4
0
    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))
Пример #5
0
 def test_load_object_with_class(self):
     object_id = '.'.join([SomeClass.__module__, SomeClass.__name__])
     obj = tobiko.load_object(object_id)
     self.assertIs(SomeClass, obj)
Пример #6
0
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