Python 3 compat: Fix patcher and hub tests

This commit is contained in:
Jakub Stasiak
2015-02-10 00:09:44 +01:00
parent 2c04b9eff8
commit 50f7940425
2 changed files with 21 additions and 9 deletions

View File

@@ -223,8 +223,19 @@ def monkey_patch(**on):
It's safe to call monkey_patch multiple times.
"""
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)
for k in six.iterkeys(on):
if k not in accepted_args:
raise TypeError("monkey_patch() got an unexpected "
@@ -235,7 +246,7 @@ def monkey_patch(**on):
if modname == 'MySQLdb':
# MySQLdb is only on when explicitly patched for the moment
on.setdefault(modname, False)
if modname == '__builtin__':
if modname == 'builtins':
on.setdefault(modname, False)
on.setdefault(modname, default_on)
@@ -258,9 +269,9 @@ def monkey_patch(**on):
if on.get('MySQLdb') and not already_patched.get('MySQLdb'):
modules_to_patch += _green_MySQLdb()
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()
already_patched['__builtin__'] = True
already_patched['builtins'] = True
if on['psycopg'] and not already_patched.get('psycopg'):
try:
from eventlet.support import psycopg2_patcher
@@ -351,7 +362,7 @@ def _green_MySQLdb():
def _green_builtins():
try:
from eventlet.green import builtin
return [('__builtin__', builtin)]
return [('__builtin__' if six.PY2 else 'builtins', builtin)]
except ImportError:
return []

View File

@@ -298,7 +298,7 @@ class TestFork(LimitedTestCase):
def test_fork(self):
output = tests.run_python('tests/hub_test_fork.py')
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):
@@ -376,8 +376,9 @@ try:
except AttributeError:
pass
import __builtin__
original_import = __builtin__.__import__
from eventlet.support.six.moves import builtins
original_import = builtins.__import__
def fail_import(name, *args, **kwargs):
if 'epoll' in name:
@@ -386,7 +387,7 @@ def fail_import(name, *args, **kwargs):
print('kqueue tried')
return original_import(name, *args, **kwargs)
__builtin__.__import__ = fail_import
builtins.__import__ = fail_import
import eventlet.hubs