def testGetByContractMulti(self): h = Habitat() svs = h.getAllByContract(IMulti) self.assertEqual(len(svs), 2) self.assertTrue(any([isinstance(s, MultiImpl1) for s in svs])) self.assertTrue(any([isinstance(s, MultiImpl2) for s in svs])) self.assertSetEqual(set((s.foo() for s in svs)), {'foo1', 'foo2'})
def testSimpleBinding(self): pl = FilePluginLoader() pl.setImportRoot(PROJ_DIR) pl.addAllInDir('serializers') pl.addModuleFile('interfaces.py') h = Habitat(pl) serializers = h.getAllByContract(ISerializer) data = map(lambda s: s.serialize(10), serializers) self.assertSetEqual(set(data), {'10', pickle.dumps(10)})
def testGetByContractInjection(self): h = Habitat() svs = h.getAllByContract(IDepends) self.assertEqual(len(svs), 1) self.assertIsInstance(svs[0], DependsImpl) self.assertEqual(svs[0].foo(), 'depends foo')
def testGetByContractSingle(self): h = Habitat() svs = h.getAllByContract(ISingle) self.assertEqual(len(svs), 1) self.assertIsInstance(svs[0], SingleImpl)