testtools-dev team mailing list archive
-
testtools-dev team
-
Mailing list archive
-
Message #00844
[Merge] lp:~jml/testtools/reraise into lp:testtools
Jonathan Lange has proposed merging lp:~jml/testtools/reraise into lp:testtools.
Requested reviews:
testtools developers (testtools-dev)
For more details, see:
https://code.launchpad.net/~jml/testtools/reraise/+merge/69375
Adds reraise to compat. Not used in testtools but would be very useful in fixtures.
--
https://code.launchpad.net/~jml/testtools/reraise/+merge/69375
Your team testtools developers is requested to review the proposed merge of lp:~jml/testtools/reraise into lp:testtools.
=== modified file 'NEWS'
--- NEWS 2011-07-21 10:22:51 +0000
+++ NEWS 2011-07-26 23:11:14 +0000
@@ -67,6 +67,8 @@
* New helper, ``safe_hasattr`` added. (Jonathan Lange)
+* ``reraise`` added to ``testtools.compat``. (Jonathan Lange)
+
0.9.11
~~~~~~
=== added file 'testtools/_compat2x.py'
--- testtools/_compat2x.py 1970-01-01 00:00:00 +0000
+++ testtools/_compat2x.py 2011-07-26 23:11:14 +0000
@@ -0,0 +1,17 @@
+# Copyright (c) 2011 testtools developers. See LICENSE for details.
+
+"""Compatibility helpers that are valid syntax in Python 2.x.
+
+Only add things here if they *only* work in Python 2.x or are Python 2
+alternatives to things that *only* work in Python 3.x.
+"""
+
+__all__ = [
+ 'reraise',
+ ]
+
+
+def reraise(exc_class, exc_obj, exc_tb, _marker=object()):
+ """Re-raise an exception received from sys.exc_info() or similar."""
+ raise exc_class, exc_obj, exc_tb
+
=== added file 'testtools/_compat3x.py'
--- testtools/_compat3x.py 1970-01-01 00:00:00 +0000
+++ testtools/_compat3x.py 2011-07-26 23:11:14 +0000
@@ -0,0 +1,17 @@
+# Copyright (c) 2011 testtools developers. See LICENSE for details.
+
+"""Compatibility helpers that are valid syntax in Python 3.x.
+
+Only add things here if they *only* work in Python 3.x or are Python 3
+alternatives to things that *only* work in Python 2.x.
+"""
+
+__all__ = [
+ 'reraise',
+ ]
+
+
+def reraise(exc_class, exc_obj, exc_tb, _marker=object()):
+ """Re-raise an exception received from sys.exc_info() or similar."""
+ raise exc_class(*exc_obj.args).with_traceback(exc_tb)
+
=== modified file 'testtools/compat.py'
--- testtools/compat.py 2011-07-01 15:55:32 +0000
+++ testtools/compat.py 2011-07-26 23:11:14 +0000
@@ -7,8 +7,14 @@
'_b',
'_u',
'advance_iterator',
+ 'all',
+ 'BytesIO',
+ 'classtypes',
+ 'isbaseexception',
+ 'istext',
'str_is_unicode',
'StringIO',
+ 'reraise',
'unicode_output_stream',
]
@@ -25,6 +31,14 @@
BytesIO = try_imports(['StringIO.StringIO', 'io.BytesIO'])
StringIO = try_imports(['StringIO.StringIO', 'io.StringIO'])
+try:
+ from testtools import _compat2x as _compat
+ _compat
+except SyntaxError:
+ from testtools import _compat3x as _compat
+
+reraise = _compat.reraise
+
__u_doc = """A function version of the 'u' prefix.
Follow ups