[pypy-commit] pypy apptest-file: fixes
rlamy
pypy.commits at gmail.com
Fri Apr 13 16:39:36 EDT 2018
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: apptest-file
Changeset: r94314:808b8574832a
Date: 2018-04-13 21:37 +0100
http://bitbucket.org/pypy/pypy/changeset/808b8574832a/
Log: fixes
diff --git a/pypy/tool/pytest/appsupport.py b/pypy/tool/pytest/appsupport.py
--- a/pypy/tool/pytest/appsupport.py
+++ b/pypy/tool/pytest/appsupport.py
@@ -198,7 +198,7 @@
w_BuiltinAssertionError = space.getitem(space.builtin.w_dict,
space.wrap('AssertionError'))
w_metaclass = space.type(w_BuiltinAssertionError)
- w_init = space.wrap(gateway.interp2app_temp(my_init))
+ w_init = space.wrap(gateway.interp2app(my_init))
w_dict = space.newdict()
space.setitem(w_dict, space.wrap('__init__'), w_init)
return space.call_function(w_metaclass,
@@ -265,14 +265,14 @@
raise
raise oefmt(space.w_AssertionError, "DID NOT RAISE")
-app_raises = gateway.interp2app_temp(pypyraises)
+app_raises = gateway.interp2app(pypyraises)
def pypyskip(space, w_message):
"""skip a test at app-level. """
msg = space.unwrap(w_message)
py.test.skip(msg)
-app_skip = gateway.interp2app_temp(pypyskip)
+app_skip = gateway.interp2app(pypyskip)
def raises_w(space, w_ExpectedException, *args, **kwds):
try:
diff --git a/pypy/tool/pytest/apptest2.py b/pypy/tool/pytest/apptest2.py
--- a/pypy/tool/pytest/apptest2.py
+++ b/pypy/tool/pytest/apptest2.py
@@ -23,20 +23,21 @@
os.path.join(pypydir, 'tool', 'pytest', 'ast-rewriter'))
w_source = space.newtext(source)
fname = str(self.fspath)
+ w_name = space.newtext(str(self.fspath.purebasename))
w_fname = space.newtext(fname)
if self.rewrite_asserts:
- w_mod = space.appexec([w_rootdir, w_source, w_fname],
- """(rootdir, source, fname):
+ w_mod = space.appexec([w_rootdir, w_source, w_fname, w_name],
+ """(rootdir, source, fname, name):
import sys
sys.path.insert(0, rootdir)
from ast_rewrite import rewrite_asserts, create_module
co = rewrite_asserts(source, fname)
- mod = create_module(fname, co)
+ mod = create_module(name, co)
return mod
""")
else:
- w_mod = create_module(space, w_fname, fname, source)
+ w_mod = create_module(space, w_name, fname, source)
mod_dict = w_mod.getdict(space).unwrap(space)
items = []
for name, w_obj in mod_dict.items():
@@ -51,7 +52,7 @@
pass
def create_module(space, w_name, filename, source):
- w_mod = Module(space, w_name)
+ w_mod = Module(space, w_name, add_package=False)
w_dict = w_mod.getdict(space)
space.setitem(w_dict, space.newtext('__file__'), space.newtext(filename))
space.exec_(source, w_dict, w_dict, filename=filename)
@@ -83,10 +84,9 @@
def execute_appex(self, space, w_func):
space.getexecutioncontext().set_sys_exc_info(None)
sig = w_func.code._signature
- if sig.varargname or sig.kwargname or sig.kwonlyargnames:
+ if sig.varargname or sig.kwargname:
raise ValueError(
- 'Test functions may not use *args, **kwargs or '
- 'keyword-only args')
+ 'Test functions may not use *args or **kwargs')
args_w = self.get_fixtures(space, sig.argnames)
try:
space.call_function(w_func, *args_w)
diff --git a/pypy/tool/pytest/ast-rewriter/ast_rewrite.py b/pypy/tool/pytest/ast-rewriter/ast_rewrite.py
--- a/pypy/tool/pytest/ast-rewriter/ast_rewrite.py
+++ b/pypy/tool/pytest/ast-rewriter/ast_rewrite.py
@@ -3,14 +3,21 @@
import ast
import itertools
import marshal
-import struct
import sys
-from ast_util import assertrepr_compare, format_explanation as _format_explanation
+from ast_util import callbinrepr, format_explanation as _format_explanation
# pytest caches rewritten pycs in __pycache__.
-PYTEST_TAG = sys.implementation.cache_tag + "-PYTEST"
+if hasattr(sys, "pypy_version_info"):
+ impl = "pypy"
+elif sys.platform == "java":
+ impl = "jython"
+else:
+ impl = "cpython"
+ver = sys.version_info
+PYTEST_TAG = "%s-%s%s-PYTEST" % (impl, ver[0], ver[1])
+del ver, impl
PYC_EXT = ".py" + (__debug__ and "c" or "o")
PYC_TAIL = "." + PYTEST_TAG + PYC_EXT
@@ -29,6 +36,7 @@
# import. However, there's little reason deviate, and I hope
# sometime to be able to use imp.load_compiled to load them. (See
# the comment in load_module above.)
+ import struct
try:
fp = open(pyc, "wb")
except IOError:
@@ -91,6 +99,7 @@
Return rewritten code if successful or None if not.
"""
+ import struct
try:
fp = open(pyc, "rb")
except IOError:
@@ -161,7 +170,7 @@
done = True
if done:
break
- custom = assertrepr_compare(ops[i], each_obj[i], each_obj[i + 1])
+ custom = callbinrepr(ops[i], each_obj[i], each_obj[i + 1])
if custom is not None:
return custom
return expl
diff --git a/pypy/tool/pytest/ast-rewriter/ast_util.py b/pypy/tool/pytest/ast-rewriter/ast_util.py
--- a/pypy/tool/pytest/ast-rewriter/ast_util.py
+++ b/pypy/tool/pytest/ast-rewriter/ast_util.py
@@ -10,6 +10,15 @@
_reprcompare = None
+# the re-encoding is needed for python2 repr
+# with non-ascii characters (see issue 877 and 1379)
+def ecu(s):
+ try:
+ return u(s, 'utf-8', 'replace')
+ except TypeError:
+ return s
+
+
def format_explanation(explanation):
"""This formats an explanation
@@ -20,6 +29,7 @@
for when one explanation needs to span multiple lines, e.g. when
displaying diffs.
"""
+ explanation = ecu(explanation)
lines = _split_explanation(explanation)
result = _format_lines(lines)
return '\n'.join(result)
@@ -90,6 +100,13 @@
s = s[:maxsize]
return s
+def callbinrepr(op, left, right):
+ new_expl = assertrepr_compare(op, left, right)
+ new_expl = [line.replace("\n", "\\n") for line in new_expl]
+ res = "\n~".join(new_expl)
+ res = res.replace("%", "%%")
+ return res
+
def assertrepr_compare(op, left, right, verbose=False):
"""Return specialised explanations for some operators/operands"""
diff --git a/pypy/tool/pytest/objspace.py b/pypy/tool/pytest/objspace.py
--- a/pypy/tool/pytest/objspace.py
+++ b/pypy/tool/pytest/objspace.py
@@ -30,6 +30,7 @@
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
+ config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
space = make_objspace(config)
space.startup() # Initialize all builtin modules
space.setitem(space.builtin.w_dict, space.wrap('AssertionError'),
More information about the pypy-commit
mailing list