예제 #1
0
    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())
예제 #2
0
 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
예제 #3
0
 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
예제 #4
0
 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())
예제 #5
0
 def test_single_level(self):
     with Context(path='/test'):
         self.assertEqual('/test', Context.current().path)
예제 #6
0
 def test_single_level(self):
     with Context(path='/test'):
         self.assertEqual('/test', Context.current().path)