← Back to team overview

testtools-dev team mailing list archive

[Merge] lp:~jseutter/testtools/py3 into lp:testtools

 

Jerry Seutter has proposed merging lp:~jseutter/testtools/py3 into lp:testtools.

Requested reviews:
  testtools committers (testtools-committers)

For more details, see:
https://code.launchpad.net/~jseutter/testtools/py3/+merge/105505

This change adds support for building and installing using python 3.  Previously this package could be used in both python 2 and python 3, but a "python setup.py install" using python 3 would fail when trying to compile _compat2x.py.

get_revno() will now silently fail if bzrlib is not present, as bzrlib is not yet available in python 3.

The diff is a little strange because I removed _compat2x.py and later added it back in.  I added brackets around the raise line:

  raise (exc_class, exc_obj, exc_tb)
-- 
https://code.launchpad.net/~jseutter/testtools/py3/+merge/105505
Your team testtools developers is subscribed to branch lp:testtools.
=== modified file 'setup.py'
--- setup.py	2011-11-25 18:24:10 +0000
+++ setup.py	2012-05-11 19:01:20 +0000
@@ -9,8 +9,11 @@
 
 
 def get_revno():
-    import bzrlib.errors
-    import bzrlib.workingtree
+    try:
+        import bzrlib.errors
+        import bzrlib.workingtree
+    except ImportError:
+        return None
     try:
         t = bzrlib.workingtree.WorkingTree.open_containing(__file__)[0]
     except (bzrlib.errors.NotBranchError, bzrlib.errors.NoWorkingTree):

=== added file 'testtools/_compat2x.py'
--- testtools/_compat2x.py	1970-01-01 00:00:00 +0000
+++ testtools/_compat2x.py	2012-05-11 19:01:20 +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)
+

=== removed file 'testtools/_compat2x.py'
--- testtools/_compat2x.py	2011-07-26 23:08:51 +0000
+++ testtools/_compat2x.py	1970-01-01 00:00:00 +0000
@@ -1,17 +0,0 @@
-# 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
-

=== modified file 'testtools/compat.py'
--- testtools/compat.py	2011-12-05 15:21:33 +0000
+++ testtools/compat.py	2012-05-11 19:01:20 +0000
@@ -32,10 +32,10 @@
 BytesIO = try_imports(['StringIO.StringIO', 'io.BytesIO'])
 StringIO = try_imports(['StringIO.StringIO', 'io.StringIO'])
 
-try:
+if sys.version_info < (3, 0):
     from testtools import _compat2x as _compat
     _compat
-except SyntaxError:
+else:
     from testtools import _compat3x as _compat
 
 reraise = _compat.reraise


Follow ups