Пример #1
0
 def test_remove_provider(self):
     ij = Injector()
     ij.add_value('val', 5)
     ij.remove('val')
     def test(val): pass
     with self.assertRaises(InjectError):
         ij.call_inject(test)
Пример #2
0
    def test_remove_provider(self):
        ij = Injector()
        ij.add_value('val', 5)
        ij.remove('val')

        def test(val):
            pass

        with self.assertRaises(InjectError):
            ij.call_inject(test)
Пример #3
0
 def test_inject_value(self):
     ij = Injector()
     value = []
     ij.add_value('val', value)
     def test(val, other=inject('val')):
         self.assertTrue(val is other)
         self.assertTrue(val is value)
         val.append(5)
     ij.call_inject(test)
     self.assertEqual([5], value)
Пример #4
0
    def test_inject_value(self):
        ij = Injector()
        value = []
        ij.add_value('val', value)

        def test(val, other=inject('val')):
            self.assertTrue(val is other)
            self.assertTrue(val is value)
            val.append(5)

        ij.call_inject(test)
        self.assertEqual([5], value)
Пример #5
0
    def test_wrap_decorator(self):
        ij = Injector()

        @ij.wrap
        def test(a):
            return a

        with self.assertRaises(InjectError):
            test()

        ij.add_value('a', 5)
        self.assertEquals(5, test())
        self.assertEquals(6, test(a=6))
Пример #6
0
    def test_wrap_decorator(self):
        ij = Injector()

        @ij.wrap
        def test(a):
            return a

        with self.assertRaises(InjectError):
            test()

        ij.add_value('a', 5)
        self.assertEquals(5, test())
        self.assertEquals(6, test(a=6))