Python 3 compat: Fix patcher and hub tests
This commit is contained in:
@@ -223,8 +223,19 @@ def monkey_patch(**on):
|
|||||||
It's safe to call monkey_patch multiple times.
|
It's safe to call monkey_patch multiple times.
|
||||||
"""
|
"""
|
||||||
accepted_args = set(('os', 'select', 'socket',
|
accepted_args = set(('os', 'select', 'socket',
|
||||||
'thread', 'time', 'psycopg', 'MySQLdb', '__builtin__'))
|
'thread', 'time', 'psycopg', 'MySQLdb',
|
||||||
|
'builtins'))
|
||||||
|
# To make sure only one of them is passed here
|
||||||
|
assert not ('__builtin__' in on and 'builtins' in on)
|
||||||
|
try:
|
||||||
|
b = on.pop('__builtin__')
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
on['builtins'] = b
|
||||||
|
|
||||||
default_on = on.pop("all", None)
|
default_on = on.pop("all", None)
|
||||||
|
|
||||||
for k in six.iterkeys(on):
|
for k in six.iterkeys(on):
|
||||||
if k not in accepted_args:
|
if k not in accepted_args:
|
||||||
raise TypeError("monkey_patch() got an unexpected "
|
raise TypeError("monkey_patch() got an unexpected "
|
||||||
@@ -235,7 +246,7 @@ def monkey_patch(**on):
|
|||||||
if modname == 'MySQLdb':
|
if modname == 'MySQLdb':
|
||||||
# MySQLdb is only on when explicitly patched for the moment
|
# MySQLdb is only on when explicitly patched for the moment
|
||||||
on.setdefault(modname, False)
|
on.setdefault(modname, False)
|
||||||
if modname == '__builtin__':
|
if modname == 'builtins':
|
||||||
on.setdefault(modname, False)
|
on.setdefault(modname, False)
|
||||||
on.setdefault(modname, default_on)
|
on.setdefault(modname, default_on)
|
||||||
|
|
||||||
@@ -258,9 +269,9 @@ def monkey_patch(**on):
|
|||||||
if on.get('MySQLdb') and not already_patched.get('MySQLdb'):
|
if on.get('MySQLdb') and not already_patched.get('MySQLdb'):
|
||||||
modules_to_patch += _green_MySQLdb()
|
modules_to_patch += _green_MySQLdb()
|
||||||
already_patched['MySQLdb'] = True
|
already_patched['MySQLdb'] = True
|
||||||
if on.get('__builtin__') and not already_patched.get('__builtin__'):
|
if on.get('builtins') and not already_patched.get('builtins'):
|
||||||
modules_to_patch += _green_builtins()
|
modules_to_patch += _green_builtins()
|
||||||
already_patched['__builtin__'] = True
|
already_patched['builtins'] = True
|
||||||
if on['psycopg'] and not already_patched.get('psycopg'):
|
if on['psycopg'] and not already_patched.get('psycopg'):
|
||||||
try:
|
try:
|
||||||
from eventlet.support import psycopg2_patcher
|
from eventlet.support import psycopg2_patcher
|
||||||
@@ -351,7 +362,7 @@ def _green_MySQLdb():
|
|||||||
def _green_builtins():
|
def _green_builtins():
|
||||||
try:
|
try:
|
||||||
from eventlet.green import builtin
|
from eventlet.green import builtin
|
||||||
return [('__builtin__', builtin)]
|
return [('__builtin__' if six.PY2 else 'builtins', builtin)]
|
||||||
except ImportError:
|
except ImportError:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ class TestFork(LimitedTestCase):
|
|||||||
def test_fork(self):
|
def test_fork(self):
|
||||||
output = tests.run_python('tests/hub_test_fork.py')
|
output = tests.run_python('tests/hub_test_fork.py')
|
||||||
lines = output.splitlines()
|
lines = output.splitlines()
|
||||||
self.assertEqual(lines, ["accept blocked", "child died ok"], output)
|
self.assertEqual(lines, [b"accept blocked", b"child died ok"], output)
|
||||||
|
|
||||||
|
|
||||||
class TestDeadRunLoop(LimitedTestCase):
|
class TestDeadRunLoop(LimitedTestCase):
|
||||||
@@ -376,8 +376,9 @@ try:
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
import __builtin__
|
from eventlet.support.six.moves import builtins
|
||||||
original_import = __builtin__.__import__
|
|
||||||
|
original_import = builtins.__import__
|
||||||
|
|
||||||
def fail_import(name, *args, **kwargs):
|
def fail_import(name, *args, **kwargs):
|
||||||
if 'epoll' in name:
|
if 'epoll' in name:
|
||||||
@@ -386,7 +387,7 @@ def fail_import(name, *args, **kwargs):
|
|||||||
print('kqueue tried')
|
print('kqueue tried')
|
||||||
return original_import(name, *args, **kwargs)
|
return original_import(name, *args, **kwargs)
|
||||||
|
|
||||||
__builtin__.__import__ = fail_import
|
builtins.__import__ = fail_import
|
||||||
|
|
||||||
|
|
||||||
import eventlet.hubs
|
import eventlet.hubs
|
||||||
|
|||||||
Reference in New Issue
Block a user