Merge lp:~jml/testtools/reraise into lp:~testtools-committers/testtools/trunk

Proposed by Jonathan Lange
Status: Merged
Merged at revision: 217
Proposed branch: lp:~jml/testtools/reraise
Merge into: lp:~testtools-committers/testtools/trunk
Diff against target: 89 lines (+50/-0)
4 files modified
NEWS (+2/-0)
testtools/_compat2x.py (+17/-0)
testtools/_compat3x.py (+17/-0)
testtools/compat.py (+14/-0)
To merge this branch: bzr merge lp:~jml/testtools/reraise
Reviewer Review Type Date Requested Status
testtools developers Pending
Review via email: mp+69375@code.launchpad.net

Description of the change

Adds reraise to compat. Not used in testtools but would be very useful in fixtures.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2011-07-21 10:22:51 +0000
3+++ NEWS 2011-07-26 23:11:14 +0000
4@@ -67,6 +67,8 @@
5
6 * New helper, ``safe_hasattr`` added. (Jonathan Lange)
7
8+* ``reraise`` added to ``testtools.compat``. (Jonathan Lange)
9+
10
11 0.9.11
12 ~~~~~~
13
14=== added file 'testtools/_compat2x.py'
15--- testtools/_compat2x.py 1970-01-01 00:00:00 +0000
16+++ testtools/_compat2x.py 2011-07-26 23:11:14 +0000
17@@ -0,0 +1,17 @@
18+# Copyright (c) 2011 testtools developers. See LICENSE for details.
19+
20+"""Compatibility helpers that are valid syntax in Python 2.x.
21+
22+Only add things here if they *only* work in Python 2.x or are Python 2
23+alternatives to things that *only* work in Python 3.x.
24+"""
25+
26+__all__ = [
27+ 'reraise',
28+ ]
29+
30+
31+def reraise(exc_class, exc_obj, exc_tb, _marker=object()):
32+ """Re-raise an exception received from sys.exc_info() or similar."""
33+ raise exc_class, exc_obj, exc_tb
34+
35
36=== added file 'testtools/_compat3x.py'
37--- testtools/_compat3x.py 1970-01-01 00:00:00 +0000
38+++ testtools/_compat3x.py 2011-07-26 23:11:14 +0000
39@@ -0,0 +1,17 @@
40+# Copyright (c) 2011 testtools developers. See LICENSE for details.
41+
42+"""Compatibility helpers that are valid syntax in Python 3.x.
43+
44+Only add things here if they *only* work in Python 3.x or are Python 3
45+alternatives to things that *only* work in Python 2.x.
46+"""
47+
48+__all__ = [
49+ 'reraise',
50+ ]
51+
52+
53+def reraise(exc_class, exc_obj, exc_tb, _marker=object()):
54+ """Re-raise an exception received from sys.exc_info() or similar."""
55+ raise exc_class(*exc_obj.args).with_traceback(exc_tb)
56+
57
58=== modified file 'testtools/compat.py'
59--- testtools/compat.py 2011-07-01 15:55:32 +0000
60+++ testtools/compat.py 2011-07-26 23:11:14 +0000
61@@ -7,8 +7,14 @@
62 '_b',
63 '_u',
64 'advance_iterator',
65+ 'all',
66+ 'BytesIO',
67+ 'classtypes',
68+ 'isbaseexception',
69+ 'istext',
70 'str_is_unicode',
71 'StringIO',
72+ 'reraise',
73 'unicode_output_stream',
74 ]
75
76@@ -25,6 +31,14 @@
77 BytesIO = try_imports(['StringIO.StringIO', 'io.BytesIO'])
78 StringIO = try_imports(['StringIO.StringIO', 'io.StringIO'])
79
80+try:
81+ from testtools import _compat2x as _compat
82+ _compat
83+except SyntaxError:
84+ from testtools import _compat3x as _compat
85+
86+reraise = _compat.reraise
87+
88
89 __u_doc = """A function version of the 'u' prefix.
90

Subscribers

People subscribed via source and target branches