|
7 | 7 | from testtools import TestCase |
8 | 8 | from testtools.matchers import Equals, MatchesListwise |
9 | 9 |
|
| 10 | +from pytest import raises |
| 11 | + |
10 | 12 | from ._base import Effect |
11 | 13 | from ._dispatcher import ComposedDispatcher, TypeDispatcher |
12 | 14 | from ._intents import ( |
|
22 | 24 | from .test_parallel_performers import EquitableException |
23 | 25 |
|
24 | 26 |
|
25 | | -class IntentTests(TestCase): |
26 | | - """Tests for intents.""" |
27 | | - |
28 | | - def test_perform_constant(self): |
29 | | - """ |
30 | | - perform_constant returns the result of a Constant. |
31 | | - """ |
32 | | - intent = Constant("foo") |
33 | | - result = sync_perform( |
34 | | - TypeDispatcher({Constant: perform_constant}), |
35 | | - Effect(intent)) |
36 | | - self.assertEqual(result, "foo") |
37 | | - |
38 | | - def test_perform_error(self): |
39 | | - """ |
40 | | - perform_error raises the exception of a Error. |
41 | | - """ |
42 | | - intent = Error(ValueError("foo")) |
43 | | - self.assertRaises( |
44 | | - ValueError, |
45 | | - lambda: sync_perform( |
46 | | - TypeDispatcher({Error: perform_error}), |
47 | | - Effect(intent))) |
48 | | - |
49 | | - def test_perform_func(self): |
50 | | - """ |
51 | | - perform_func calls the function given in a Func. |
52 | | - """ |
53 | | - intent = Func(lambda: "foo") |
54 | | - result = sync_perform( |
55 | | - TypeDispatcher({Func: perform_func}), |
56 | | - Effect(intent)) |
57 | | - self.assertEqual(result, "foo") |
58 | | - |
59 | | - |
60 | | -class ParallelTests(TestCase): |
61 | | - """Tests for :func:`parallel`.""" |
62 | | - |
63 | | - def test_first_error_str(self): |
64 | | - """FirstErrors have a pleasing format.""" |
65 | | - fe = FirstError(exc_info=(ValueError, ValueError('foo'), None), |
66 | | - index=150) |
67 | | - self.assertEqual( |
68 | | - str(fe), |
69 | | - '(index=150) ValueError: foo') |
| 27 | +def test_perform_constant(): |
| 28 | + """perform_constant returns the result of a Constant.""" |
| 29 | + intent = Constant("foo") |
| 30 | + result = sync_perform( |
| 31 | + TypeDispatcher({Constant: perform_constant}), |
| 32 | + Effect(intent)) |
| 33 | + assert result == "foo" |
| 34 | + |
| 35 | +def test_perform_error(): |
| 36 | + """perform_error raises the exception of an Error.""" |
| 37 | + intent = Error(ValueError("foo")) |
| 38 | + with raises(ValueError): |
| 39 | + sync_perform(TypeDispatcher({Error: perform_error}), Effect(intent)) |
| 40 | + |
| 41 | +def test_perform_func(): |
| 42 | + """perform_func calls the function given in a Func.""" |
| 43 | + intent = Func(lambda: "foo") |
| 44 | + result = sync_perform( |
| 45 | + TypeDispatcher({Func: perform_func}), |
| 46 | + Effect(intent)) |
| 47 | + assert result == "foo" |
| 48 | + |
| 49 | +def test_perform_func_args_kwargs(): |
| 50 | + """arbitrary positional and keyword arguments can be passed to Func.""" |
| 51 | + f = lambda *a, **kw: (a, kw) |
| 52 | + intent = Func(f, 1, 2, key=3) |
| 53 | + result = sync_perform(TypeDispatcher({Func: perform_func}), Effect(intent)) |
| 54 | + assert result == ((1, 2), {'key': 3}) |
| 55 | + |
| 56 | +def test_first_error_str(): |
| 57 | + """FirstErrors have a pleasing format.""" |
| 58 | + fe = FirstError(exc_info=(ValueError, ValueError('foo'), None), |
| 59 | + index=150) |
| 60 | + assert str(fe) == '(index=150) ValueError: foo' |
70 | 61 |
|
71 | 62 |
|
72 | 63 | class ParallelAllErrorsTests(TestCase): |
|
0 commit comments