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

Proposed by Colin Watson on 2018-07-10
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 2018-07-10 Approve on 2018-07-12
Review via email: mp+349244@code.launchpad.net

Commit message

Upgrade to Twisted 18.4.0.

To post a comment you must log in.
18713. By Colin Watson on 2018-07-10

Merge devel.

William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'constraints.txt'
--- constraints.txt 2018-07-03 09:17:30 +0000
+++ constraints.txt 2018-07-10 09:07:12 +0000
@@ -360,7 +360,7 @@
360testscenarios==0.4360testscenarios==0.4
361timeline==0.0.3361timeline==0.0.3
362treq==18.6.0362treq==18.6.0
363Twisted[conch,tls]==17.9.0363Twisted[conch,tls]==18.4.0
364txAMQP==0.6.2364txAMQP==0.6.2
365txfixtures==0.4.2365txfixtures==0.4.2
366txlongpoll==0.2.12366txlongpoll==0.2.12
367367
=== modified file 'lib/lp/services/twistedsupport/tests/test_gracefulshutdown.py'
--- lib/lp/services/twistedsupport/tests/test_gracefulshutdown.py 2017-12-21 17:27:18 +0000
+++ lib/lp/services/twistedsupport/tests/test_gracefulshutdown.py 2018-07-10 09:07:12 +0000
@@ -1,14 +1,17 @@
1# Copyright 2011 Canonical Ltd. This software is licensed under the1# Copyright 2011-2018 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Tests for our graceful daemon shutdown support."""4"""Tests for our graceful daemon shutdown support."""
55
6__metaclass__ = type6__metaclass__ = type
77
8import io
9
8from twisted.application import service10from twisted.application import service
9from twisted.internet.defer import Deferred11from twisted.internet.defer import Deferred
10from twisted.internet.protocol import (12from twisted.internet.protocol import (
11 Factory,13 Factory,
14 FileWrapper,
12 Protocol,15 Protocol,
13 )16 )
14from twisted.web import http17from twisted.web import http
@@ -99,7 +102,10 @@
99102
100 def make_dummy_http_request(self):103 def make_dummy_http_request(self):
101 """Make a dummy HTTP request for tests."""104 """Make a dummy HTTP request for tests."""
102 return http.Request(http.HTTPChannel(), True)105 transport = FileWrapper(io.BytesIO())
106 channel = http.HTTPChannel()
107 channel.makeConnection(transport)
108 return http.Request(channel, True)
103109
104 def test_200_when_available(self):110 def test_200_when_available(self):
105 """When the factory is available a 200 response is generated."""111 """When the factory is available a 200 response is generated."""
106112
=== modified file 'lib/lp/services/twistedsupport/tests/test_xmlrpc.py'
--- lib/lp/services/twistedsupport/tests/test_xmlrpc.py 2018-04-05 17:03:54 +0000
+++ lib/lp/services/twistedsupport/tests/test_xmlrpc.py 2018-07-10 09:07:12 +0000
@@ -5,6 +5,12 @@
55
6__metaclass__ = type6__metaclass__ = type
77
8import sys
9
10from testtools.matchers import (
11 LessThan,
12 Not,
13 )
8from twisted.python.failure import Failure14from twisted.python.failure import Failure
915
10from lp.services.twistedsupport import extract_result16from lp.services.twistedsupport import extract_result
@@ -49,30 +55,31 @@
49 except:55 except:
50 return Failure()56 return Failure()
5157
52 def assertRaisesExactException(self, exception, function, *args, **kwargs):58 def assertRaisesFailure(self, failure, function, *args, **kwargs):
53 try:59 try:
54 function(*args, **kwargs)60 function(*args, **kwargs)
61 except Failure as raised_failure:
62 self.assertThat(sys.version_info, LessThan((3, 0)))
63 self.assertEqual(failure, raised_failure)
55 except Exception as raised_exception:64 except Exception as raised_exception:
56 self.assertEqual(raised_exception, exception)65 self.assertThat(sys.version_info, Not(LessThan((3, 0))))
66 self.assertEqual(failure.value, raised_exception)
5767
58 def test_raises_non_faults(self):68 def test_raises_non_faults(self):
59 # trap_fault re-raises the underlying exception from any failures it69 # trap_fault re-raises any failures it gets that aren't faults.
60 # gets that aren't faults.
61 failure = self.makeFailure(RuntimeError, 'example failure')70 failure = self.makeFailure(RuntimeError, 'example failure')
62 self.assertRaisesExactException(71 self.assertRaisesFailure(failure, trap_fault, failure, TestFaultOne)
63 failure.value, trap_fault, failure, TestFaultOne)
6472
65 def test_raises_faults_with_wrong_code(self):73 def test_raises_faults_with_wrong_code(self):
66 # trap_fault re-raises the underlying exception from any failures it74 # trap_fault re-raises any failures it gets that are faults but have
67 # gets that are faults but have the wrong fault code.75 # the wrong fault code.
68 failure = self.makeFailure(TestFaultOne)76 failure = self.makeFailure(TestFaultOne)
69 self.assertRaisesExactException(77 self.assertRaisesFailure(failure, trap_fault, failure, TestFaultTwo)
70 failure.value, trap_fault, failure, TestFaultTwo)
7178
72 def test_raises_faults_if_no_codes_given(self):79 def test_raises_faults_if_no_codes_given(self):
73 # If trap_fault is not given any fault codes, it re-raises the fault.80 # If trap_fault is not given any fault codes, it re-raises the fault.
74 failure = self.makeFailure(TestFaultOne)81 failure = self.makeFailure(TestFaultOne)
75 self.assertRaisesExactException(failure.value, trap_fault, failure)82 self.assertRaisesFailure(failure, trap_fault, failure)
7683
77 def test_returns_fault_if_code_matches(self):84 def test_returns_fault_if_code_matches(self):
78 # trap_fault returns the Fault inside the Failure if the fault code85 # trap_fault returns the Fault inside the Failure if the fault code
7986
=== modified file 'lib/lp/services/twistedsupport/xmlrpc.py'
--- lib/lp/services/twistedsupport/xmlrpc.py 2018-04-05 17:03:54 +0000
+++ lib/lp/services/twistedsupport/xmlrpc.py 2018-07-10 09:07:12 +0000
@@ -10,6 +10,8 @@
10 'trap_fault',10 'trap_fault',
11 ]11 ]
1212
13import sys
14
13from twisted.internet import defer15from twisted.internet import defer
14from twisted.web import xmlrpc16from twisted.web import xmlrpc
1517
@@ -55,13 +57,17 @@
5557
56 :param failure: A Twisted L{Failure}.58 :param failure: A Twisted L{Failure}.
57 :param *fault_codes: `LaunchpadFault` subclasses.59 :param *fault_codes: `LaunchpadFault` subclasses.
58 :raise Exception: the underlying exception from 'failure' if 'failure'60 :raise Exception: if 'failure' is not a Fault failure, or if the fault
59 is not a Fault failure, or if the fault code does not match the61 code does not match the given codes. In line with L{Failure.trap},
60 given codes.62 the exception is the L{Failure} itself on Python 2 and the
63 underlying exception on Python 3.
61 :return: The Fault if it matches one of the codes.64 :return: The Fault if it matches one of the codes.
62 """65 """
63 failure.trap(xmlrpc.Fault)66 failure.trap(xmlrpc.Fault)
64 fault = failure.value67 fault = failure.value
65 if fault.faultCode in [cls.error_code for cls in fault_classes]:68 if fault.faultCode in [cls.error_code for cls in fault_classes]:
66 return fault69 return fault
67 failure.raiseException()70 if sys.version_info >= (3, 0):
71 failure.raiseException()
72 else:
73 raise failure