Commit 29e42097 authored by Jason Madden's avatar Jason Madden

Fix test__backdoor and backdoor undor Py36.

Also stop wrapping methods over and over. Yikes.
parent 117239ff
......@@ -134,7 +134,12 @@ class BackdoorServer(StreamServer):
getcurrent().switch_in()
try:
console = InteractiveConsole(self._create_interactive_locals())
console.interact(banner=self.banner)
if sys.version_info[:3] >= (3, 6, 0):
# Beginning in 3.6, the console likes to print "now exiting <class>"
# but probably our socket is already closed, so this just causes problems.
console.interact(banner=self.banner, exitmsg='')
else:
console.interact(banner=self.banner)
except SystemExit: # raised by quit()
if hasattr(sys, 'exc_clear'): # py2
sys.exc_clear()
......
......@@ -117,7 +117,7 @@ class ExpectedException(Exception):
def wrap_switch_count_check(method):
@wraps(method)
def wrapped(self, *args, **kwargs):
def wrap_switch_count_check(self, *args, **kwargs):
initial_switch_count = getattr(_get_hub(), 'switch_count', None)
self.switch_expected = getattr(self, 'switch_expected', True)
if initial_switch_count is not None:
......@@ -137,7 +137,7 @@ def wrap_switch_count_check(method):
else:
raise AssertionError('Invalid value for switch_expected: %r' % (self.switch_expected, ))
return result
return wrapped
return wrap_switch_count_check
def wrap_timeout(timeout, method):
......@@ -145,11 +145,11 @@ def wrap_timeout(timeout, method):
return method
@wraps(method)
def wrapped(self, *args, **kwargs):
def wrap_timeout(self, *args, **kwargs):
with gevent.Timeout(timeout, 'test timed out', ref=False):
return method(self, *args, **kwargs)
return wrapped
return wrap_timeout
def ignores_leakcheck(func):
func.ignore_leakcheck = True
......@@ -193,7 +193,7 @@ def wrap_refcount(method):
return diff
@wraps(method)
def wrapped(self, *args, **kwargs):
def wrap_refcount(self, *args, **kwargs):
gc.collect()
gc.collect()
gc.collect()
......@@ -253,12 +253,12 @@ def wrap_refcount(method):
gc.enable()
self.skipTearDown = True
return wrapped
return wrap_refcount
def wrap_error_fatal(method):
@wraps(method)
def wrapped(self, *args, **kwargs):
def wrap_error_fatal(self, *args, **kwargs):
# XXX should also be able to do gevent.SYSTEM_ERROR = object
# which is a global default to all hubs
SYSTEM_ERROR = gevent.get_hub().SYSTEM_ERROR
......@@ -267,12 +267,12 @@ def wrap_error_fatal(method):
return method(self, *args, **kwargs)
finally:
gevent.get_hub().SYSTEM_ERROR = SYSTEM_ERROR
return wrapped
return wrap_error_fatal
def wrap_restore_handle_error(method):
@wraps(method)
def wrapped(self, *args, **kwargs):
def wrap_restore_handle_error(self, *args, **kwargs):
old = gevent.get_hub().handle_error
try:
return method(self, *args, **kwargs)
......@@ -280,7 +280,7 @@ def wrap_restore_handle_error(method):
gevent.get_hub().handle_error = old
if self.peek_error()[0] is not None:
gevent.getcurrent().throw(*self.peek_error()[1:])
return wrapped
return wrap_restore_handle_error
def _get_class_attr(classDict, bases, attr, default=AttributeError):
......@@ -315,7 +315,7 @@ class TestCaseMetaClass(type):
timeout *= 6
check_totalrefcount = _get_class_attr(classDict, bases, 'check_totalrefcount', True)
error_fatal = _get_class_attr(classDict, bases, 'error_fatal', True)
for key, value in classDict.items():
for key, value in list(classDict.items()): # Python 3: must copy, we mutate
if key.startswith('test') and callable(value):
classDict.pop(key)
#value = wrap_switch_count_check(value)
......
......@@ -58,6 +58,7 @@ class Test(greentest.TestCase):
def test_quit(self):
server = backdoor.BackdoorServer(('127.0.0.1', 0))
server.start()
conn = None
try:
conn = create_connection(('127.0.0.1', server.server_port))
read_until(conn, '>>> ')
......@@ -65,12 +66,14 @@ class Test(greentest.TestCase):
line = readline(conn)
self.assertEqual(line, '')
finally:
conn.close()
if conn is not None:
conn.close()
server.stop()
def test_sys_exit(self):
server = backdoor.BackdoorServer(('127.0.0.1', 0))
server.start()
conn = None
try:
conn = create_connection(('127.0.0.1', server.server_port))
read_until(conn, b'>>> ')
......@@ -78,7 +81,8 @@ class Test(greentest.TestCase):
line = readline(conn)
self.assertEqual(line, '')
finally:
conn.close()
if conn is not None:
conn.close()
server.stop()
def test_banner(self):
......@@ -96,6 +100,7 @@ class Test(greentest.TestCase):
def test_builtins(self):
server = backdoor.BackdoorServer(('127.0.0.1', 0))
server.start()
conn = None
try:
conn = create_connection(('127.0.0.1', server.server_port))
read_until(conn, b'>>> ')
......@@ -103,7 +108,8 @@ class Test(greentest.TestCase):
response = read_until(conn, '>>> ')
self.assertTrue(len(response) < 300, msg="locals() unusable: %s..." % response)
finally:
conn.close()
if conn is not None:
conn.close()
server.stop()
......
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