def test_call(self): # Calling a switch_back instance should cause hub.switch() to return # with an (args, kwargs) tuple. hub = gruvi.get_hub() with gruvi.switch_back() as switcher: hub.run_callback(lambda: switcher('foo', bar='baz')) self.assertEqual(hub.switch(), (('foo', ), {'bar': 'baz'}))
def test_call(self): # Calling a switch_back instance should cause hub.switch() to return # with an (args, kwargs) tuple. hub = gruvi.get_hub() with gruvi.switch_back() as switcher: hub.run_callback(lambda: switcher('foo', bar='baz')) self.assertEqual(hub.switch(), (('foo',), {'bar': 'baz'}))
def test_throw(self): # An exception thrown with the throw() method of a switch_back instance # should cause hub.switch to raise that exception. hub = gruvi.get_hub() with gruvi.switch_back() as switcher: hub.run_callback(lambda: switcher.throw(ValueError('foo'))) exc = self.assertRaises(ValueError, hub.switch) self.assertEqual(exc.args[0], 'foo')
def test_many_hubs(self): # Create and close a Hub in many threads. If the hub does not garbage # collect, then this will run out of file descriptors. for i in range(100): hub = gruvi.Hub() with gruvi.switch_back(timeout=0, hub=hub): self.assertRaises(gruvi.Timeout, hub.switch) hub.close() hub.switch() gc.collect()
def mem_switch_back(self): self.add_result(sizeof(gruvi.switch_back(), exclude=('_hub', '_fiber')))
def test_timeout(self): # A timeout in a switch_back instance should cause hub.switch() to # raise a Timeout exception. hub = gruvi.get_hub() with gruvi.switch_back(0.01): self.assertRaises(gruvi.Timeout, hub.switch)