153
def test_setattr_replaces(self):
154
"""ScopeReplacer can create an instance in local scope.
156
An object should appear in globals() by constructing a ScopeReplacer,
157
and it will be replaced with the real object upon the first request.
159
def factory(replacer, scope, name):
164
# test_obj6 shouldn't exist yet
167
self.fail('test_obj6 was not supposed to exist yet')
169
orig_globals = set(globals().keys())
171
lazy_import.ScopeReplacer(scope=globals(), name='test_obj6',
174
new_globals = set(globals().keys())
176
# We can't use isinstance() because that uses test_obj6.__class__
177
# and that goes through __getattribute__ which would activate
179
self.assertEqual(lazy_import.ScopeReplacer,
180
object.__getattribute__(test_obj6, '__class__'))
181
test_obj6.bar = 'test'
182
self.assertNotEqual(lazy_import.ScopeReplacer,
183
object.__getattribute__(test_obj6, '__class__'))
184
self.assertEqual('test', test_obj6.bar)
153
186
def test_replace_side_effects(self):
154
187
"""Creating a new object should only create one entry in globals.