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