Exemplo n.º 1
0
    def test_callable_returns_none(self):
        def returns_none() -> str:
            return None

        descr = ObjectDescriptor.from_callable('a', returns_none)
        descr.resolve_dependencies(None, contextlib.ExitStack())
        self.assertRaises(ValueError, lambda: descr.instance)
Exemplo n.º 2
0
 def test_eq(self):
     descr1 = ObjectDescriptor.from_object('a', "str")
     descr2 = ObjectDescriptor.from_object('a', "str")
     self.assertTrue(descr1 == descr2)
Exemplo n.º 3
0
 def test_eq_not_implemented(self):
     descr = ObjectDescriptor.from_object('a', "str")
     self.assertFalse(descr == 1)
Exemplo n.º 4
0
 def test_from_callable_none(self):
     self.assertRaises(AssertionError,
                       lambda: ObjectDescriptor.from_callable('a', None))
Exemplo n.º 5
0
 def test_repr(self):
     descr = ObjectDescriptor.from_object('a', "value")
     self.assertEqual(str(descr), '<ObjectDescriptor> a: str')
Exemplo n.º 6
0
 def test_from_with_object(self):
     with mock.patch('pytel.context.ObjectDescriptor.from_object') as m:
         ObjectDescriptor.from_('a', "str")
         m.was_called_once_with("str")
Exemplo n.º 7
0
 def test_from_object(self):
     descr = ObjectDescriptor.from_object('a', "str")
     self.assertEqual(ObjectDescriptor(None, 'a', str, {}), descr)
Exemplo n.º 8
0
 def test_from_with_callable(self):
     with mock.patch('pytel.context.ObjectDescriptor.from_callable') as m:
         ObjectDescriptor.from_('a', ''.capitalize)
         m.was_called_once_with(str.capitalize)
Exemplo n.º 9
0
 def test_from_with_type(self):
     with mock.patch('pytel.context.ObjectDescriptor.from_callable') as m:
         ObjectDescriptor.from_('a', str)
         m.was_called_once_with(str)
Exemplo n.º 10
0
    def test_from_callable_param_with_type(self):
        def a(b: str) -> str:
            pass

        descr = ObjectDescriptor.from_('b', a)
        self.assertEqual(str, descr.dependencies['b'])
Exemplo n.º 11
0
 def test_from_with_none(self):
     self.assertRaises(ValueError,
                       lambda: ObjectDescriptor.from_('a', None))
Exemplo n.º 12
0
    def test_from_callable_params_no_type(self):
        def a(b) -> str:
            pass

        self.assertRaises(TypeError, lambda: ObjectDescriptor.from_('a', a))
Exemplo n.º 13
0
    def test_from_callable_type(self):
        def a() -> str:
            pass

        descr = ObjectDescriptor.from_('a', a)
        self.assertEqual(str, descr.object_type)
Exemplo n.º 14
0
    def test_from_callable_type_none(self):
        def factory() -> None:
            pass

        self.assertRaises(TypeError,
                          lambda: ObjectDescriptor.from_('a', factory))
Exemplo n.º 15
0
 def test_items(self):
     ctx = Pytel({'a': A})
     self.assertEqual({'a': ObjectDescriptor.from_callable('a', A)}, dict(ctx.items()))
Exemplo n.º 16
0
 def test_init(self):
     ctx = {'a': A}
     p = Pytel(ctx)
     self.assertEqual({'a': ObjectDescriptor.from_callable('a', A)}, p._objects)
     self.assertIsInstance(p._exit_stack, contextlib.ExitStack)