def testInlineCallbacks(self):
    """Test context saving across I/O."""
    with thread.locals(someValue = 12345):
      yield time.sleep(0.001)
      self.assertEqual(None, thread.getLocal('anotherValue'))
      self.assertEqual(12345, thread.getLocal('someValue'))

      with thread.locals(anotherValue = 'abcde'):
        yield client.getPage('http://greplin.com')
        self.assertEqual('abcde', thread.getLocal('anotherValue'))
        self.assertEqual(12345, thread.getLocal('someValue'))

      yield threads.deferToThread(lambda: None)
      self.assertEqual(None, thread.getLocal('anotherValue'))
      self.assertEqual(12345, thread.getLocal('someValue'))

    self.assertEqual(None, thread.getLocal('someValue'))
 def testFromDelay(self):
   """Test saving context across a delayed call."""
   with thread.locals(source = 'delay'):
     return time.sleep(0.001).addCallback(lambda _: self.assertEqual('delay', thread.getLocal('source')))
 def testFromThread(self):
   """Test saving context across a thread deferment."""
   with thread.locals(source = 'thread'):
     return threads.deferToThread(lambda: None). \
         addCallback(lambda _: self.assertEqual('thread', thread.getLocal('source')))
 def testFromRequest(self):
   """Test saving context across a socket request."""
   with thread.locals(source = 'page'):
     return client.getPage('http://greplin.com').addCallback(
         lambda _: self.assertEqual('page', thread.getLocal('source')))