Skip to content

Commit b7fb4c7

Browse files
authored
Merge pull request #1 from python-effect/py3
get rid of exc_info-using code to be compatible with new release of Effect
2 parents d125faa + 91669aa commit b7fb4c7

File tree

6 files changed

+27
-47
lines changed

6 files changed

+27
-47
lines changed

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ sudo: false
22

33
language: python
44
python:
5-
- "2.7"
6-
- "2.6"
7-
- "3.4"
8-
- "pypy"
5+
- "3.6"
6+
- "3.7"
7+
- "3.8"
8+
- "pypy3"
99
install:
1010
- pip install -r dev-requirements.txt
1111
- pip install .
1212
script:
13-
- make lint
13+
- flake8
1414
- py.test
1515
- make doc
1616

Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
lint:
2-
flake8 --ignore=E131,E731,W503 txeffect/
3-
41
build-dist:
52
rm -rf dist
63
python setup.py sdist bdist_wheel

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
# 3. If at all possible, it is good practice to do this. If you cannot, you
44
# will need to generate wheels for each Python version that you support.
55
universal=1
6+
7+
[flake8]
8+
max-line-length = 100
9+
ignore = E131,E731,W503

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'License :: OSI Approved :: MIT License',
1414
'Programming Language :: Python :: 2',
1515
'Programming Language :: Python :: 3',
16-
],
16+
],
1717
packages=['txeffect'],
1818
install_requires=['effect', 'twisted'],
19-
)
19+
)

txeffect/__init__.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,25 @@
1313
does.
1414
"""
1515

16-
from __future__ import absolute_import
17-
1816
from functools import partial
19-
import sys
2017

2118
from twisted.internet.defer import Deferred
22-
from twisted.python.failure import Failure
2319
from twisted.internet.task import deferLater
2420

2521
from effect import (
2622
Delay,
2723
ParallelEffects,
2824
perform as base_perform,
2925
TypeDispatcher)
30-
from effect.async import perform_parallel_async
26+
from effect.parallel_async import perform_parallel_async
3127
from effect._utils import wraps # whoah there
3228

3329

3430
def deferred_to_box(d, box):
3531
"""
3632
Make a Deferred pass its success or fail events on to the given box.
3733
"""
38-
d.addCallbacks(box.succeed, lambda f: box.fail((f.type, f.value, f.tb)))
34+
d.addCallbacks(box.succeed, lambda f: box.fail(f.value))
3935

4036

4137
def make_twisted_dispatcher(reactor):
@@ -71,8 +67,8 @@ def deferred_wrapper(*args, **kwargs):
7167
pass_args = args[:-1]
7268
try:
7369
result = f(*pass_args, **kwargs)
74-
except:
75-
box.fail(sys.exc_info())
70+
except Exception as e:
71+
box.fail(e)
7672
else:
7773
if isinstance(result, Deferred):
7874
deferred_to_box(result, box)
@@ -97,11 +93,6 @@ def perform(dispatcher, effect):
9793
d = Deferred()
9894
eff = effect.on(
9995
success=d.callback,
100-
error=lambda e: d.errback(exc_info_to_failure(e)))
96+
error=lambda e: d.errback(e))
10197
base_perform(dispatcher, eff)
10298
return d
103-
104-
105-
def exc_info_to_failure(exc_info):
106-
"""Convert an exc_info tuple to a :class:`Failure`."""
107-
return Failure(exc_info[1], exc_info[0], exc_info[2])

txeffect/test_txeffect.py

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
from __future__ import absolute_import
22

33
from functools import partial
4-
import sys
54

65
from testtools import TestCase
7-
from testtools.matchers import MatchesListwise, Equals, MatchesException
6+
from testtools.matchers import MatchesListwise, Equals
87

98
from twisted.trial.unittest import SynchronousTestCase
109
from twisted.internet.defer import Deferred
@@ -16,9 +15,9 @@
1615
base_dispatcher, parallel,
1716
ComposedDispatcher,
1817
)
18+
from effect._test_utils import MatchesException
1919
from . import (
2020
deferred_performer,
21-
exc_info_to_failure,
2221
make_twisted_dispatcher,
2322
perform)
2423

@@ -95,14 +94,22 @@ def test_perform_failure(self):
9594
effect.twisted.perform fails the Deferred it returns if the ultimate
9695
result of the Effect is an exception.
9796
"""
97+
try:
98+
raise ValueError("oh dear")
99+
except Exception as e:
100+
exc = e
101+
98102
boxes = []
99103
e = Effect(boxes.append)
100104
d = perform(func_dispatcher, e)
101105
self.assertNoResult(d)
102-
boxes[0].fail((ValueError, ValueError("oh dear"), None))
106+
boxes[0].fail(exc)
103107
f = self.failureResultOf(d)
104108
self.assertEqual(f.type, ValueError)
105109
self.assertEqual(str(f.value), 'oh dear')
110+
self.assertRegex(
111+
f.getTraceback().splitlines()[-3],
112+
r'^\s+File ".*?test_txeffect.py", line \d+, in test_perform_failure$')
106113

107114

108115
class DeferredPerformerTests(TestCase):
@@ -219,22 +226,3 @@ def p(dispatcher, intent, extra):
219226
dispatcher = lambda _: partial(p, extra='extra val')
220227
result = self.successResultOf(perform(dispatcher, Effect('foo')))
221228
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

Comments
 (0)