# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview
# User holger krekel <hol...@merlinux.eu>
# Date 1272496856 -7200
# Node ID ab65e0695c3941c364d642b51ba59b247c8fa5c2
# Parent  d42910531b648556b0473dd6c07f7896476a8bc5
expose py.code._reinterpret functions so that pypy and internal
uses don't need to go through internal implementation imports

--- a/testing/code/test_assertion.py
+++ b/testing/code/test_assertion.py
@@ -1,7 +1,5 @@
 import py
 
-#pytestmark = py.test.mark.skipif("sys.platform.startswith('java')")
-
 def exvalue():
     return py.std.sys.exc_info()[1]
 
@@ -201,3 +199,7 @@ class TestView:
         assert codelines == ["4 + 5", "getitem('', 'join')", 
             "setattr('x', 'y', 3)", "12 - 1"]
 
+def test_underscore_api():
+    py.code._AssertionError
+    py.code._reinterpret_old # used by pypy
+    py.code._reinterpret

--- a/py/_plugin/pytest_assertion.py
+++ b/py/_plugin/pytest_assertion.py
@@ -8,9 +8,6 @@ def pytest_addoption(parser):
         help="disable python assert expression reinterpretation."),
 
 def pytest_configure(config):
-    #if sys.platform.startswith("java"):
-    #    return # XXX assertions don't work yet with jython 2.5.1
-
     if not config.getvalue("noassert") and not config.getvalue("nomagic"):
         warn_about_missing_assertion()
         config._oldassertion = py.builtin.builtins.AssertionError

--- a/py/_code/code.py
+++ b/py/_code/code.py
@@ -199,9 +199,8 @@ class TracebackEntry(object):
         """Reinterpret the failing statement and returns a detailed information
            about what operations are performed."""
         if self.exprinfo is None:
-            from py._code import assertion 
             source = str(self.statement).strip()
-            x = assertion.interpret(source, self.frame, should_fail=True)
+            x = py.code._reinterpret(source, self.frame, should_fail=True)
             if not isinstance(x, str):
                 raise TypeError("interpret returned non-string %r" % (x,))
             self.exprinfo = x 

--- a/py/_code/assertion.py
+++ b/py/_code/assertion.py
@@ -37,12 +37,6 @@ def _format_explanation(explanation):
     return '\n'.join(result)
 
 
-if sys.version_info >= (2, 6) or (sys.platform.startswith("java")):
-    from py._code._assertionnew import interpret
-else:
-    from py._code._assertionold import interpret
-
-
 class AssertionError(BuiltinAssertionError):
 
     def __init__(self, *args):
@@ -65,7 +59,7 @@ class AssertionError(BuiltinAssertionErr
                 # this can also occur during reinterpretation, when the
                 # co_filename is set to "<run>".
             if source:
-                self.msg = interpret(source, f, should_fail=True)
+                self.msg = reinterpret(source, f, should_fail=True)
                 if not self.args:
                     self.args = (self.msg,)
             else:
@@ -73,3 +67,11 @@ class AssertionError(BuiltinAssertionErr
 
 if sys.version_info > (3, 0):
     AssertionError.__module__ = "builtins"
+    reinterpret_old = "old reinterpretation not available for py3"
+else:
+    from py._code._assertionold import interpret as reinterpret_old
+if sys.version_info >= (2, 6) or (sys.platform.startswith("java")):
+    from py._code._assertionnew import interpret as reinterpret
+else:
+    reinterpret = reinterpret_old
+    

--- a/py/__init__.py
+++ b/py/__init__.py
@@ -98,6 +98,8 @@ py.apipkg.initpkg(__name__, dict(
         'patch_builtins'    : '._code.code:patch_builtins',
         'unpatch_builtins'  : '._code.code:unpatch_builtins',
         '_AssertionError'   : '._code.assertion:AssertionError',
+        '_reinterpret_old'  : '._code.assertion:reinterpret_old',
+        '_reinterpret'      : '._code.assertion:reinterpret',
     },
 
     # backports and additions of builtins
_______________________________________________
py-svn mailing list
py-svn@codespeak.net
http://codespeak.net/mailman/listinfo/py-svn

Reply via email to