[Python-modules-commits] [txfixtures] 01/03: New upstream version 0.2.7

Free Ekanayaka freee at moszumanska.debian.org
Thu Feb 2 09:42:19 UTC 2017


This is an automated email from the git hooks/post-receive script.

freee pushed a commit to branch master
in repository txfixtures.

commit ccee206f47152870ed49ddc03058a8c422abba2d
Author: Free Ekanayaka <freee at debian.org>
Date:   Thu Feb 2 09:18:15 2017 +0000

    New upstream version 0.2.7
---
 ChangeLog                                 |  5 ++++
 Makefile                                  |  2 +-
 PKG-INFO                                  |  2 +-
 setup.cfg                                 |  2 +-
 tests/test_phantomjs.py                   |  7 +++++
 tests/test_service.py                     |  5 ++--
 txfixtures.egg-info/PKG-INFO              |  2 +-
 txfixtures.egg-info/SOURCES.txt           |  3 +++
 txfixtures.egg-info/pbr.json              |  2 +-
 txfixtures/_twisted/__init__.py           |  1 +
 txfixtures/_twisted/backports/__init__.py |  1 +
 txfixtures/_twisted/backports/defer.py    | 45 +++++++++++++++++++++++++++++++
 txfixtures/_twisted/backports/testing.py  | 42 +++++++++++++++++++++++++++++
 txfixtures/_twisted/testing.py            |  2 ++
 txfixtures/_twisted/threading.py          |  2 +-
 txfixtures/service.py                     |  5 +++-
 16 files changed, 119 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7b8858f..bc691a8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,11 @@
 CHANGES
 =======
 
