[pypy-commit] pypy py3.6: merge default
cfbolz
pypy.commits at gmail.com
Fri Sep 13 07:01:10 EDT 2019
Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch: py3.6
Changeset: r97472:6e832892a7f7
Date: 2019-09-13 13:00 +0200
http://bitbucket.org/pypy/pypy/changeset/6e832892a7f7/
Log: merge default
diff --git a/pypy/config/test/test_pypyoption.py b/pypy/config/test/test_pypyoption.py
--- a/pypy/config/test/test_pypyoption.py
+++ b/pypy/config/test/test_pypyoption.py
@@ -8,14 +8,13 @@
def test_required():
conf = get_pypy_config()
assert not conf.translating
-
assert conf.objspace.usemodules.gc
def test_conflicting_gcrootfinder():
conf = get_pypy_config()
conf.translation.gc = "boehm"
- py.test.raises(ConfigError, "conf.translation.gcrootfinder = 'asmgcc'")
-
+ with py.test.raises(ConfigError):
+ conf.translation.gcrootfinder = 'asmgcc'
def test_frameworkgc():
for name in ["minimark", "semispace"]:
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,8 @@
import sys
f = sys._getframe()
assert f.f_globals is globals()
- pytest.raises(AttributeError, "f.f_globals = globals()")
+ with pytest.raises(AttributeError):
+ f.f_globals = globals()
def test_f_builtins():
import sys, builtins
diff --git a/pypy/interpreter/test/test_function.py b/pypy/interpreter/test/test_function.py
--- a/pypy/interpreter/test/test_function.py
+++ b/pypy/interpreter/test/test_function.py
@@ -160,7 +160,8 @@
return 41
assert f() == 42
assert g() == 41
- raises(TypeError, "f.__code__ = 1")
+ with raises(TypeError):
+ f.__code__ = 1
f.__code__ = g.__code__
assert f() == 41
def get_h(f=f):
@@ -168,14 +169,17 @@
return f() # a closure
return h
h = get_h()
- raises(ValueError, "f.__code__ = h.__code__")
+ with raises(ValueError):
+ f.__code__ = h.__code__
@pytest.mark.skipif("config.option.runappdirect")
def test_write_code_builtin_forbidden(self):
def f(*args):
return 42
- raises(TypeError, "dir.__code__ = f.__code__")
- raises(TypeError, "list.append.__code__ = f.__code__")
+ with raises(TypeError):
+ dir.__code__ = f.__code__
+ with raises(TypeError):
+ list.append.__code__ = f.__code__
def test_set_module_to_name_eagerly(self):
skip("fails on PyPy but works on CPython. Unsure we want to care")
@@ -313,19 +317,10 @@
def func(self, **kw):
return self, kw
func = A().func
-
- # don't want the extra argument passing of raises
- try:
+ with raises(TypeError):
func(self=23)
- assert False
- except TypeError:
- pass
-
- try:
+ with raises(TypeError):
func(**{'self': 23})
- assert False
- except TypeError:
- pass
def test_kwargs_confusing_name(self):
def func(self): # 'self' conflicts with the interp-level
diff --git a/pypy/interpreter/test/test_nestedscope.py b/pypy/interpreter/test/test_nestedscope.py
--- a/pypy/interpreter/test/test_nestedscope.py
+++ b/pypy/interpreter/test/test_nestedscope.py
@@ -99,7 +99,8 @@
x = 1
g = f()
- raises(ValueError, "g.__closure__[0].cell_contents")
+ with raises(ValueError):
+ g.__closure__[0].cell_contents
def test_compare_cells(self):
def f(n):
diff --git a/pypy/interpreter/test/test_raise.py b/pypy/interpreter/test/test_raise.py
--- a/pypy/interpreter/test/test_raise.py
+++ b/pypy/interpreter/test/test_raise.py
@@ -2,9 +2,8 @@
class AppTestRaise:
def test_arg_as_string(self):
- def f():
+ with raises(TypeError):
raise "test"
- raises(TypeError, f)
def test_control_flow(self):
try:
@@ -36,9 +35,8 @@
assert isinstance(e, IndexError)
def test_raise_cls(self):
- def f():
+ with raises(IndexError):
raise IndexError
- raises(IndexError, f)
def test_raise_cls_catch(self):
def f(r):
@@ -46,7 +44,8 @@
raise r
except LookupError:
return 1
- raises(Exception, f, Exception)
+ with raises(Exception):
+ f(Exception)
assert f(IndexError) == 1
def test_raise_wrong(self):
@@ -99,7 +98,7 @@
assert sys.exc_info() == (None, None, None)
def test_reraise_1(self):
- raises(IndexError, """
+ with raises(IndexError):
import sys
try:
raise ValueError
@@ -109,10 +108,10 @@
finally:
assert sys.exc_info()[0] is IndexError
raise
- """)
+
def test_reraise_2(self):
- raises(IndexError, """
+ with raises(IndexError):
def foo():
import sys
assert sys.exc_info()[0] is IndexError
@@ -124,10 +123,10 @@
raise IndexError
finally:
foo()
- """)
+
def test_reraise_3(self):
- raises(IndexError, """
+ with raises(IndexError):
def spam():
import sys
try:
@@ -142,7 +141,6 @@
raise IndexError
finally:
spam()
- """)
def test_reraise_4(self):
import sys
@@ -156,7 +154,7 @@
assert ok
def test_reraise_5(self):
- raises(IndexError, """
+ with raises(IndexError):
import sys
try:
raise ValueError
@@ -170,17 +168,16 @@
finally:
assert sys.exc_info()[0] is IndexError
assert sys.exc_info()[2].tb_next is some_traceback
- """)
def test_nested_reraise(self):
- raises(TypeError, """
+ with raises(TypeError):
def nested_reraise():
raise
try:
raise TypeError("foo")
except:
nested_reraise()
- """)
+
def test_with_reraise_1(self):
class Context:
@@ -196,7 +193,8 @@
with Context():
pass
raise
- raises(ValueError, "fn()")
+ with raises(ValueError):
+ fn()
def test_with_reraise_2(self):
@@ -213,23 +211,20 @@
with Context():
raise KeyError("caught")
raise
- raises(ValueError, "fn()")
+ with raises(ValueError):
+ fn()
def test_userclass(self):
# new-style classes can't be raised unless they inherit from
# BaseException
-
class A(object):
def __init__(self, x=None):
self.x = x
-
- def f():
+
+ with raises(TypeError):
raise A
- raises(TypeError, f)
-
- def f():
+ with raises(TypeError):
raise A(42)
- raises(TypeError, f)
def test_userclass_catch(self):
# classes can't be caught unless they inherit from BaseException
@@ -259,7 +254,7 @@
def test_catch_tuple(self):
class A(Exception):
pass
-
+
try:
raise ValueError
except (ValueError, A):
@@ -307,7 +302,9 @@
class MyException(Exception):
def __new__(cls, *args):
return object()
- raises(TypeError, "raise MyException")
+
+ with raises(TypeError):
+ raise MyException
def test_with_exit_True(self):
class X:
diff --git a/pypy/interpreter/test/test_syntax.py b/pypy/interpreter/test/test_syntax.py
--- a/pypy/interpreter/test/test_syntax.py
+++ b/pypy/interpreter/test/test_syntax.py
@@ -344,9 +344,6 @@
class AppTestWith:
def test_with_simple(self):
-
- s = """
-if 1:
class Context:
def __init__(self):
self.calls = list()
@@ -360,78 +357,28 @@
acontext = Context()
with acontext:
pass
- """
- ns = {}
- exec(s, ns)
- acontext = ns['acontext']
assert acontext.calls == '__enter__ __exit__'.split()
def test_compound_with(self):
- s = """class Context:
- def __init__(self, var):
- self.record = []
- self.var = var
- def __enter__(self):
- self.record.append(("__enter__", self.var))
- return self.var
- def __exit__(self, tp, value, tb):
- self.record.append(("__exit__", self.var))
-c1 = Context("blah")
-c2 = Context("bling")
-with c1 as v1, c2 as v2:
- pass
- """
- ns = {}
- exec(s, ns)
- assert ns["v1"] == "blah"
- assert ns["v2"] == "bling"
- assert ns["c1"].record == [("__enter__", "blah"), ("__exit__", "blah")]
- assert ns["c2"].record == [("__enter__", "bling"),
- ("__exit__", "bling")]
-
-
- def test_start_with_blank_line(self):
- s = """
-if 1:
class Context:
- def __init__(self):
- self.calls = list()
-
+ def __init__(self, var):
+ self.record = []
+ self.var = var
def __enter__(self):
- self.calls.append('__enter__')
-
- def __exit__(self, exc_type, exc_value, exc_tb):
- self.calls.append('__exit__')
-
- acontext = Context()
- with acontext:
+ self.record.append(("__enter__", self.var))
+ return self.var
+ def __exit__(self, tp, value, tb):
+ self.record.append(("__exit__", self.var))
+ c1 = Context("blah")
+ c2 = Context("bling")
+ with c1 as v1, c2 as v2:
pass
-"""
- ns = {}
- exec(s, ns)
- acontext = ns['acontext']
- assert acontext.calls == '__enter__ __exit__'.split()
-
- def test_raw_doc_string(self):
- s = """r'doc'
-class Context(object):
- def __enter__(self):
- global enter
- enter = True
- def __exit__(self, *exc):
- global exit
- exit = True
-with Context() as w:
- pass"""
- ns = {}
- exec(s, ns)
- assert ns['enter']
- assert ns['exit']
+ assert v1 == "blah"
+ assert v2 == "bling"
+ assert c1.record == [("__enter__", "blah"), ("__exit__", "blah")]
+ assert c2.record == [("__enter__", "bling"), ("__exit__", "bling")]
def test_with_as_var(self):
-
- s = """
-if 1:
class Context:
def __init__(self):
self.calls = list()
@@ -448,17 +395,10 @@
with acontextfact as avar:
avar.append('__body__')
pass
- """
- ns = {}
- exec(s, ns)
- acontextfact = ns['acontextfact']
assert acontextfact.exit_params == (None, None, None)
assert acontextfact.calls == '__enter__ __body__ __exit__'.split()
def test_with_raise_exception(self):
-
- s = """
-if 1:
class Context:
def __init__(self):
self.calls = list()
@@ -482,20 +422,12 @@
pass
else:
raise AssertionError('With did not raise RuntimeError')
- """
- ns = {}
- exec(s, ns)
- acontextfact = ns['acontextfact']
- error = ns['error']
assert acontextfact.calls == '__enter__ __body__ __exit__'.split()
assert acontextfact.exit_params[0:2] == (RuntimeError, error)
import types
assert isinstance(acontextfact.exit_params[2], types.TracebackType)
def test_with_swallow_exception(self):
-
- s = """
-if 1:
class Context:
def __init__(self):
self.calls = list()
@@ -515,11 +447,6 @@
avar.append('__body__')
raise error
avar.append('__after_raise__')
- """
- ns = {}
- exec(s, ns)
- acontextfact = ns['acontextfact']
- error = ns['error']
assert acontextfact.calls == '__enter__ __body__ __exit__'.split()
assert acontextfact.exit_params[0:2] == (RuntimeError, error)
import types
@@ -544,9 +471,6 @@
assert c.calls == ['exit']
def test_with_break(self):
-
- s = """
-if 1:
class Context:
def __init__(self):
self.calls = list()
@@ -568,17 +492,10 @@
avar.append('__after_break__')
else:
raise AssertionError('Break failed with With, reached else clause')
- """
- ns = {}
- exec(s, ns)
- acontextfact = ns['acontextfact']
assert acontextfact.calls == '__enter__ __body__ __exit__'.split()
assert acontextfact.exit_params == (None, None, None)
def test_with_continue(self):
-
- s = """
-if 1:
class Context:
def __init__(self):
self.calls = list()
@@ -600,16 +517,10 @@
avar.append('__after_continue__')
else:
avar.append('__continue__')
- """
- ns = {}
- exec(s, ns)
- acontextfact = ns['acontextfact']
assert acontextfact.calls == '__enter__ __body__ __exit__ __continue__'.split()
assert acontextfact.exit_params == (None, None, None)
def test_with_return(self):
- s = """
-if 1:
class Context:
def __init__(self):
self.calls = list()
@@ -630,28 +541,16 @@
return '__return__'
avar.append('__after_return__')
acontextfact.calls.append(g(acontextfact))
- """
- ns = {}
- exec(s, ns)
- acontextfact = ns['acontextfact']
assert acontextfact.calls == '__enter__ __body__ __exit__ __return__'.split()
assert acontextfact.exit_params == (None, None, None)
def test_with_as_keyword(self):
- try:
+ with raises(SyntaxError):
exec("with = 9")
- except SyntaxError:
- pass
- else:
- assert False, 'Assignment to with did not raise SyntaxError'
def test_with_as_keyword_compound(self):
- try:
+ with raises(SyntaxError):
exec("from __future__ import generators, with_statement\nwith = 9")
- except SyntaxError:
- pass
- else:
- assert False, 'Assignment to with did not raise SyntaxError'
def test_missing_as_SyntaxError(self):
snippets = [
@@ -662,21 +561,10 @@
pass
"""]
for snippet in snippets:
- try:
+ with raises(SyntaxError):
exec(snippet)
- except SyntaxError:
- pass
- else:
- assert False, "%s: did not raise SyntaxError" % snippet
- def test_with_propagate_compileflag(self):
- s = """
-if 1:
- compile('''with x:
- pass''', '', 'exec')
- """
- exec(s)
class AppTestFunctionAnnotations:
@@ -707,7 +595,6 @@
pass
f1()
"""
-
class AppTestSyntaxError:
def test_tokenizer_error_location(self):
@@ -752,7 +639,8 @@
# -*- coding: uft-8 -*-
pass
"""
- raises(SyntaxError, exec, program)
+ with raises(SyntaxError):
+ exec(program)
'''
def test_exception_target_in_nested_scope(self):
@@ -798,24 +686,3 @@
raise AssertionError("should have raised")
"""
-
-if __name__ == '__main__':
- # only to check on top of CPython (you need 2.4)
- from py.test import raises
- for s in VALID:
- try:
- compile(s, '?', 'exec')
- except Exception as e:
- print '-'*20, 'FAILED TO COMPILE:', '-'*20
- print s
- print '%s: %s' % (e.__class__, e)
- print '-'*60
- for s in INVALID:
- try:
- raises(SyntaxError, compile, s, '?', 'exec')
- except Exception as e:
- print '-'*20, 'UNEXPECTEDLY COMPILED:', '-'*20
- print s
- print '%s: %s' % (e.__class__, e)
- print '-'*60
-
diff --git a/pypy/module/_io/interp_textio.py b/pypy/module/_io/interp_textio.py
--- a/pypy/module/_io/interp_textio.py
+++ b/pypy/module/_io/interp_textio.py
@@ -444,10 +444,9 @@
assert 0 <= ord(marker) < 128
# ascii fast path
if self.ulen == len(self.text):
- if limit < 0:
- end = len(self.text)
- else:
- end = self.pos + limit
+ end = len(self.text)
+ if limit >= 0:
+ end = min(end, self.pos + limit)
pos = self.pos
assert pos >= 0
assert end >= 0
@@ -868,8 +867,7 @@
end_scan = self.decoded.pos
uend_scan = self.decoded.upos
if end_scan > start:
- s = self.decoded.text[start:end_scan]
- builder.append_utf8(s, uend_scan - ustart)
+ builder.append_utf8_slice(self.decoded.text, start, end_scan, uend_scan - ustart)
if found or (limit >= 0 and builder.getlength() >= limit):
break
diff --git a/pypy/module/_io/test/test_interp_textio.py b/pypy/module/_io/test/test_interp_textio.py
--- a/pypy/module/_io/test/test_interp_textio.py
+++ b/pypy/module/_io/test/test_interp_textio.py
@@ -35,6 +35,7 @@
@given(data=st_readline(),
mode=st.sampled_from(['\r', '\n', '\r\n', '']))
@settings(deadline=None, database=None)
+ at example(data=(u'\n\r\n', [0, -1, 2, -1, 0, -1]), mode='\r')
def test_readline(space, data, mode):
txt, limits = data
w_stream = W_BytesIO(space)
diff --git a/rpython/rlib/rutf8.py b/rpython/rlib/rutf8.py
--- a/rpython/rlib/rutf8.py
+++ b/rpython/rlib/rutf8.py
@@ -772,6 +772,13 @@
self._lgt += length
@always_inline
+ def append_utf8_slice(self, utf8, start, end, slicelength):
+ self._s.append_slice(utf8, start, end)
+ self._lgt += slicelength
+ if not we_are_translated():
+ assert len(utf8[start: end].decode("utf-8")) == slicelength
+
+ @always_inline
def append_multiple_char(self, utf8, times):
self._s.append(utf8 * times)
self._lgt += times
diff --git a/rpython/rlib/test/test_rutf8.py b/rpython/rlib/test/test_rutf8.py
--- a/rpython/rlib/test/test_rutf8.py
+++ b/rpython/rlib/test/test_rutf8.py
@@ -211,6 +211,10 @@
s.append_code(0xD800)
assert s.getlength() == 5
+ s.append_utf8_slice(u"äöüß".encode("utf-8"), 2, 6, 2)
+ assert s.getlength() == 7
+ assert s.build().decode("utf-8") == u"abc\u1234\ud800öü"
+
def test_utf8_string_builder_bad_code():
s = rutf8.Utf8StringBuilder()
with pytest.raises(rutf8.OutOfRange):
More information about the pypy-commit
mailing list