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 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)