|
1 | 1 | from __future__ import print_function, absolute_import |
2 | 2 |
|
| 3 | +from functools import partial |
| 4 | + |
| 5 | +import six |
| 6 | + |
3 | 7 | from testtools import TestCase |
| 8 | +from testtools.matchers import Equals, MatchesListwise |
4 | 9 |
|
5 | 10 | from ._base import Effect |
6 | | -from ._sync import sync_perform |
7 | | -from ._dispatcher import TypeDispatcher |
8 | | - |
| 11 | +from ._dispatcher import ComposedDispatcher, TypeDispatcher |
9 | 12 | from ._intents import ( |
| 13 | + base_dispatcher, |
10 | 14 | Constant, perform_constant, |
11 | 15 | Error, perform_error, |
12 | 16 | Func, perform_func, |
13 | | - FirstError) |
| 17 | + FirstError, |
| 18 | + ParallelEffects, parallel_all_errors) |
| 19 | +from ._sync import sync_perform |
| 20 | +from ._test_utils import MatchesReraisedExcInfo, get_exc_info |
| 21 | +from .async import perform_parallel_async |
| 22 | +from .test_parallel_performers import EquitableException |
14 | 23 |
|
15 | 24 |
|
16 | 25 | class IntentTests(TestCase): |
@@ -58,3 +67,36 @@ def test_first_error_str(self): |
58 | 67 | self.assertEqual( |
59 | 68 | str(fe), |
60 | 69 | '(index=150) ValueError: foo') |
| 70 | + |
| 71 | + |
| 72 | +class ParallelAllErrorsTests(TestCase): |
| 73 | + """Tests for :func:`parallel_all_errors`.""" |
| 74 | + |
| 75 | + def test_parallel_all_errors(self): |
| 76 | + """ |
| 77 | + Exceptions raised from child effects get turned into (True, exc_info) |
| 78 | + results. |
| 79 | + """ |
| 80 | + exc_info1 = get_exc_info(EquitableException(message='foo')) |
| 81 | + reraise1 = partial(six.reraise, *exc_info1) |
| 82 | + exc_info2 = get_exc_info(EquitableException(message='bar')) |
| 83 | + reraise2 = partial(six.reraise, *exc_info2) |
| 84 | + |
| 85 | + dispatcher = ComposedDispatcher([ |
| 86 | + TypeDispatcher({ |
| 87 | + ParallelEffects: perform_parallel_async, |
| 88 | + }), |
| 89 | + base_dispatcher]) |
| 90 | + es = [Effect(Func(reraise1)), |
| 91 | + Effect(Constant(1)), |
| 92 | + Effect(Func(reraise2))] |
| 93 | + eff = parallel_all_errors(es) |
| 94 | + self.assertThat( |
| 95 | + sync_perform(dispatcher, eff), |
| 96 | + MatchesListwise([ |
| 97 | + MatchesListwise([Equals(True), |
| 98 | + MatchesReraisedExcInfo(exc_info1)]), |
| 99 | + Equals((False, 1)), |
| 100 | + MatchesListwise([Equals(True), |
| 101 | + MatchesReraisedExcInfo(exc_info2)]), |
| 102 | + ])) |
0 commit comments