예제 #1
0
 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'})
예제 #2
0
    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)})
예제 #3
0
 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')
예제 #4
0
 def testGetByContractSingle(self):
     h = Habitat()
     svs = h.getAllByContract(ISingle)
     self.assertEqual(len(svs), 1)
     self.assertIsInstance(svs[0], SingleImpl)