def testContextManager(self):
     '''RequestScope should support the context manager protocol.'''
     s = RequestScope()
     self.assertRaises(NoRequestError, s.get, A)
     
     with s:
         a = A()
         s.bind(A, a)
         self.assertTrue(s.get(A) is a)
     
     self.assertRaises(NoRequestError, s.get, A)
     
     with s:
         self.assertTrue(s.get(A) is None)
    def testContextManager(self):
        '''RequestScope should support the context manager protocol.'''
        s = RequestScope()
        self.assertRaises(NoRequestError, s.get, A)

        with s:
            a = A()
            s.bind(A, a)
            self.assertTrue(s.get(A) is a)

        self.assertRaises(NoRequestError, s.get, A)

        with s:
            self.assertTrue(s.get(A) is None)
 def testRequestLocalAndFactories(self):
     s = RequestScope()
     s.start()
     
     s.bind_factory(A, A)
     self.assertTrue(s.is_factory_bound(A))
     self.assertFalse(s.is_bound(A))
     
     a = s.get(A)
     self.assertTrue(s.is_bound(A))
     
     s.end()
     self.assertTrue(s.is_factory_bound(A))
     self.assertFalse(s.is_bound(A))
     
     s.start()
     a2 = s.get(A)
     self.assertFalse(a2 is a)
     s.end()
    def testRequestLocalAndFactories(self):
        s = RequestScope()
        s.start()

        s.bind_factory(A, A)
        self.assertTrue(s.is_factory_bound(A))
        self.assertFalse(s.is_bound(A))

        a = s.get(A)
        self.assertTrue(s.is_bound(A))

        s.end()
        self.assertTrue(s.is_factory_bound(A))
        self.assertFalse(s.is_bound(A))

        s.start()
        a2 = s.get(A)
        self.assertFalse(a2 is a)
        s.end()
 def testRequestLocal(self):
     s = RequestScope()
     s.start()
     
     self.assertFalse(s.is_bound(A))
     a = A()
     s.bind(A, a)
     self.assertTrue(s.get(A) is a)
     
     def run():
         a2 = A()
         s.start()
         self.assertFalse(s.is_bound(A))
         s.bind(A, a2)
         self.assertTrue(s.get(A) is a2)
     
     thread = threading.Thread(target=run)
     thread.start()
     thread.join()
     
     self.assertTrue(s.is_bound(A))
     self.assertTrue(s.get(A) is a)
    def testRequestLocal(self):
        s = RequestScope()
        s.start()

        self.assertFalse(s.is_bound(A))
        a = A()
        s.bind(A, a)
        self.assertTrue(s.get(A) is a)

        def run():
            a2 = A()
            s.start()
            self.assertFalse(s.is_bound(A))
            s.bind(A, a2)
            self.assertTrue(s.get(A) is a2)

        thread = threading.Thread(target=run)
        thread.start()
        thread.join()

        self.assertTrue(s.is_bound(A))
        self.assertTrue(s.get(A) is a)