[pypy-commit] pypy py3tests: hg merge apptest-file
Author: Ronan Lamy Branch: py3tests Changeset: r96308:243d7e29848d Date: 2019-03-13 21:14 + http://bitbucket.org/pypy/pypy/changeset/243d7e29848d/ Log:hg merge apptest-file diff --git a/pypy/interpreter/mixedmodule.py b/pypy/interpreter/mixedmodule.py --- a/pypy/interpreter/mixedmodule.py +++ b/pypy/interpreter/mixedmodule.py @@ -79,8 +79,7 @@ if cls.applevel_name is not None: return cls.applevel_name else: -pkgroot = cls.__module__ -return pkgroot.split('.')[-1] +return cls.__module__.split('.')[-2] def get(self, name): space = self.space diff --git a/pypy/interpreter/test/test_appinterp.py b/pypy/interpreter/test/test_appinterp.py --- a/pypy/interpreter/test/test_appinterp.py +++ b/pypy/interpreter/test/test_appinterp.py @@ -129,6 +129,7 @@ assert name in module.__dict__ """) assert space.is_true(w_module.call('somefunc')) +assert Module.get_applevel_name() == 'demomixedmod' def test_whacking_at_loaders(self): """Some MixedModules change 'self.loaders' in __init__(), but doing ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3tests: hg merge apptest-file
Author: Ronan Lamy Branch: py3tests Changeset: r95354:c2e1ab58d77d Date: 2018-11-20 20:46 + http://bitbucket.org/pypy/pypy/changeset/c2e1ab58d77d/ Log:hg merge apptest-file diff --git a/pypy/module/_cffi_backend/test/test_c.py b/pypy/module/_cffi_backend/test/test_c.py --- a/pypy/module/_cffi_backend/test/test_c.py +++ b/pypy/module/_cffi_backend/test/test_c.py @@ -25,6 +25,8 @@ from rpython.translator.platform import host from rpython.translator.tool.cbuild import ExternalCompilationInfo +from .. import VERSION as TEST_VERSION + class AppTestC(object): """Populated below, hack hack hack.""" @@ -32,6 +34,15 @@ spaceconfig = dict(usemodules=('_cffi_backend', '_io', 'array')) def setup_class(cls): +if cls.runappdirect: +_cffi_backend = py.test.importorskip('_cffi_backend') +if _cffi_backend.__version__ != TEST_VERSION: +py.test.skip( +"These tests are for cffi version %s, this Python " +"has version %s installed" % +(TEST_VERSION, _cffi_backend.__version__)) + + testfuncs_w = [] keepalive_funcs = [] UniqueCache.for_testing = True diff --git a/pypy/module/_continuation/test/conftest.py b/pypy/module/_continuation/test/conftest.py --- a/pypy/module/_continuation/test/conftest.py +++ b/pypy/module/_continuation/test/conftest.py @@ -1,7 +1,7 @@ -import pytest import sys def pytest_configure(config): -if sys.platform.startswith('linux'): +if (not config.getoption('runappdirect') and +sys.platform.startswith('linux')): from rpython.rlib.rvmprof.cintf import configure_libbacktrace_linux configure_libbacktrace_linux() diff --git a/pypy/module/_cppyy/test/conftest.py b/pypy/module/_cppyy/test/conftest.py --- a/pypy/module/_cppyy/test/conftest.py +++ b/pypy/module/_cppyy/test/conftest.py @@ -41,6 +41,8 @@ disabled = None def pytest_configure(config): +if config.getoption('runappdirect'): +return if py.path.local.sysfind('genreflex') is None: import pypy.module._cppyy.capi.loadable_capi as lcapi try: diff --git a/pypy/module/cpyext/test/conftest.py b/pypy/module/cpyext/test/conftest.py --- a/pypy/module/cpyext/test/conftest.py +++ b/pypy/module/cpyext/test/conftest.py @@ -16,10 +16,9 @@ space = gettestobjspace(usemodules=['time']) space.getbuiltinmodule("time") -def pytest_ignore_collect(path, config): # ensure additional functions are registered import pypy.module.cpyext.test.test_cpyext -return False + def pytest_funcarg__api(request): return request.cls.api diff --git a/pypy/module/pypyjit/test/conftest.py b/pypy/module/pypyjit/test/conftest.py deleted file mode 100644 --- a/pypy/module/pypyjit/test/conftest.py +++ /dev/null @@ -1,7 +0,0 @@ -def pytest_addoption(parser): -group = parser.getgroup("pypyjit options") -group.addoption("--pypy", action="store", default=None, dest="pypy_c", -help="DEPRECATED: use this in test_pypy_c instead") -# XXX kill the corresponding section in the buildbot run, -# which (as far as I can tell) ignores that option entirely and does -# the same as the regular py.test. ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3tests: hg merge apptest-file
Author: Ronan Lamy Branch: py3tests Changeset: r95301:399533825dcd Date: 2018-11-12 21:17 + http://bitbucket.org/pypy/pypy/changeset/399533825dcd/ Log:hg merge apptest-file diff --git a/pypy/interpreter/test/demomixedmod/__init__.py b/pypy/interpreter/test/demomixedmod/__init__.py --- a/pypy/interpreter/test/demomixedmod/__init__.py +++ b/pypy/interpreter/test/demomixedmod/__init__.py @@ -1,15 +0,0 @@ -from pypy.interpreter.mixedmodule import MixedModule - -class Module(MixedModule): -interpleveldefs = { -'__name__' : '(space.wrap("mixedmodule"))', -'__doc__' : '(space.wrap("mixedmodule doc"))', -'somefunc' : 'file1.somefunc', -'value': '(space.w_None)', -'path' : 'file1.initpath(space)', -'cpypath' : 'space.wrap(sys.path)' -} - -appleveldefs = { -'someappfunc' : 'file2_app.someappfunc', -} diff --git a/pypy/interpreter/test/demomixedmod/__init__.py b/pypy/interpreter/test/demomixedmod/moduledef.py copy from pypy/interpreter/test/demomixedmod/__init__.py copy to pypy/interpreter/test/demomixedmod/moduledef.py diff --git a/pypy/interpreter/test/test_appinterp.py b/pypy/interpreter/test/test_appinterp.py --- a/pypy/interpreter/test/test_appinterp.py +++ b/pypy/interpreter/test/test_appinterp.py @@ -3,32 +3,32 @@ from pypy.interpreter.gateway import appdef, ApplevelClass, applevel_temp from pypy.interpreter.error import OperationError -def test_execwith_novars(space): -val = space.appexec([], """ -(): -return 42 -""") +def test_execwith_novars(space): +val = space.appexec([], """ +(): +return 42 +""") assert space.eq_w(val, space.wrap(42)) -def test_execwith_withvars(space): +def test_execwith_withvars(space): val = space.appexec([space.wrap(7)], """ -(x): -y = 6 * x -return y -""") +(x): +y = 6 * x +return y +""") assert space.eq_w(val, space.wrap(42)) -def test_execwith_compile_error(space): +def test_execwith_compile_error(space): excinfo = py.test.raises(OperationError, space.appexec, [], """ -(): -y y +(): +y y """) # NOTE: the following test only works because excinfo.value is not # normalized so far -assert str(excinfo.value.get_w_value(space)).find('y y') != -1 +assert str(excinfo.value.get_w_value(space)).find('y y') != -1 def test_simple_applevel(space): -app = appdef("""app(x,y): +app = appdef("""app(x,y): return x + y """) assert app.__name__ == 'app' @@ -36,15 +36,15 @@ assert space.eq_w(w_result, space.wrap(42)) def test_applevel_with_one_default(space): -app = appdef("""app(x,y=1): +app = appdef("""app(x,y=1): return x + y """) assert app.__name__ == 'app' -w_result = app(space, space.wrap(41)) +w_result = app(space, space.wrap(41)) assert space.eq_w(w_result, space.wrap(42)) def test_applevel_with_two_defaults(space): -app = appdef("""app(x=1,y=2): +app = appdef("""app(x=1,y=2): return x + y """) w_result = app(space, space.wrap(41), space.wrap(1)) @@ -58,19 +58,19 @@ def test_applevel_noargs(space): -app = appdef("""app(): -return 42 +app = appdef("""app(): +return 42 """) assert app.__name__ == 'app' -w_result = app(space) +w_result = app(space) assert space.eq_w(w_result, space.wrap(42)) -def somefunc(arg2=42): -return arg2 +def somefunc(arg2=42): +return arg2 -def test_app2interp_somefunc(space): -app = appdef(somefunc) -w_result = app(space) +def test_app2interp_somefunc(space): +app = appdef(somefunc) +w_result = app(space) assert space.eq_w(w_result, space.wrap(42)) def test_applevel_functions(space, applevel_temp = applevel_temp): @@ -87,45 +87,45 @@ def test_applevel_class(space, applevel_temp = applevel_temp): app = applevel_temp(''' class C(object): -clsattr = 42 -def __init__(self, x=13): -self.attr = x +clsattr = 42 +def __init__(self, x=13): +self.attr = x ''') C = app.interphook('C') -c = C(space, space.wrap(17)) +c = C(space, space.wrap(17)) w_attr = space.getattr(c, space.wrap('clsattr')) assert space.eq_w(w_attr, space.wrap(42)) w_clsattr = space.getattr(c, space.wrap('attr')) assert space.eq_w(w_clsattr, space.wrap(17)) -def app_test_something_at_app_level(): +def app_test_something_at_app_level(): x = 2 assert x/2 == 1 -class AppTestMethods: -def test_some_app_test_method(self): +class AppTestMethods: +def test_some_app_test_method(self): assert 2 == 2 -class TestMixedModule: -def test_accesses(self): +class TestMixedModule: +def test_accesses(self): space = self.space -import demomixedmod -
[pypy-commit] pypy py3tests: hg merge apptest-file
Author: Ronan LamyBranch: py3tests Changeset: r94343:77838bcabf15 Date: 2018-04-15 18:01 +0100 http://bitbucket.org/pypy/pypy/changeset/77838bcabf15/ Log:hg merge apptest-file diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py --- a/pypy/config/pypyoption.py +++ b/pypy/config/pypyoption.py @@ -252,6 +252,10 @@ BoolOption("newshortcut", "cache and shortcut calling __new__ from builtin types", default=False), +BoolOption("reinterpretasserts", + "Perform reinterpretation when an assert fails " + "(only relevant for tests)", + default=False), ]), ]) diff --git a/pypy/conftest.py b/pypy/conftest.py --- a/pypy/conftest.py +++ b/pypy/conftest.py @@ -132,10 +132,9 @@ """ def accept_regular_test(self): if self.config.option.runappdirect: -# only collect regular tests if we are in an 'app_test' directory, -# or in test_lib_pypy +# only collect regular tests if we are in test_lib_pypy for name in self.listnames(): -if "app_test" in name or "test_lib_pypy" in name: +if "test_lib_pypy" in name: return True return False return True diff --git a/pypy/tool/pytest/apptest.py b/pypy/tool/pytest/apptest.py --- a/pypy/tool/pytest/apptest.py +++ b/pypy/tool/pytest/apptest.py @@ -237,7 +237,7 @@ src = extract_docstring_if_empty_function(target) if self.config.option.runappdirect: return run_with_python(self.config.option.python, src, None) -space = gettestobjspace() +space = gettestobjspace(**{'objspace.std.reinterpretasserts': True}) filename = self._getdynfilename(target) func = app2interp_temp(src, filename=filename) # print "executing", func 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 @@ -7,7 +7,7 @@ _SPACECACHE={} def gettestobjspace(**kwds): -""" helper for instantiating and caching space's for testing. +""" helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) @@ -33,8 +33,9 @@ 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'), - appsupport.build_pytest_assertion(space)) +if config.objspace.std.reinterpretasserts: +space.setitem(space.builtin.w_dict, space.wrap('AssertionError'), +appsupport.build_pytest_assertion(space)) space.setitem(space.builtin.w_dict, space.wrap('raises'), space.wrap(appsupport.app_raises)) space.setitem(space.builtin.w_dict, space.wrap('skip'), diff --git a/pypy/tool/pytest/test/test_appsupport.py b/pypy/tool/pytest/test/test_appsupport.py --- a/pypy/tool/pytest/test/test_appsupport.py +++ b/pypy/tool/pytest/test/test_appsupport.py @@ -24,10 +24,16 @@ def test_method(self): pass """) +testdir.makepyfile(apptest_collection=""" +def test_app(): +pass +""") setpypyconftest(testdir) result = testdir.runpytest("--collectonly") assert result.ret == 0 result.stdout.fnmatch_lines([ +"*AppTestModule*apptest_collection*", +"*AppTestFunction*test_app*", "*Function*test_func*", "*Class*TestClassInt*", "*Function*test_method*", @@ -128,6 +134,47 @@ "*E*application-level*KeyError*42*", ]) +def test_apptest_raise(testdir): +setpypyconftest(testdir) +p = testdir.makepyfile(apptest_raise=""" +def test_raise(): +raise KeyError(42) +""") +result = testdir.runpytest(p) +assert result.ret == 1 +result.stdout.fnmatch_lines([ +"*E*application-level*KeyError*42*", +]) + +def test_apptest_fail_plain(testdir): +setpypyconftest(testdir) +p = testdir.makepyfile(apptest_fail=""" +def test_fail(): +x = 'foo' +assert x == 'bar' +""") +result = testdir.runpytest(p) +assert result.ret == 1 +result.stdout.fnmatch_lines([ +"*E*(application-level) AssertionError", +]) + +def test_apptest_fail_rewrite(testdir): +setpypyconftest(testdir) +p = testdir.makepyfile(apptest_fail_rewrite=""" +def test_fail(): +x = 'foo' +assert x == 'bar' +""") +result = testdir.runpytest(p, "--applevel-rewrite") +assert result.ret == 1 +result.stdout.fnmatch_lines([ +"*E*application-level*AssertionError: assert 'foo' == 'bar'", +"*E*- foo*", +"*E*+ bar*", +]) + + def app_test_raises(): info =
[pypy-commit] pypy py3tests: hg merge apptest-file
Author: Ronan LamyBranch: py3tests Changeset: r94340:8cfa4b755c8e Date: 2018-04-14 20:12 +0100 http://bitbucket.org/pypy/pypy/changeset/8cfa4b755c8e/ Log:hg merge apptest-file diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst --- a/pypy/doc/whatsnew-head.rst +++ b/pypy/doc/whatsnew-head.rst @@ -52,3 +52,13 @@ .. branch: refactor-slots Refactor cpyext slots. + + +.. branch: call-loopinvariant-into-bridges + +Speed up branchy code that does a lot of function inlining by saving one call +to read the TLS in most bridges. + +.. branch: rpython-sprint + +Refactor in rpython signatures diff --git a/pypy/interpreter/test/apptest_pyframe.py b/pypy/interpreter/test/apptest_pyframe.py --- a/pypy/interpreter/test/apptest_pyframe.py +++ b/pypy/interpreter/test/apptest_pyframe.py @@ -13,7 +13,7 @@ import sys f = sys._getframe() assert f.f_globals is globals() -raises(AttributeError, "f.f_globals = globals()") +pytest.raises(TypeError, "f.f_globals = globals()") def test_f_builtins(): import sys, builtins diff --git a/pypy/interpreter/test/fixtures.py b/pypy/interpreter/test/fixtures.py new file mode 100644 --- /dev/null +++ b/pypy/interpreter/test/fixtures.py @@ -0,0 +1,5 @@ +from _pytest.tmpdir import TempdirFactory + +def tempfile(space, config): +tmpdir = TempdirFactory(config).getbasetemp() +return space.newtext(str(tmpdir / 'tempfile1')) diff --git a/pypy/interpreter/test/test_pyframe.py b/pypy/interpreter/test/test_pyframe.py --- a/pypy/interpreter/test/test_pyframe.py +++ b/pypy/interpreter/test/test_pyframe.py @@ -1,4 +1,3 @@ -from rpython.tool import udir from pypy.conftest import option from pypy.interpreter.gateway import interp2app diff --git a/pypy/module/cpyext/frameobject.py b/pypy/module/cpyext/frameobject.py --- a/pypy/module/cpyext/frameobject.py +++ b/pypy/module/cpyext/frameobject.py @@ -82,10 +82,10 @@ def PyTraceBack_Here(space, w_frame): from pypy.interpreter.pytraceback import record_application_traceback state = space.fromcache(State) -if state.operror is None: +if state.get_exception() is None: return -1 frame = space.interp_w(PyFrame, w_frame) -record_application_traceback(space, state.operror, frame, 0) +record_application_traceback(space, state.get_exception(), frame, 0) return 0 @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL) diff --git a/pypy/module/cpyext/pyerrors.py b/pypy/module/cpyext/pyerrors.py --- a/pypy/module/cpyext/pyerrors.py +++ b/pypy/module/cpyext/pyerrors.py @@ -67,9 +67,10 @@ @cpython_api([], PyObject, result_borrowed=True) def PyErr_Occurred(space): state = space.fromcache(State) -if state.operror is None: +operror = state.get_exception() +if operror is None: return None -return state.operror.w_type # borrowed ref +return operror.w_type # borrowed ref @cpython_api([], lltype.Void) def PyErr_Clear(space): diff --git a/pypy/module/cpyext/state.py b/pypy/module/cpyext/state.py --- a/pypy/module/cpyext/state.py +++ b/pypy/module/cpyext/state.py @@ -2,11 +2,18 @@ from rpython.rtyper.lltypesystem import rffi, lltype from pypy.interpreter.error import OperationError, oefmt from pypy.interpreter import executioncontext +from pypy.interpreter.executioncontext import ExecutionContext from rpython.rtyper.annlowlevel import llhelper from rpython.rlib.rdynload import DLLHANDLE from rpython.rlib import rawrefcount import sys + +# Keep track of exceptions raised in cpyext for a particular execution +# context. +ExecutionContext.cpyext_operror = None + + class State: def __init__(self, space): self.space = space @@ -18,7 +25,8 @@ def reset(self): from pypy.module.cpyext.modsupport import PyMethodDef -self.operror = None +ec = self.space.getexecutioncontext() +ec.cpyext_operror = None self.new_method_def = lltype.nullptr(PyMethodDef) # When importing a package, use this to keep track @@ -37,17 +45,24 @@ def set_exception(self, operror): self.clear_exception() -self.operror = operror +ec = self.space.getexecutioncontext() +ec.cpyext_operror = operror def clear_exception(self): """Clear the current exception state, and return the operror.""" -operror = self.operror -self.operror = None +ec = self.space.getexecutioncontext() +operror = ec.cpyext_operror +ec.cpyext_operror = None return operror +def get_exception(self): +ec = self.space.getexecutioncontext() +return ec.cpyext_operror + @specialize.arg(1) def check_and_raise_exception(self, always=False): -operror = self.operror +ec = self.space.getexecutioncontext() +operror = ec.cpyext_operror if operror: self.clear_exception() raise operror diff --git