|
4 | 4 | import sys |
5 | 5 |
|
6 | 6 | from testtools import TestCase |
7 | | -from testtools.matchers import MatchesListwise, Equals, MatchesException |
| 7 | +from testtools.matchers import MatchesListwise, Equals |
8 | 8 |
|
9 | 9 | from twisted.trial.unittest import SynchronousTestCase |
10 | 10 | from twisted.internet.defer import Deferred |
|
16 | 16 | base_dispatcher, parallel, |
17 | 17 | ComposedDispatcher, |
18 | 18 | ) |
| 19 | +from effect._test_utils import MatchesException |
19 | 20 | from . import ( |
20 | 21 | deferred_performer, |
21 | | - exc_info_to_failure, |
22 | 22 | make_twisted_dispatcher, |
23 | 23 | perform) |
24 | 24 |
|
@@ -95,14 +95,22 @@ def test_perform_failure(self): |
95 | 95 | effect.twisted.perform fails the Deferred it returns if the ultimate |
96 | 96 | result of the Effect is an exception. |
97 | 97 | """ |
| 98 | + try: |
| 99 | + raise ValueError("oh dear") |
| 100 | + except Exception as e: |
| 101 | + exc = e |
| 102 | + |
98 | 103 | boxes = [] |
99 | 104 | e = Effect(boxes.append) |
100 | 105 | d = perform(func_dispatcher, e) |
101 | 106 | self.assertNoResult(d) |
102 | | - boxes[0].fail((ValueError, ValueError("oh dear"), None)) |
| 107 | + boxes[0].fail(exc) |
103 | 108 | f = self.failureResultOf(d) |
104 | 109 | self.assertEqual(f.type, ValueError) |
105 | 110 | self.assertEqual(str(f.value), 'oh dear') |
| 111 | + self.assertRegex( |
| 112 | + f.getTraceback().splitlines()[-3], |
| 113 | + '^\s+File ".*?test_txeffect.py", line \d+, in test_perform_failure$') |
106 | 114 |
|
107 | 115 |
|
108 | 116 | class DeferredPerformerTests(TestCase): |
@@ -219,22 +227,3 @@ def p(dispatcher, intent, extra): |
219 | 227 | dispatcher = lambda _: partial(p, extra='extra val') |
220 | 228 | result = self.successResultOf(perform(dispatcher, Effect('foo'))) |
221 | 229 | self.assertEqual(result, 'extra val') |
222 | | - |
223 | | - |
224 | | -class ExcInfoToFailureTests(TestCase): |
225 | | - """Tests for :func:`exc_info_to_failure`.""" |
226 | | - |
227 | | - def test_exc_info_to_failure(self): |
228 | | - """ |
229 | | - :func:`exc_info_to_failure` converts an exc_info tuple to a |
230 | | - :obj:`Failure`. |
231 | | - """ |
232 | | - try: |
233 | | - raise RuntimeError("foo") |
234 | | - except: |
235 | | - exc_info = sys.exc_info() |
236 | | - |
237 | | - failure = exc_info_to_failure(exc_info) |
238 | | - self.assertIs(failure.type, RuntimeError) |
239 | | - self.assertEqual(str(failure.value), "foo") |
240 | | - self.assertIs(failure.tb, exc_info[2]) |
0 commit comments