def test_multi_levels_method(self): class Context1(Context): def a(self): return 1 def b(self): return 2 class Context2(Context): def b(self): return 3 def c(self): return 4 with Context1(): self.assertEqual(1, Context.current().a()) self.assertEqual(2, Context.current().b()) with Context2(): self.assertEqual(1, Context.current().a()) self.assertEqual(3, Context.current().b()) self.assertEqual(4, Context.current().c()) self.assertEqual(1, Context.current().a()) self.assertEqual(2, Context.current().b()) with self.assertRaises(AttributeError): self.assertEqual(3, Context.current().c())
def test_multi_levels(self): with Context(a=1, b=2): self.assertEqual(1, Context.current().a) self.assertEqual(2, Context.current().b) with Context(b=3, c=4): self.assertEqual(1, Context.current().a) self.assertEqual(3, Context.current().b) self.assertEqual(4, Context.current().c) self.assertEqual(1, Context.current().a) self.assertEqual(2, Context.current().b) with self.assertRaises(AttributeError): Context.current().c
def test_single_level(self): with Context(path='/test'): self.assertEqual('/test', Context.current().path)