def test_factory_returned_none(self): class Configurer: def a(self) -> str: return None ctx = Pytel(Configurer()) self.assertRaises(ValueError, lambda: ctx._get('a'))
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'))
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)
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)
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)
def test_get_missing_name(self): ctx = Pytel([]) self.assertRaises(KeyError, lambda: ctx._get('a'))