+0.2.7
+-----
+
+* Make the code compatible with Twisted 16.0.0 (#4)
+
 0.2.6
 -----
 
diff --git a/Makefile b/Makefile
index 95f965c..9c5edeb 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ PYTHON ?= python
 COVERAGE ?= $(PYTHON)-coverage
 
 SOURCE = txfixtures
-OMIT = $(SOURCE)/osutils.py,$(SOURCE)/tachandler.py
+OMIT = $(SOURCE)/osutils.py,$(SOURCE)/tachandler.py,$(SOURCE)/_twisted/backports/*.py
 
 check:
 	rm -f .coverage
diff --git a/PKG-INFO b/PKG-INFO
index f7249c2..d5d1cd6 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: txfixtures
-Version: 0.2.6
+Version: 0.2.7
 Summary: Treat Twisted applications as Python test fixtures
 Home-page: https://launchpad.net/txfixtures
 Author: Martin Pool
diff --git a/setup.cfg b/setup.cfg
index ddf50f7..9548f8b 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -32,7 +32,7 @@ mongodb =
 universal = 1
 
 [egg_info]
+tag_date = 0
 tag_svn_revision = 0
 tag_build = 
-tag_date = 0
 
diff --git a/tests/test_phantomjs.py b/tests/test_phantomjs.py
index eb4f864..64b6233 100644
--- a/tests/test_phantomjs.py
+++ b/tests/test_phantomjs.py
@@ -1,11 +1,17 @@
+from unittest import skipIf
+
 from testtools import TestCase
 
 from fixtures import FakeLogger
 
+from twisted import version as twistedVersion
+
 from txfixtures.reactor import Reactor
 from txfixtures.service import Service
 from txfixtures.phantomjs import PhantomJS
 
+hasTwist = (twistedVersion.major, twistedVersion.minor) >= (16, 5)
+
 
 class PhantomJSIntegrationTest(TestCase):
 
@@ -22,6 +28,7 @@ class PhantomJSIntegrationTest(TestCase):
 
         self.fixture = PhantomJS(timeout=5)
 
+    @skipIf(not hasTwist, "twist executable not available")
     def test_webdriver(self):
         """After setUp is run, the service is fully ready."""
         self.useFixture(self.fixture)
diff --git a/tests/test_service.py b/tests/test_service.py
index ea0d78b..7780790 100644
--- a/tests/test_service.py
+++ b/tests/test_service.py
@@ -23,6 +23,7 @@ from twisted.internet.error import (
     ProcessDone,
 )
 
+from txfixtures._twisted.backports.defer import addTimeout
 from txfixtures.reactor import Reactor
 from txfixtures.service import (
     Service,
@@ -193,7 +194,7 @@ class ServiceProtocolIntegrationTest(TestCase):
         """
         self.script.sleep(1)
         self.protocol.expectedOutput = "hello"
-        self.protocol.ready.addTimeout(0.2, reactor)
+        addTimeout(self.protocol.ready, 0.2, reactor)
         self.process = reactor.spawnProcess(self.protocol, self.script.path)
         try:
             yield self.protocol.ready
@@ -218,7 +219,7 @@ class ServiceProtocolIntegrationTest(TestCase):
         self.addCleanup(sock.close)
         _, self.protocol.expectedPort = sock.getsockname()
 
-        self.protocol.ready.addTimeout(0.2, reactor)
+        addTimeout(self.protocol.ready, 0.2, reactor)
         self.process = reactor.spawnProcess(self.protocol, self.script.path)
         try:
             yield self.protocol.ready
diff --git a/txfixtures.egg-info/PKG-INFO b/txfixtures.egg-info/PKG-INFO
index f7249c2..d5d1cd6 100644
--- a/txfixtures.egg-info/PKG-INFO
+++ b/txfixtures.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: txfixtures
-Version: 0.2.6
+Version: 0.2.7
 Summary: Treat Twisted applications as Python test fixtures
 Home-page: https://launchpad.net/txfixtures
 Author: Martin Pool
diff --git a/txfixtures.egg-info/SOURCES.txt b/txfixtures.egg-info/SOURCES.txt
index 2f2393b..363fbe5 100644
--- a/txfixtures.egg-info/SOURCES.txt
+++ b/txfixtures.egg-info/SOURCES.txt
@@ -39,6 +39,9 @@ txfixtures.egg-info/top_level.txt
 txfixtures/_twisted/__init__.py
 txfixtures/_twisted/testing.py
 txfixtures/_twisted/threading.py
+txfixtures/_twisted/backports/__init__.py
+txfixtures/_twisted/backports/defer.py
+txfixtures/_twisted/backports/testing.py
 txfixtures/_twisted/tests/__init__.py
 txfixtures/_twisted/tests/test_threading.py
 txfixtures/tests/__init__.py
diff --git a/txfixtures.egg-info/pbr.json b/txfixtures.egg-info/pbr.json
index fe49564..72802ae 100644
--- a/txfixtures.egg-info/pbr.json
+++ b/txfixtures.egg-info/pbr.json
@@ -1 +1 @@
-{"is_release": true, "git_version": "b0215e4"}
\ No newline at end of file
+{"git_version": "9ee4d6a", "is_release": true}
\ No newline at end of file
diff --git a/txfixtures/_twisted/__init__.py b/txfixtures/_twisted/__init__.py
index e69de29..8b13789 100644
--- a/txfixtures/_twisted/__init__.py
+++ b/txfixtures/_twisted/__init__.py
@@ -0,0 +1 @@
+
diff --git a/txfixtures/_twisted/backports/__init__.py b/txfixtures/_twisted/backports/__init__.py
new file mode 100644
index 0000000..728683e
--- /dev/null
+++ b/txfixtures/_twisted/backports/__init__.py
@@ -0,0 +1 @@
+"""Backports of Twisted's stock code."""
diff --git a/txfixtures/_twisted/backports/defer.py b/txfixtures/_twisted/backports/defer.py
new file mode 100644
index 0000000..172cb76
--- /dev/null
+++ b/txfixtures/_twisted/backports/defer.py
@@ -0,0 +1,45 @@
+from twisted.python import failure
+from twisted.internet.defer import CancelledError, TimeoutError
+
+
+def addTimeout(deferred, timeout, clock, onTimeoutCancel=None):
+    """Backport of Deferred.addTimeout, which is only available on >=16.5."""
+
+    # Use the stock addTimeout if available
+    if hasattr(deferred, "addTimeout"):
+        return deferred.addTimeout(
+            timeout, clock, onTimeoutCancel=onTimeoutCancel)
+
+    timedOut = [False]
+
+    def timeItOut():
+        timedOut[0] = True
+        deferred.cancel()
+
+    delayedCall = clock.callLater(timeout, timeItOut)
+
+    def convertCancelled(value):
+        # if C{deferred} was timed out, call the translation function,
+        # if provdied, otherwise just use L{cancelledToTimedOutError}
+        if timedOut[0]:
+            toCall = onTimeoutCancel or _cancelledToTimedOutError
+            return toCall(value, timeout)
+        return value
+
+    deferred.addBoth(convertCancelled)
+
+    def cancelTimeout(result):
+        # stop the pending call to cancel the deferred if it's been fired
+        if delayedCall.active():
+            delayedCall.cancel()
+        return result
+
+    deferred.addBoth(cancelTimeout)
+    return deferred
+
+
+def _cancelledToTimedOutError(value, timeout):
+    if isinstance(value, failure.Failure):
+        value.trap(CancelledError)
+        raise TimeoutError(timeout, "Deferred")
+    return value
diff --git a/txfixtures/_twisted/backports/testing.py b/txfixtures/_twisted/backports/testing.py
new file mode 100644
index 0000000..34e8b48
--- /dev/null
+++ b/txfixtures/_twisted/backports/testing.py
@@ -0,0 +1,42 @@
+from twisted import version
+from twisted.test.proto_helpers import MemoryReactorClock
+
+
+class MemoryReactorClock16_5(MemoryReactorClock):
+
+    def __init__(self):
+        super(MemoryReactorClock16_5, self).__init__()
+        self.running = False
+        self.hasRun = False
+        self.triggers = {}
+        self.whenRunningHooks = []
+
+    def run(self):
+        assert self.running is False
+        self.running = True
+        self.hasRun = True
+
+        for f, args, kwargs in self.whenRunningHooks:
+            f(*args, **kwargs)
+
+        self.stop()
+
+    def crash(self):
+        self.running = None
+        self.hasCrashed = True
+
+    def stop(self):
+        self.running = False
+        self.hasStopped = True
+
+    def addSystemEventTrigger(self, phase, eventType, callable, *args, **kw):
+        phaseTriggers = self.triggers.setdefault(phase, {})
+        eventTypeTriggers = phaseTriggers.setdefault(eventType, [])
+        eventTypeTriggers.append((callable, args, kw))
+
+    def callWhenRunning(self, callable, *args, **kw):
+        self.whenRunningHooks.append((callable, args, kw))
+
+
+if (version.major, version.minor) < (16, 5):
+    MemoryReactorClock = MemoryReactorClock16_5
diff --git a/txfixtures/_twisted/testing.py b/txfixtures/_twisted/testing.py
index 06756ee..bf36910 100644
--- a/txfixtures/_twisted/testing.py
+++ b/txfixtures/_twisted/testing.py
@@ -7,6 +7,8 @@ from twisted.internet.error import ProcessTerminated
 from twisted.internet._baseprocess import BaseProcess
 from twisted.python.failure import Failure
 
+from txfixtures._twisted.backports.testing import MemoryReactorClock
+
 EXPECTED_SIGNALS = (signal.SIGTERM, signal.SIGTERM)
 
 
diff --git a/txfixtures/_twisted/threading.py b/txfixtures/_twisted/threading.py
index def3801..18d2e1b 100644
--- a/txfixtures/_twisted/threading.py
+++ b/txfixtures/_twisted/threading.py
@@ -1,4 +1,4 @@
-"""Extensions to stock Twisted code."""
+"""Extensions to Twisted's stock threading code."""
 
 from six.moves.queue import (
     Queue,
diff --git a/txfixtures/service.py b/txfixtures/service.py
index 44734b1..f716c56 100644
--- a/txfixtures/service.py
+++ b/txfixtures/service.py
@@ -30,6 +30,7 @@ from twisted.internet.error import (
 from twisted.protocols.basic import LineOnlyReceiver
 
 from txfixtures._twisted.threading import interruptableCallFromThread
+from txfixtures._twisted.backports.defer import addTimeout
 
 
 TIMEOUT = 15
@@ -231,7 +232,9 @@ class ServiceProtocol(ProcessProtocol):
 
         logging.info("Service process spawned")
 
-        self.ready.addTimeout(self.timeout, self.reactor)
+        # XXX Replace with self.ready.addTimeout once support for Twisted<16.5
+        #     gets dropped.
+        addTimeout(self.ready, self.timeout, self.reactor)
 
         # The twisted.protocols.basic.LineOnlyReceiver class expects to know
         # when the transport is disconnecting.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/txfixtures.git



More information about the Python-modules-commits mailing list