Exemplo n.º 1
0
    def test_factory_returned_none(self):
        class Configurer:
            def a(self) -> str:
                return None

        ctx = Pytel(Configurer())
        self.assertRaises(ValueError, lambda: ctx._get('a'))
Exemplo n.º 2
0
    def test_object_not_truthy_is_valid(self):
        def factory() -> int:
            return 0

        self.assertFalse(factory())

        ctx = Pytel({'a': factory})
        self.assertEqual(0, ctx._get('a'))
Exemplo n.º 3
0
    def test_factory_returning_subclass(self):
        class D(A):
            pass

        def factory() -> A:
            return D()

        ctx = Pytel({'a': factory})
        self.assertIsInstance(ctx._get('a'), D)
Exemplo n.º 4
0
    def test_object_not_truthy_is_valid_dependency(self):
        def factory() -> int:
            return 0

        def factory2(a: int) -> B:
            self.assertEqual(0, a)
            return B()

        ctx = Pytel({'a': factory, 'b': factory2})
        self.assertIsInstance(ctx._get('b'), B)
Exemplo n.º 5
0
    def test_factory_returning_subclass_as_dependency(self):
        class D(A):
            pass

        def factory() -> A:
            return D()

        ctx = Pytel({'a': factory, 'c': C})
        c = ctx._get('c')
        self.assertIsInstance(c, C)
        self.assertIsInstance(c.a, D)
Exemplo n.º 6
0
 def test_get_missing_name(self):
     ctx = Pytel([])
     self.assertRaises(KeyError, lambda: ctx._get('a'))