Make twistedsupport and tests work on Python 3
This commit is contained in:
14
.travis.yml
14
.travis.yml
@@ -7,21 +7,9 @@ python:
|
|||||||
- "3.5"
|
- "3.5"
|
||||||
- "pypy"
|
- "pypy"
|
||||||
|
|
||||||
# Twisted tests currently only work on Python 2.
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- python: "2.7"
|
|
||||||
env: TWISTED_REQ="Twisted==13.0.0"
|
|
||||||
- python: "2.7"
|
|
||||||
env: TWISTED_REQ="Twisted"
|
|
||||||
- python: "pypy"
|
|
||||||
env: TWISTED_REQ="Twisted==13.0.0"
|
|
||||||
- python: "pypy"
|
|
||||||
env: TWISTED_REQ="Twisted"
|
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- pip install -U pip wheel setuptools
|
- pip install -U pip wheel setuptools
|
||||||
- pip install sphinx $TWISTED_REQ
|
- pip install sphinx Twisted
|
||||||
- pip install .[test]
|
- pip install .[test]
|
||||||
|
|
||||||
script:
|
script:
|
||||||
|
|||||||
@@ -137,8 +137,8 @@ class TestRunInReactor(NeedsTwistedTestCase):
|
|||||||
|
|
||||||
def test_preserve_signal_handler(self):
|
def test_preserve_signal_handler(self):
|
||||||
signals = ['SIGINT', 'SIGTERM', 'SIGCHLD']
|
signals = ['SIGINT', 'SIGTERM', 'SIGCHLD']
|
||||||
signals = filter(
|
signals = list(filter(
|
||||||
None, (getattr(signal, name, None) for name in signals))
|
None, (getattr(signal, name, None) for name in signals)))
|
||||||
for sig in signals:
|
for sig in signals:
|
||||||
self.addCleanup(signal.signal, sig, signal.getsignal(sig))
|
self.addCleanup(signal.signal, sig, signal.getsignal(sig))
|
||||||
new_hdlrs = list(lambda *a: None for _ in signals)
|
new_hdlrs = list(lambda *a: None for _ in signals)
|
||||||
@@ -146,7 +146,7 @@ class TestRunInReactor(NeedsTwistedTestCase):
|
|||||||
signal.signal(sig, hdlr)
|
signal.signal(sig, hdlr)
|
||||||
spinner = self.make_spinner()
|
spinner = self.make_spinner()
|
||||||
spinner.run(self.make_timeout(), lambda: None)
|
spinner.run(self.make_timeout(), lambda: None)
|
||||||
self.assertEqual(new_hdlrs, map(signal.getsignal, signals))
|
self.assertItemsEqual(new_hdlrs, list(map(signal.getsignal, signals)))
|
||||||
|
|
||||||
def test_timeout(self):
|
def test_timeout(self):
|
||||||
# If the function takes too long to run, we raise a
|
# If the function takes too long to run, we raise a
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ __all__ = [
|
|||||||
from fixtures import Fixture
|
from fixtures import Fixture
|
||||||
import signal
|
import signal
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
from ._deferreddebug import DebugTwisted
|
from ._deferreddebug import DebugTwisted
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
@@ -68,10 +70,31 @@ def trap_unhandled_errors(function, *args, **kwargs):
|
|||||||
"""
|
"""
|
||||||
real_DebugInfo = defer.DebugInfo
|
real_DebugInfo = defer.DebugInfo
|
||||||
debug_infos = []
|
debug_infos = []
|
||||||
|
|
||||||
|
# Apparently the fact that Twisted now decorates DebugInfo with @_oldStyle
|
||||||
|
# screws up things a bit for us here: monkey patching the __del__ method on
|
||||||
|
# an instance doesn't work with Python 3 and viceversa overriding __del__
|
||||||
|
# via inheritance doesn't work with Python 2. So we handle the two cases
|
||||||
|
# differently. TODO: perhaps there's a way to have a single code path?
|
||||||
|
if six.PY2:
|
||||||
def DebugInfo():
|
def DebugInfo():
|
||||||
info = real_DebugInfo()
|
info = real_DebugInfo()
|
||||||
debug_infos.append(info)
|
debug_infos.append(info)
|
||||||
return info
|
return info
|
||||||
|
else:
|
||||||
|
|
||||||
|
class DebugInfo(real_DebugInfo):
|
||||||
|
|
||||||
|
_runRealDel = True
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
real_DebugInfo.__init__(self)
|
||||||
|
debug_infos.append(self)
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
if self._runRealDel:
|
||||||
|
real_DebugInfo.__del__(self)
|
||||||
|
|
||||||
defer.DebugInfo = DebugInfo
|
defer.DebugInfo = DebugInfo
|
||||||
try:
|
try:
|
||||||
result = function(*args, **kwargs)
|
result = function(*args, **kwargs)
|
||||||
@@ -83,7 +106,10 @@ def trap_unhandled_errors(function, *args, **kwargs):
|
|||||||
errors.append(info)
|
errors.append(info)
|
||||||
# Disable the destructor that logs to error. We are already
|
# Disable the destructor that logs to error. We are already
|
||||||
# catching the error here.
|
# catching the error here.
|
||||||
|
if six.PY2:
|
||||||
info.__del__ = lambda: None
|
info.__del__ = lambda: None
|
||||||
|
else:
|
||||||
|
info._runRealDel = False
|
||||||
return result, errors
|
return result, errors
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user