class LazyImportTestCase(unittest.TestCase): def setUp(self): self.injector = Injector() self.injector.register() def tearDown(self): self.injector.unregister() def testObjProperty(self): '''LazyImport should lazily reference an object.''' self.assertTrue(LazyRef.obj is Ref) def testHashEq(self): '''LazyImport should be equal to the ref object, and has the same hash.''' self.assertEqual(hash(LazyRef), hash(Ref)) self.assertEqual(LazyRef, Ref) def testInjection(self): '''LazyImport in injections.''' class B(object): a = inject.attr(inject.lazy('inject_tests.fixtures.lazy.A')) b = B() from inject_tests.fixtures.lazy import A a = A() self.injector.bind(A, a) self.assertTrue(b.a is a)