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__')
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__')
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']
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)
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
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'])
def test__str__(self): scope = {} placeholder = demandload.Placeholder(scope, 'foo', list) assert scope == object.__getattribute__(placeholder, '_scope') assert str(placeholder) == str([]) assert scope['foo'] == []
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'], [])
def test__str__(self): scope = {} placehold = demandload.Placeholder(scope, 'foo', list) self.assertEqual({}, scope) self.assertEqual(str(placehold), str([])) self.assertEqual(scope['foo'], [])