summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFree Ekanayaka <free@ekanayaka.io>2016-11-26 16:53:28 +0000
committerFree Ekanayaka <free@ekanayaka.io>2016-11-26 16:53:28 +0000
commit61baa3e0f6eaf9ff103b0071b9cecc35a1ff20e0 (patch)
tree7c414c8da078347522b0fa3aedae42fc915ec4f3
parentbfc88a45a3d94b4b030f9210471b2f700d294f15 (diff)
downloadtesttools-remove-test-dependency-on-twisted-13.tar.gz
Make twistedsupport and tests work on Python 3remove-test-dependency-on-twisted-13
-rw-r--r--.travis.yml14
-rw-r--r--testtools/tests/twistedsupport/test_spinner.py6
-rw-r--r--testtools/twistedsupport/_spinner.py36
3 files changed, 35 insertions, 21 deletions
diff --git a/.travis.yml b/.travis.yml
index 6b26826..190a176 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,21 +7,9 @@ python:
- "3.5"
- "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:
- pip install -U pip wheel setuptools
- - pip install sphinx $TWISTED_REQ
+ - pip install sphinx Twisted
- pip install .[test]
script:
diff --git a/testtools/tests/twistedsupport/test_spinner.py b/testtools/tests/twistedsupport/test_spinner.py
index 62ace9f..d2b30f2 100644
--- a/testtools/tests/twistedsupport/test_spinner.py
+++ b/testtools/tests/twistedsupport/test_spinner.py
@@ -137,8 +137,8 @@ class TestRunInReactor(NeedsTwistedTestCase):
def test_preserve_signal_handler(self):
signals = ['SIGINT', 'SIGTERM', 'SIGCHLD']
- signals = filter(
- None, (getattr(signal, name, None) for name in signals))
+ signals = list(filter(
+ None, (getattr(signal, name, None) for name in signals)))
for sig in signals:
self.addCleanup(signal.signal, sig, signal.getsignal(sig))
new_hdlrs = list(lambda *a: None for _ in signals)
@@ -146,7 +146,7 @@ class TestRunInReactor(NeedsTwistedTestCase):
signal.signal(sig, hdlr)
spinner = self.make_spinner()
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):
# If the function takes too long to run, we raise a
diff --git a/testtools/twistedsupport/_spinner.py b/testtools/twistedsupport/_spinner.py
index 0bf05aa..197f756 100644
--- a/testtools/twistedsupport/_spinner.py
+++ b/testtools/twistedsupport/_spinner.py
@@ -19,6 +19,8 @@ __all__ = [
from fixtures import Fixture
import signal
+import six
+
from ._deferreddebug import DebugTwisted
from twisted.internet import defer
@@ -68,10 +70,31 @@ def trap_unhandled_errors(function, *args, **kwargs):
"""
real_DebugInfo = defer.DebugInfo
debug_infos = []
- def DebugInfo():
- info = real_DebugInfo()
- debug_infos.append(info)
- return info
+
+ # 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():
+ info = real_DebugInfo()
+ debug_infos.append(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
try:
result = function(*args, **kwargs)
@@ -83,7 +106,10 @@ def trap_unhandled_errors(function, *args, **kwargs):
errors.append(info)
# Disable the destructor that logs to error. We are already
# catching the error here.
- info.__del__ = lambda: None
+ if six.PY2:
+ info.__del__ = lambda: None
+ else:
+ info._runRealDel = False
return result, errors