Commit a268865b authored by Jason Madden's avatar Jason Madden

Stop reading private _exc_info variable. Fixes tests on PyPy.

parent 9c8e01d8
......@@ -36,11 +36,11 @@ cdef class Greenlet(greenlet):
cdef public dict spawn_tree_locals
cdef readonly _Frame spawning_stack
# A test case reads these, otherwise they would
# A test case reads this, otherwise they would
# be private
cdef readonly tuple _exc_info
cdef readonly list _links
cdef object tuple _exc_info
cdef object _notifier
cdef object _start_event
cdef dict _kwargs
......
# A greenlet that's killed before it is ever started
# should never be switched to
import gevent
import greentest
switched_to = [False, False]
class MyException(Exception):
pass
class TestSwitch(greentest.TestCase):
def runner(i):
switched_to[i] = True
def setUp(self):
self.switched_to = [False, False]
self.caught = None
def runner(self, i):
self.switched_to[i] = True
def check(g, g2):
def check(self, g, g2):
gevent.joinall((g, g2))
assert switched_to == [False, False], switched_to
self.assertEqual([False, False], self.switched_to)
# They both have a GreenletExit as their value
assert isinstance(g.value, gevent.GreenletExit)
assert isinstance(g2.value, gevent.GreenletExit)
# They both have no reported exc_info
assert g._exc_info == (None, None, None)
assert g2._exc_info == (None, None, None)
assert g._exc_info is not type(g)._exc_info
assert g2._exc_info is not type(g2)._exc_info
switched_to[:] = [False, False]
g = gevent.spawn(runner, 0) # create but do not switch to
g2 = gevent.spawn(runner, 1) # create but do not switch to
# Using gevent.kill
gevent.kill(g)
gevent.kill(g2)
check(g, g2)
# killing directly
g = gevent.spawn(runner, 0)
g2 = gevent.spawn(runner, 1)
g.kill()
g2.kill()
check(g, g2)
# throwing
g = gevent.spawn(runner, 0)
g2 = gevent.spawn(runner, 1)
g.throw(gevent.GreenletExit)
g2.throw(gevent.GreenletExit)
check(g, g2)
# Killing with gevent.kill gets the right exception
class MyException(Exception):
pass
self.assertIsInstance(g.value, gevent.GreenletExit)
self.assertIsInstance(g2.value, gevent.GreenletExit)
def catcher():
# They both have no reported exc_info
self.assertIsNone(g.exc_info)
self.assertIsNone(g2.exc_info)
self.assertIsNone(g.exception)
self.assertIsNone(g2.exception)
def test_gevent_kill(self):
g = gevent.spawn(self.runner, 0) # create but do not switch to
g2 = gevent.spawn(self.runner, 1) # create but do not switch to
# Using gevent.kill
gevent.kill(g)
gevent.kill(g2)
self.check(g, g2)
def test_greenlet_kill(self):
# killing directly
g = gevent.spawn(self.runner, 0)
g2 = gevent.spawn(self.runner, 1)
g.kill()
g2.kill()
self.check(g, g2)
def test_throw(self):
# throwing
g = gevent.spawn(self.runner, 0)
g2 = gevent.spawn(self.runner, 1)
g.throw(gevent.GreenletExit)
g2.throw(gevent.GreenletExit)
self.check(g, g2)
def catcher(self):
try:
while True:
gevent.sleep(0)
except Exception as e:
switched_to[0] = e
except MyException as e:
self.caught = e
def test_kill_exception(self):
# Killing with gevent.kill gets the right exception
g = gevent.spawn(self.catcher)
g.start()
gevent.sleep()
gevent.kill(g, MyException())
gevent.sleep()
self.assertIsInstance(self.caught, MyException)
self.assertIsNone(g.exception, MyException)
g = gevent.spawn(catcher)
g.start()
gevent.sleep()
gevent.kill(g, MyException())
gevent.sleep()
assert isinstance(switched_to[0], MyException), switched_to
if __name__ == '__main__':
greentest.main()
......@@ -13,3 +13,4 @@ test__socket_errors.py
test__socket_send_memoryview.py
test__socket_timeout.py
test__examples.py
test__issue330.py
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment