[pypy-commit] pypy py3.6: merge heads
arigo
pypy.commits at gmail.com
Thu Nov 7 08:08:17 EST 2019
Author: Armin Rigo <arigo at tunes.org>
Branch: py3.6
Changeset: r97979:2a48a020ef28
Date: 2019-11-07 14:07 +0100
http://bitbucket.org/pypy/pypy/changeset/2a48a020ef28/
Log: merge heads
diff --git a/lib-python/3/test/test_dis.py b/lib-python/3/test/test_dis.py
--- a/lib-python/3/test/test_dis.py
+++ b/lib-python/3/test/test_dis.py
@@ -262,7 +262,7 @@
20 RETURN_VALUE
"""
-# XXX: change for PyPy?
+# changed for PyPy
dis_traceback = """\
%3d 0 SETUP_EXCEPT 12 (to 14)
@@ -280,18 +280,18 @@
22 POP_TOP
24 STORE_FAST 0 (e)
26 POP_TOP
- 28 SETUP_FINALLY 12 (to 42)
+ 28 SETUP_FINALLY 10 (to 40)
%3d 30 LOAD_FAST 0 (e)
32 LOAD_ATTR 1 (__traceback__)
34 STORE_FAST 1 (tb)
36 POP_BLOCK
- 38 POP_EXCEPT
- 40 LOAD_CONST 0 (None)
- >> 42 LOAD_CONST 0 (None)
- 44 STORE_FAST 0 (e)
- 46 DELETE_FAST 0 (e)
- 48 END_FINALLY
+ 38 LOAD_CONST 0 (None)
+ >> 40 LOAD_CONST 0 (None)
+ 42 STORE_FAST 0 (e)
+ 44 DELETE_FAST 0 (e)
+ 46 END_FINALLY
+ 48 POP_EXCEPT
50 JUMP_FORWARD 2 (to 54)
>> 52 END_FINALLY
@@ -686,9 +686,9 @@
# End fodder for opinfo generation tests
expected_outer_line = 1
_line_offset = outer.__code__.co_firstlineno - 1
-code_object_f = outer.__code__.co_consts[3]
+code_object_f = outer.__code__.co_consts[2]
expected_f_line = code_object_f.co_firstlineno - _line_offset
-code_object_inner = code_object_f.co_consts[3]
+code_object_inner = code_object_f.co_consts[2]
expected_inner_line = code_object_inner.co_firstlineno - _line_offset
expected_jumpy_line = 1
@@ -713,22 +713,22 @@
Instruction = dis.Instruction
expected_opinfo_outer = [
- Instruction(opname='LOAD_CONST', opcode=100, arg=8, argval=(3, 4), argrepr='(3, 4)', offset=0, starts_line=2, is_jump_target=False),
+ Instruction(opname='LOAD_CONST', opcode=100, arg=1, argval=(3, 4), argrepr='(3, 4)', offset=0, starts_line=2, is_jump_target=False),
Instruction(opname='LOAD_CLOSURE', opcode=135, arg=0, argval='a', argrepr='a', offset=2, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_CLOSURE', opcode=135, arg=1, argval='b', argrepr='b', offset=4, starts_line=None, is_jump_target=False),
Instruction(opname='BUILD_TUPLE', opcode=102, arg=2, argval=2, argrepr='', offset=6, starts_line=None, is_jump_target=False),
- Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=code_object_f, argrepr=repr(code_object_f), offset=8, starts_line=None, is_jump_target=False),
- Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='outer.<locals>.f', argrepr="'outer.<locals>.f'", offset=10, starts_line=None, is_jump_target=False),
+ Instruction(opname='LOAD_CONST', opcode=100, arg=2, argval=code_object_f, argrepr=repr(code_object_f), offset=8, starts_line=None, is_jump_target=False),
+ Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval='outer.<locals>.f', argrepr="'outer.<locals>.f'", offset=10, starts_line=None, is_jump_target=False),
Instruction(opname='MAKE_FUNCTION', opcode=132, arg=9, argval=9, argrepr='', offset=12, starts_line=None, is_jump_target=False),
Instruction(opname='STORE_FAST', opcode=125, arg=2, argval='f', argrepr='f', offset=14, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='print', argrepr='print', offset=16, starts_line=7, is_jump_target=False),
Instruction(opname='LOAD_DEREF', opcode=136, arg=0, argval='a', argrepr='a', offset=18, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_DEREF', opcode=136, arg=1, argval='b', argrepr='b', offset=20, starts_line=None, is_jump_target=False),
- Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval='', argrepr="''", offset=22, starts_line=None, is_jump_target=False),
- Instruction(opname='LOAD_CONST', opcode=100, arg=6, argval=1, argrepr='1', offset=24, starts_line=None, is_jump_target=False),
+ Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='', argrepr="''", offset=22, starts_line=None, is_jump_target=False),
+ Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval=1, argrepr='1', offset=24, starts_line=None, is_jump_target=False),
Instruction(opname='BUILD_LIST', opcode=103, arg=0, argval=0, argrepr='', offset=26, starts_line=None, is_jump_target=False),
Instruction(opname='BUILD_MAP', opcode=105, arg=0, argval=0, argrepr='', offset=28, starts_line=None, is_jump_target=False),
- Instruction(opname='LOAD_CONST', opcode=100, arg=7, argval='Hello world!', argrepr="'Hello world!'", offset=30, starts_line=None, is_jump_target=False),
+ Instruction(opname='LOAD_CONST', opcode=100, arg=6, argval='Hello world!', argrepr="'Hello world!'", offset=30, starts_line=None, is_jump_target=False),
Instruction(opname='CALL_FUNCTION', opcode=131, arg=7, argval=7, argrepr='', offset=32, starts_line=None, is_jump_target=False),
Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=34, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_FAST', opcode=124, arg=2, argval='f', argrepr='f', offset=36, starts_line=8, is_jump_target=False),
@@ -736,14 +736,14 @@
]
expected_opinfo_f = [
- Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval=(5, 6), argrepr='(5, 6)', offset=0, starts_line=3, is_jump_target=False),
+ Instruction(opname='LOAD_CONST', opcode=100, arg=1, argval=(5, 6), argrepr='(5, 6)', offset=0, starts_line=3, is_jump_target=False),
Instruction(opname='LOAD_CLOSURE', opcode=135, arg=2, argval='a', argrepr='a', offset=2, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_CLOSURE', opcode=135, arg=3, argval='b', argrepr='b', offset=4, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_CLOSURE', opcode=135, arg=0, argval='c', argrepr='c', offset=6, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_CLOSURE', opcode=135, arg=1, argval='d', argrepr='d', offset=8, starts_line=None, is_jump_target=False),
Instruction(opname='BUILD_TUPLE', opcode=102, arg=4, argval=4, argrepr='', offset=10, starts_line=None, is_jump_target=False),
- Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=code_object_inner, argrepr=repr(code_object_inner), offset=12, starts_line=None, is_jump_target=False),
- Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='outer.<locals>.f.<locals>.inner', argrepr="'outer.<locals>.f.<locals>.inner'", offset=14, starts_line=None, is_jump_target=False),
+ Instruction(opname='LOAD_CONST', opcode=100, arg=2, argval=code_object_inner, argrepr=repr(code_object_inner), offset=12, starts_line=None, is_jump_target=False),
+ Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval='outer.<locals>.f.<locals>.inner', argrepr="'outer.<locals>.f.<locals>.inner'", offset=14, starts_line=None, is_jump_target=False),
Instruction(opname='MAKE_FUNCTION', opcode=132, arg=9, argval=9, argrepr='', offset=16, starts_line=None, is_jump_target=False),
Instruction(opname='STORE_FAST', opcode=125, arg=2, argval='inner', argrepr='inner', offset=18, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='print', argrepr='print', offset=20, starts_line=5, is_jump_target=False),
diff --git a/lib-python/3/test/test_extcall.py b/lib-python/3/test/test_extcall.py
--- a/lib-python/3/test/test_extcall.py
+++ b/lib-python/3/test/test_extcall.py
@@ -57,7 +57,7 @@
Traceback (most recent call last):
...
TypeError: ...got multiple values for keyword argument 'a'
- >>> f(1, 2, a=3, **{'a': 4}, **{'a': 5})
+ >>> f(1, 2, a=3, **{'a': 4}, **{'a': 5}) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
TypeError: ...got multiple values for keyword argument 'a'
@@ -254,20 +254,21 @@
...
TypeError: h() argument after * must be an iterable, not function
- >>> h(*[1], *h)
+ >>> h(*[1], *h) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
- TypeError: h() argument after * must be an iterable, not function
+ TypeError: ...
>>> dir(*h)
Traceback (most recent call last):
...
TypeError: dir() argument after * must be an iterable, not function
- >>> None(*h)
+ >>> None(**h) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
- TypeError: ...argument after * must be an iterable, not function
+ TypeError: ... object argument after ** must be a mapping, \
+not function
>>> h(**h)
Traceback (most recent call last):
@@ -289,35 +290,20 @@
...
TypeError: h() argument after ** must be a mapping, not list
- >>> h(**{'a': 1}, **h)
+ >>> h(**{'a': 1}, **h) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
- TypeError: h() argument after ** must be a mapping, not function
+ TypeError: ...argument after ** must be a mapping, not function
- >>> h(**{'a': 1}, **[])
+ >>> h(**{'a': 1}, **[]) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
- TypeError: h() argument after ** must be a mapping, not list
+ TypeError: ...argument after ** must be a mapping, not list
>>> dir(**h)
Traceback (most recent call last):
...
- TypeError: ...argument after * must be an iterable, not function
-
- >>> None(*h) #doctest: +ELLIPSIS
- Traceback (most recent call last):
- ...
- TypeError: ...argument after * must be an iterable, not function
-
- >>> h(**h) #doctest: +ELLIPSIS
- Traceback (most recent call last):
- ...
- TypeError: ...argument after ** must be a mapping, not function
-
- >>> dir(**h) #doctest: +ELLIPSIS
- Traceback (most recent call last):
- ...
- TypeError: ...argument after ** must be a mapping, not function
+ TypeError: dir() argument after ** must be a mapping, not function
>>> None(**h) #doctest: +ELLIPSIS
Traceback (most recent call last):
diff --git a/lib-python/3/test/test_flufl.py b/lib-python/3/test/test_flufl.py
--- a/lib-python/3/test/test_flufl.py
+++ b/lib-python/3/test/test_flufl.py
@@ -15,7 +15,7 @@
self.assertEqual(cm.exception.text, '2 != 3\n')
self.assertEqual(cm.exception.filename, '<FLUFL test>')
self.assertEqual(cm.exception.lineno, 2)
- self.assertEqual(cm.exception.offset, 4)
+ self.assertEqual(cm.exception.offset, 2) # changed in PyPy
def test_guido_as_bdfl(self):
code = '2 {0} 3'
@@ -26,7 +26,7 @@
self.assertEqual(cm.exception.text, '2 <> 3\n')
self.assertEqual(cm.exception.filename, '<FLUFL test>')
self.assertEqual(cm.exception.lineno, 1)
- self.assertEqual(cm.exception.offset, 4)
+ self.assertEqual(cm.exception.offset, 2) # changed in PyPy
if __name__ == '__main__':
diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -218,10 +218,6 @@
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
@@ -135,8 +135,8 @@
return PyPyModule(path, parent)
def is_applevel(item):
- from pypy.tool.pytest.apptest import AppTestFunction
- return isinstance(item, AppTestFunction)
+ from pypy.tool.pytest.apptest import AppTestMethod
+ return isinstance(item, AppTestMethod)
def pytest_collection_modifyitems(config, items):
if config.getoption('runappdirect') or config.getoption('direct_apptest'):
@@ -166,8 +166,6 @@
def funcnamefilter(self, name):
if name.startswith('test_'):
return self.accept_regular_test()
- if name.startswith('app_test_'):
- return True
return False
def classnamefilter(self, name):
@@ -182,13 +180,6 @@
if name.startswith('AppTest'):
from pypy.tool.pytest.apptest import AppClassCollector
return AppClassCollector(name, parent=self)
-
- elif hasattr(obj, 'func_code') and self.funcnamefilter(name):
- if name.startswith('app_test_'):
- assert not obj.func_code.co_flags & 32, \
- "generator app level functions? you must be joking"
- from pypy.tool.pytest.apptest import AppTestFunction
- return AppTestFunction(name, parent=self)
return super(PyPyModule, self).makeitem(name, obj)
def skip_on_missing_buildoption(**ropts):
@@ -207,27 +198,15 @@
py.test.skip("need translated pypy3 with: %s, got %s"
%(ropts,options))
-class LazyObjSpaceGetter(object):
- def __get__(self, obj, cls=None):
- from pypy.tool.pytest.objspace import gettestobjspace
- space = gettestobjspace()
- if cls:
- cls.space = space
- return space
-
-
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, py.test.collect.Function):
appclass = item.getparent(py.test.Class)
if appclass is not None:
+ from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
- spaceconfig = getattr(appclass.obj, 'spaceconfig', None)
- if spaceconfig is not None:
- from pypy.tool.pytest.objspace import gettestobjspace
- appclass.obj.space = gettestobjspace(**spaceconfig)
- else:
- appclass.obj.space = LazyObjSpaceGetter()
+ spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
+ appclass.obj.space = gettestobjspace(**spaceconfig)
appclass.obj.runappdirect = option.runappdirect
def pytest_ignore_collect(path, config):
diff --git a/pypy/interpreter/astcompiler/astbuilder.py b/pypy/interpreter/astcompiler/astbuilder.py
--- a/pypy/interpreter/astcompiler/astbuilder.py
+++ b/pypy/interpreter/astcompiler/astbuilder.py
@@ -497,10 +497,10 @@
def handle_async_funcdef(self, node, decorators=None):
return self.handle_funcdef_impl(node.get_child(1), 1, decorators)
-
+
def handle_funcdef(self, node, decorators=None):
return self.handle_funcdef_impl(node, 0, decorators)
-
+
def handle_async_stmt(self, node):
ch = node.get_child(1)
if ch.type == syms.funcdef:
@@ -942,7 +942,7 @@
if flufl and comp_node.get_value() == '!=':
self.error("with Barry as BDFL, use '<>' instead of '!='", comp_node)
elif not flufl and comp_node.get_value() == '<>':
- self.error('invalid comparison', comp_node)
+ self.error('invalid syntax', comp_node)
return ast.NotEq
elif comp_type == tokens.NAME:
if comp_node.get_value() == "is":
@@ -1014,7 +1014,7 @@
atom_node.get_column())
else:
return atom_expr
-
+
def handle_power(self, power_node):
atom_expr = self.handle_atom_expr(power_node.get_child(0))
if power_node.num_children() == 1:
@@ -1092,7 +1092,7 @@
def handle_call(self, args_node, callable_expr):
arg_count = 0 # position args + iterable args unpackings
keyword_count = 0 # keyword args + keyword args unpackings
- generator_count = 0
+ generator_count = 0
for i in range(args_node.num_children()):
argument = args_node.get_child(i)
if argument.type == syms.argument:
@@ -1300,7 +1300,6 @@
if is_dict:
raise self.error("dict unpacking cannot be used in "
"dict comprehension", atom_node)
-
return self.handle_dictcomp(maker, atom_node)
else:
# a dictionary display
@@ -1423,7 +1422,7 @@
comps = self.comprehension_helper(dict_maker.get_child(i))
return ast.DictComp(key, value, comps, atom_node.get_lineno(),
atom_node.get_column())
-
+
def handle_dictdisplay(self, node, atom_node):
keys = []
values = []
@@ -1435,7 +1434,7 @@
i += 1
return ast.Dict(keys, values, atom_node.get_lineno(),
atom_node.get_column())
-
+
def handle_setdisplay(self, node, atom_node):
elts = []
i = 0
diff --git a/pypy/interpreter/astcompiler/codegen.py b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -393,6 +393,14 @@
self.emit_op_arg(ops.BUILD_CONST_KEY_MAP, l)
return l
+ def _visit_defaults(self, defaults):
+ w_tup = self._tuple_of_consts(defaults)
+ if w_tup:
+ self.load_const(w_tup)
+ else:
+ self.visit_sequence(defaults)
+ self.emit_op_arg(ops.BUILD_TUPLE, len(defaults))
+
@specialize.arg(2)
def _visit_function(self, func, function_code_generator):
self.update_position(func.lineno, True)
@@ -403,11 +411,10 @@
assert isinstance(args, ast.arguments)
oparg = 0
- self.visit_sequence(args.defaults)
if args.defaults is not None and len(args.defaults):
oparg = oparg | 0x01
- self.emit_op_arg(ops.BUILD_TUPLE, len(args.defaults))
+ self._visit_defaults(args.defaults)
if args.kwonlyargs:
kw_default_count = self._visit_kwonlydefaults(args)
@@ -438,12 +445,10 @@
args = lam.args
assert isinstance(args, ast.arguments)
- self.visit_sequence(args.defaults)
-
oparg = 0
if args.defaults is not None and len(args.defaults):
oparg = oparg | 0x01
- self.emit_op_arg(ops.BUILD_TUPLE, len(args.defaults))
+ self._visit_defaults(args.defaults)
if args.kwonlyargs:
kw_default_count = self._visit_kwonlydefaults(args)
diff --git a/pypy/interpreter/astcompiler/test/apptest_misc.py b/pypy/interpreter/astcompiler/test/apptest_misc.py
new file mode 100644
--- /dev/null
+++ b/pypy/interpreter/astcompiler/test/apptest_misc.py
@@ -0,0 +1,18 @@
+def test_warning_to_error_translation():
+ import warnings
+ statement = """\
+def wrong1():
+ a = 1
+ b = 2
+ global a
+ global b
+"""
+ with warnings.catch_warnings():
+ warnings.filterwarnings("error", module="<test string>")
+ try:
+ compile(statement, '<test string>', 'exec')
+ except SyntaxError as err:
+ assert err.lineno is not None
+ assert err.filename is not None
+ assert err.offset is not None
+ assert err.msg is not None
diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py b/pypy/interpreter/astcompiler/test/test_compiler.py
--- a/pypy/interpreter/astcompiler/test/test_compiler.py
+++ b/pypy/interpreter/astcompiler/test/test_compiler.py
@@ -1548,6 +1548,30 @@
counts = self.count_instructions(source)
assert ops.BUILD_TUPLE not in counts
+ def test_fold_defaults_tuple(self):
+ source = """def f():
+ def g(a, b=2, c=None, d='foo'):
+ return None
+ return g
+ """
+ counts = self.count_instructions(source)
+ assert ops.BUILD_TUPLE not in counts
+
+ source = """def f():
+ g = lambda a, b=2, c=None, d='foo': None
+ return g
+ """
+ counts = self.count_instructions(source)
+ assert ops.BUILD_TUPLE not in counts
+
+ source = """def f():
+ def g(a, b=2, c=None, d=[]):
+ return None
+ return g
+ """
+ counts = self.count_instructions(source)
+ assert counts[ops.BUILD_TUPLE] == 1
+
def test_constant_tuples_star(self):
source = """def f(a, c):
return (u"a", 1, *a, 3, 5, 3, *c)
diff --git a/pypy/interpreter/astcompiler/test/test_misc.py b/pypy/interpreter/astcompiler/test/test_misc.py
--- a/pypy/interpreter/astcompiler/test/test_misc.py
+++ b/pypy/interpreter/astcompiler/test/test_misc.py
@@ -43,26 +43,6 @@
Instruction(ops.LOAD_FAST, 0x5030201).encode(c)
assert c == [chr(ops.EXTENDED_ARG), '\x05', chr(ops.EXTENDED_ARG), '\x03', chr(ops.EXTENDED_ARG), '\x02', chr(ops.LOAD_FAST), '\x01']
-def app_test_warning_to_error_translation():
- import warnings
-
- with warnings.catch_warnings():
- warnings.filterwarnings("error", module="<test string>")
- statement = """\
-def wrong1():
- a = 1
- b = 2
- global a
- global b
-"""
- try:
- compile(statement, '<test string>', 'exec')
- except SyntaxError as err:
- assert err.lineno is not None
- assert err.filename is not None
- assert err.offset is not None
- assert err.msg is not None
-
def test_encode_lnotab_pair():
l = []
_encode_lnotab_pair(0, 1, l)
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
@@ -98,10 +98,6 @@
w_clsattr = space.getattr(c, space.wrap('attr'))
assert space.eq_w(w_clsattr, space.wrap(17))
-def app_test_something_at_app_level():
- x = 2
- assert x/2 == 1
-
class AppTestMethods:
def test_some_app_test_method(self):
assert 2 == 2
diff --git a/pypy/objspace/std/test/test_operation.py b/pypy/objspace/std/test/apptest_operation.py
rename from pypy/objspace/std/test/test_operation.py
rename to pypy/objspace/std/test/apptest_operation.py
--- a/pypy/objspace/std/test/test_operation.py
+++ b/pypy/objspace/std/test/apptest_operation.py
@@ -1,10 +1,11 @@
+from pytest import raises
+def teq(a, b):
+ assert a == b
+ assert type(a) is type(b)
-def app_test_int_vs_float():
- def teq(a, b):
- assert a == b
- assert type(a) is type(b)
+def test_int_vs_float():
# binary operators
teq( 5 - 2 , 3 )
teq( 5 - 2.0 , 3.0 )
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
@@ -1,7 +1,7 @@
# Collects and executes application-level tests.
#
-# Classes which names start with "AppTest", or function which names
-# start with "app_test*" are not executed by the host Python, but
+# Classes which names start with "AppTest"
+# are not executed by the host Python, but
# by an interpreted pypy object space.
#
# ...unless the -A option ('runappdirect') is passed.
@@ -232,7 +232,7 @@
return fn
-class AppTestFunction(py.test.collect.Function):
+class AppTestMethod(py.test.collect.Function):
def _prunetraceback(self, traceback):
return traceback
@@ -252,21 +252,10 @@
raise AppError, AppError(appexcinfo), tb
raise
- def runtest(self):
- target = self.obj
- src = extract_docstring_if_empty_function(target)
- if self.config.option.runappdirect:
- return run_with_python(self.config.option.python, src, None)
- space = gettestobjspace(**{'objspace.std.reinterpretasserts': True})
- filename = self._getdynfilename(target)
- func = app2interp_temp(src, filename=filename)
- # print "executing", func
- self.execute_appex(space, func, space)
-
def repr_failure(self, excinfo):
if excinfo.errisinstance(AppError):
excinfo = excinfo.value.excinfo
- return super(AppTestFunction, self).repr_failure(excinfo)
+ return super(AppTestMethod, self).repr_failure(excinfo)
def _getdynfilename(self, func):
code = getattr(func, 'im_func', func).func_code
@@ -279,8 +268,6 @@
if hasattr(self, 'space'):
self.space.getexecutioncontext()._run_finalizers_now()
-
-class AppTestMethod(AppTestFunction):
def setup(self):
super(AppTestMethod, self).setup()
instance = self.parent.obj
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
@@ -33,9 +33,6 @@
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
space = make_objspace(config)
space.startup() # Initialize all builtin modules
- 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/pypy_test_failure_demo.py b/pypy/tool/pytest/pypy_test_failure_demo.py
--- a/pypy/tool/pytest/pypy_test_failure_demo.py
+++ b/pypy/tool/pytest/pypy_test_failure_demo.py
@@ -1,39 +1,14 @@
-class AppTestTest:
+class AppTestTest:
def test_app_method(self):
- assert 42 == 41
+ assert 42 == 41
-def app_test_app_func():
- assert 41 == 42
-
-def test_interp_func(space):
- assert space.is_true(space.w_None)
+def test_interp_func(space):
+ assert space.is_true(space.w_None)
def test_interp_reinterpret(space):
a = 1
assert a == 2
-class TestInterpTest:
- def test_interp_method(self):
- assert self.space.is_true(self.space.w_False)
-
-def app_test_raises_in_statement():
- raises(ValueError, """
- y = x # name error
- """)
-
-def app_test_raises_something():
- int("hallo")
-
-def app_test_raises_wrong1():
- raises(SyntaxError, 'int("hello")')
-
-def app_test_raises_wrong2():
- raises(SyntaxError, int, "hello")
-
-def app_test_raises_doesnt():
- raises(ValueError, int, 3)
-
-def app_test_skip():
- skip("skipped test")
-
-
+class TestInterpTest:
+ def test_interp_method(self):
+ assert self.space.is_true(self.space.w_False)
diff --git a/pypy/tool/pytest/test/conftest1_innertest.py b/pypy/tool/pytest/test/conftest1_innertest.py
--- a/pypy/tool/pytest/test/conftest1_innertest.py
+++ b/pypy/tool/pytest/test/conftest1_innertest.py
@@ -1,17 +1,9 @@
-def test_something(space):
- assert space.w_None is space.w_None
+def test_something(space):
+ assert space.w_None is space.w_None
-def app_test_something():
- assert 42 == 42
-
-def app_test_code_in_docstring_failing():
- """
- assert False
- """
-
-class AppTestSomething:
- def test_method_app(self):
+class AppTestSomething:
+ def test_method_app(self):
assert 23 == 23
def test_code_in_docstring_failing(self):
@@ -26,12 +18,7 @@
"""
assert True
-
+
class TestSomething:
- def test_method(self):
- assert self.space
-
-def app_test_raise_in_a_closure():
- def f(x):
- raises(AttributeError, "x.foo")
- f(42)
+ def test_method(self):
+ assert self.space
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
@@ -77,8 +77,6 @@
def test_applevel_raises_simple_display(testdir):
setpypyconftest(testdir)
p = testdir.makepyfile("""
- def app_test_raises():
- raises(ValueError, x)
class AppTestRaises:
def test_func(self):
raises (ValueError, x)
@@ -87,7 +85,6 @@
result = testdir.runpytest(p, "-s")
assert result.ret == 1
result.stdout.fnmatch_lines([
- "*E*application-level*NameError*x*not defined",
"*test_func(self)*",
">*raises*ValueError*",
"*E*application-level*NameError*x*not defined",
@@ -99,37 +96,6 @@
"*E*application-level*NameError*x*not defined",
])
-def test_applevel_raises_display(testdir):
- setpypyconftest(testdir)
- p = testdir.makepyfile("""
- def app_test_raises():
- raises(ValueError, "x")
- pass
- """)
- result = testdir.runpytest(p, "-s")
- assert result.ret == 1
- result.stdout.fnmatch_lines([
- "*E*application-level*NameError*x*not defined",
- ])
- result = testdir.runpytest(p) # this time we may run the pyc file
- assert result.ret == 1
- result.stdout.fnmatch_lines([
- "*E*application-level*NameError*x*not defined",
- ])
-
-def test_applevel_raise_keyerror(testdir):
- setpypyconftest(testdir)
- p = testdir.makepyfile("""
- def app_test_raises():
- raise KeyError(42)
- pass
- """)
- result = testdir.runpytest(p, "-s")
- assert result.ret == 1
- result.stdout.fnmatch_lines([
- "*E*application-level*KeyError*42*",
- ])
-
def test_apptest_raise(testdir):
setpypyconftest(testdir)
p = testdir.makepyfile(apptest_raise="""
@@ -170,17 +136,6 @@
"*E*+ bar*",
])
-
-def app_test_raises():
- info = raises(TypeError, id)
- assert info.type is TypeError
- assert isinstance(info.value, TypeError)
-
- x = 43
- info = raises(ZeroDivisionError, "x/0")
- assert info.type is ZeroDivisionError
- assert isinstance(info.value, ZeroDivisionError)
-
def test_rename_module():
from pypy.tool.pytest.apptest import _rename_module
assert _rename_module("sys") == "sys"
diff --git a/pypy/tool/pytest/test/test_conftest1.py b/pypy/tool/pytest/test/test_conftest1.py
--- a/pypy/tool/pytest/test/test_conftest1.py
+++ b/pypy/tool/pytest/test/test_conftest1.py
@@ -41,10 +41,9 @@
def test_selection_by_keyword_app(self):
passed, failed = subproc_run("-m", "applevel -docstring", innertest)
- assert len(passed) == 4
- assert len(failed) == 2
- assert "app_test_something" in passed[0]
- assert "test_method_app" in passed[1]
+ assert len(passed) == 2
+ assert len(failed) == 1
+ assert "test_method_app" in passed[0]
def test_docstring_in_methods(self):
passed, failed = subproc_run("-k", "AppTestSomething and test_code_in_docstring",
@@ -54,12 +53,6 @@
assert "test_code_in_docstring_ignored" in passed[0]
assert "test_code_in_docstring_failing" in failed[0]
- def test_docstring_in_functions(self):
- passed, failed = subproc_run("-k", "app_test_code_in_docstring", innertest)
- assert passed == []
- assert len(failed) == 1
- assert "app_test_code_in_docstring_failing" in failed[0]
-
@py.test.mark.xfail(reason='fails on buildslave')
def test_docstring_runappdirect(self):
passed, failed = subproc_run(innertest,
diff --git a/pypy/tool/pytest/test/test_pytestsupport.py b/pypy/tool/pytest/test/test_pytestsupport.py
--- a/pypy/tool/pytest/test/test_pytestsupport.py
+++ b/pypy/tool/pytest/test/test_pytestsupport.py
@@ -6,21 +6,6 @@
pytest_plugins = "pytester"
-def app_test_exception():
- try:
- raise AssertionError("42")
- except AssertionError:
- pass
- else:
- raise AssertionError("app level AssertionError mixup!")
-
-def app_test_exception_with_message():
- try:
- assert 0, "Failed"
- except AssertionError as e:
- assert e.msg == "Failed"
-
-
def test_appexecinfo(space):
try:
space.appexec([], "(): raise ValueError")
More information about the pypy-commit
mailing list