Merge lp:~cjwatson/launchpad/twisted-18.4.0 into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18727
Proposed branch: lp:~cjwatson/launchpad/twisted-18.4.0
Merge into: lp:launchpad
Diff against target: 142 lines (+37/-18)
4 files modified
constraints.txt (+1/-1)
lib/lp/services/twistedsupport/tests/test_gracefulshutdown.py (+8/-2)
lib/lp/services/twistedsupport/tests/test_xmlrpc.py (+18/-11)
lib/lp/services/twistedsupport/xmlrpc.py (+10/-4)
To merge this branch: bzr merge lp:~cjwatson/launchpad/twisted-18.4.0
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+349244@code.launchpad.net

Commit message

Upgrade to Twisted 18.4.0.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'constraints.txt'
2--- constraints.txt 2018-07-03 09:17:30 +0000
3+++ constraints.txt 2018-07-10 09:07:12 +0000
4@@ -360,7 +360,7 @@
5 testscenarios==0.4
6 timeline==0.0.3
7 treq==18.6.0
8-Twisted[conch,tls]==17.9.0
9+Twisted[conch,tls]==18.4.0
10 txAMQP==0.6.2
11 txfixtures==0.4.2
12 txlongpoll==0.2.12
13
14=== modified file 'lib/lp/services/twistedsupport/tests/test_gracefulshutdown.py'
15--- lib/lp/services/twistedsupport/tests/test_gracefulshutdown.py 2017-12-21 17:27:18 +0000
16+++ lib/lp/services/twistedsupport/tests/test_gracefulshutdown.py 2018-07-10 09:07:12 +0000
17@@ -1,14 +1,17 @@
18-# Copyright 2011 Canonical Ltd. This software is licensed under the
19+# Copyright 2011-2018 Canonical Ltd. This software is licensed under the
20 # GNU Affero General Public License version 3 (see the file LICENSE).
21
22 """Tests for our graceful daemon shutdown support."""
23
24 __metaclass__ = type
25
26+import io
27+
28 from twisted.application import service
29 from twisted.internet.defer import Deferred
30 from twisted.internet.protocol import (
31 Factory,
32+ FileWrapper,
33 Protocol,
34 )
35 from twisted.web import http
36@@ -99,7 +102,10 @@
37
38 def make_dummy_http_request(self):
39 """Make a dummy HTTP request for tests."""
40- return http.Request(http.HTTPChannel(), True)
41+ transport = FileWrapper(io.BytesIO())
42+ channel = http.HTTPChannel()
43+ channel.makeConnection(transport)
44+ return http.Request(channel, True)
45
46 def test_200_when_available(self):
47 """When the factory is available a 200 response is generated."""
48
49=== modified file 'lib/lp/services/twistedsupport/tests/test_xmlrpc.py'
50--- lib/lp/services/twistedsupport/tests/test_xmlrpc.py 2018-04-05 17:03:54 +0000
51+++ lib/lp/services/twistedsupport/tests/test_xmlrpc.py 2018-07-10 09:07:12 +0000
52@@ -5,6 +5,12 @@
53
54 __metaclass__ = type
55
56+import sys
57+
58+from testtools.matchers import (
59+ LessThan,
60+ Not,
61+ )
62 from twisted.python.failure import Failure
63
64 from lp.services.twistedsupport import extract_result
65@@ -49,30 +55,31 @@
66 except:
67 return Failure()
68
69- def assertRaisesExactException(self, exception, function, *args, **kwargs):
70+ def assertRaisesFailure(self, failure, function, *args, **kwargs):
71 try:
72 function(*args, **kwargs)
73+ except Failure as raised_failure:
74+ self.assertThat(sys.version_info, LessThan((3, 0)))
75+ self.assertEqual(failure, raised_failure)
76 except Exception as raised_exception:
77- self.assertEqual(raised_exception, exception)
78+ self.assertThat(sys.version_info, Not(LessThan((3, 0))))
79+ self.assertEqual(failure.value, raised_exception)
80
81 def test_raises_non_faults(self):
82- # trap_fault re-raises the underlying exception from any failures it
83- # gets that aren't faults.
84+ # trap_fault re-raises any failures it gets that aren't faults.
85 failure = self.makeFailure(RuntimeError, 'example failure')
86- self.assertRaisesExactException(
87- failure.value, trap_fault, failure, TestFaultOne)
88+ self.assertRaisesFailure(failure, trap_fault, failure, TestFaultOne)
89
90 def test_raises_faults_with_wrong_code(self):
91- # trap_fault re-raises the underlying exception from any failures it
92- # gets that are faults but have the wrong fault code.
93+ # trap_fault re-raises any failures it gets that are faults but have
94+ # the wrong fault code.
95 failure = self.makeFailure(TestFaultOne)
96- self.assertRaisesExactException(
97- failure.value, trap_fault, failure, TestFaultTwo)
98+ self.assertRaisesFailure(failure, trap_fault, failure, TestFaultTwo)
99
100 def test_raises_faults_if_no_codes_given(self):
101 # If trap_fault is not given any fault codes, it re-raises the fault.
102 failure = self.makeFailure(TestFaultOne)
103- self.assertRaisesExactException(failure.value, trap_fault, failure)
104+ self.assertRaisesFailure(failure, trap_fault, failure)
105
106 def test_returns_fault_if_code_matches(self):
107 # trap_fault returns the Fault inside the Failure if the fault code
108
109=== modified file 'lib/lp/services/twistedsupport/xmlrpc.py'
110--- lib/lp/services/twistedsupport/xmlrpc.py 2018-04-05 17:03:54 +0000
111+++ lib/lp/services/twistedsupport/xmlrpc.py 2018-07-10 09:07:12 +0000
112@@ -10,6 +10,8 @@
113 'trap_fault',
114 ]
115
116+import sys
117+
118 from twisted.internet import defer
119 from twisted.web import xmlrpc
120
121@@ -55,13 +57,17 @@
122
123 :param failure: A Twisted L{Failure}.
124 :param *fault_codes: `LaunchpadFault` subclasses.
125- :raise Exception: the underlying exception from 'failure' if 'failure'
126- is not a Fault failure, or if the fault code does not match the
127- given codes.
128+ :raise Exception: if 'failure' is not a Fault failure, or if the fault
129+ code does not match the given codes. In line with L{Failure.trap},
130+ the exception is the L{Failure} itself on Python 2 and the
131+ underlying exception on Python 3.
132 :return: The Fault if it matches one of the codes.
133 """
134 failure.trap(xmlrpc.Fault)
135 fault = failure.value
136 if fault.faultCode in [cls.error_code for cls in fault_classes]:
137 return fault
138- failure.raiseException()
139+ if sys.version_info >= (3, 0):
140+ failure.raiseException()
141+ else:
142+ raise failure