Esempio n. 1
0
 def test_getattr(self):
     scope = {}
     placeholder = demandload.Placeholder(scope, 'foo', list)
     self.assertEqual(scope, object.__getattribute__(placeholder, '_scope'))
     self.assertEqual(placeholder.__doc__, [].__doc__)
     self.assertEqual(scope['foo'], [])
     demandload._protection_enabled = lambda: True
     self.assertRaises(ValueError, getattr, placeholder, '__doc__')
Esempio n. 2
0
 def test_getattr(self):
     scope = {}
     placeholder = demandload.Placeholder(scope, 'foo', list)
     assert scope == object.__getattribute__(placeholder, '_scope')
     assert placeholder.__doc__ == [].__doc__
     assert scope['foo'] == []
     demandload._protection_enabled = lambda: True
     with pytest.raises(ValueError):
         getattr(placeholder, '__doc__')
Esempio n. 3
0
 def test_call(self):
     def passthrough(*args, **kwargs):
         return args, kwargs
     def get_func():
         return passthrough
     scope = {}
     placeholder = demandload.Placeholder(scope, 'foo', get_func)
     assert scope == object.__getattribute__(placeholder, '_scope')
     assert (('arg',), {'kwarg': 42}) == placeholder('arg', kwarg=42)
     assert passthrough is scope['foo']
Esempio n. 4
0
    def test_setattr(self):
        class Struct(object):
            pass

        scope = {}
        placeholder = demandload.Placeholder(scope, 'foo', Struct)
        placeholder.val = 7
        demandload._protection_enabled = lambda: True
        self.assertRaises(ValueError, getattr, placeholder, 'val')
        self.assertEqual(7, scope['foo'].val)
Esempio n. 5
0
    def test_setattr(self):
        class Struct:
            pass

        scope = {}
        placeholder = demandload.Placeholder(scope, 'foo', Struct)
        placeholder.val = 7
        demandload._protection_enabled = lambda: True
        with pytest.raises(ValueError):
            getattr(placeholder, 'val')
        assert 7 == scope['foo'].val
Esempio n. 6
0
    def test_call(self):
        def passthrough(*args, **kwargs):
            return args, kwargs

        def get_func():
            return passthrough

        scope = {}
        placeholder = demandload.Placeholder(scope, 'foo', get_func)
        self.assertEqual(scope, object.__getattribute__(placeholder, '_scope'))
        self.assertEqual((('arg', ), {
            'kwarg': 42
        }), placeholder('arg', kwarg=42))
        self.assertIdentical(passthrough, scope['foo'])
Esempio n. 7
0
 def test__str__(self):
     scope = {}
     placeholder = demandload.Placeholder(scope, 'foo', list)
     assert scope == object.__getattribute__(placeholder, '_scope')
     assert str(placeholder) == str([])
     assert scope['foo'] == []
Esempio n. 8
0
 def test__str__(self):
     scope = {}
     placeholder = demandload.Placeholder(scope, 'foo', list)
     self.assertEqual(scope, object.__getattribute__(placeholder, '_scope'))
     self.assertEqual(str(placeholder), str([]))
     self.assertEqual(scope['foo'], [])
Esempio n. 9
0
 def test__str__(self):
     scope = {}
     placehold = demandload.Placeholder(scope, 'foo', list)
     self.assertEqual({}, scope)
     self.assertEqual(str(placehold), str([]))
     self.assertEqual(scope['foo'], [])