[pypy-commit] pypy py3.6: Emit warnings from unrelated older tests before catching the warnings from this precise test

2019-09-13 Thread arigo
Author: Armin Rigo 
Branch: py3.6
Changeset: r97473:b8f000ca2554
Date: 2019-09-13 20:31 +0200
http://bitbucket.org/pypy/pypy/changeset/b8f000ca2554/

Log:Emit warnings from unrelated older tests before catching the
warnings from this precise test

diff --git a/pypy/interpreter/test/apptest_coroutine.py 
b/pypy/interpreter/test/apptest_coroutine.py
--- a/pypy/interpreter/test/apptest_coroutine.py
+++ b/pypy/interpreter/test/apptest_coroutine.py
@@ -202,6 +202,7 @@
 import gc, warnings  # XXX: importing warnings is expensive untranslated
 async def foobaz():
 pass
+gc.collect()   # emit warnings from unrelated older tests
 with warnings.catch_warnings(record=True) as l:
 foobaz()
 gc.collect()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.6: merge default

2019-09-13 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
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):
-

[pypy-commit] pypy default: fix corner case about readline with limit that goes beyond the end of the string

2019-09-13 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
Branch: 
Changeset: r97471:6e25c50447f0
Date: 2019-09-13 11:21 +0200
http://bitbucket.org/pypy/pypy/changeset/6e25c50447f0/

Log:fix corner case about readline with limit that goes beyond the end
of the string

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
@@ -429,10 +429,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
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)
+@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)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit