expose py.code._reinterpret functions so that pypy and internal
uses don't need to go through internal implementation imports --HG-- branch : trunk
This commit is contained in:
		
							parent
							
								
									78d67c007b
								
							
						
					
					
						commit
						030548bc73
					
				|  | @ -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 | ||||
|  |  | |||
|  | @ -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(BuiltinAssertionError): | |||
|                 # 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(BuiltinAssertionError): | |||
| 
 | ||||
| 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 | ||||
|      | ||||
|  |  | |||
|  | @ -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  | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue