[pypy-commit] pypy default: move from/tobytes tests to correct class

2018-02-04 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
Branch: 
Changeset: r93746:ec3f718627ff
Date: 2018-02-03 22:43 +0100
http://bitbucket.org/pypy/pypy/changeset/ec3f718627ff/

Log:move from/tobytes tests to correct class

diff --git a/rpython/rlib/test/test_rbigint.py 
b/rpython/rlib/test/test_rbigint.py
--- a/rpython/rlib/test/test_rbigint.py
+++ b/rpython/rlib/test/test_rbigint.py
@@ -686,6 +686,47 @@
 assert rbigint.fromlong(2).log(2.0) == 1.0
 assert rbigint.fromlong(2**1023).log(2.0) == 1023.0
 
+def test_frombytes(self):
+bigint = rbigint.frombytes('', byteorder='big', signed=True)
+assert bigint.tolong() == 0
+s = "\xFF\x12\x34\x56"
+bigint = rbigint.frombytes(s, byteorder="big", signed=False)
+assert bigint.tolong() == 0xFF123456
+bigint = rbigint.frombytes(s, byteorder="little", signed=False)
+assert bigint.tolong() == 0x563412FF
+s = "\xFF\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\xFF"
+bigint = rbigint.frombytes(s, byteorder="big", signed=False)
+assert s == bigint.tobytes(16, byteorder="big", signed=False)
+py.test.raises(InvalidEndiannessError, bigint.frombytes, '\xFF', 'foo',
+   signed=True)
+bigint = rbigint.frombytes('\x82', byteorder='big', signed=True)
+assert bigint.tolong() == -126
+
+def test_tobytes(self):
+assert rbigint.fromint(0).tobytes(1, 'big', signed=True) == '\x00'
+assert rbigint.fromint(1).tobytes(2, 'big', signed=True) == '\x00\x01'
+py.test.raises(OverflowError, rbigint.fromint(255).tobytes, 1, 'big', 
signed=True)
+assert rbigint.fromint(-129).tobytes(2, 'big', signed=True) == 
'\xff\x7f'
+assert rbigint.fromint(-129).tobytes(2, 'little', signed=True) == 
'\x7f\xff'
+assert rbigint.fromint(65535).tobytes(3, 'big', signed=True) == 
'\x00\xff\xff'
+assert rbigint.fromint(-65536).tobytes(3, 'little', signed=True) == 
'\x00\x00\xff'
+assert rbigint.fromint(65535).tobytes(2, 'big', signed=False) == 
'\xff\xff'
+assert rbigint.fromint(-8388608).tobytes(3, 'little', signed=True) == 
'\x00\x00\x80'
+i = rbigint.fromint(-8388608)
+py.test.raises(InvalidEndiannessError, i.tobytes, 3, 'foo', 
signed=True)
+py.test.raises(InvalidSignednessError, i.tobytes, 3, 'little', 
signed=False)
+py.test.raises(OverflowError, i.tobytes, 2, 'little', signed=True)
+
+@given(strategies.binary(), strategies.booleans(), strategies.booleans())
+def test_frombytes_tobytes_hypothesis(self, s, big, signed):
+# check the roundtrip from binary strings to bigints and back
+byteorder = 'big' if big else 'little'
+bigint = rbigint.frombytes(s, byteorder=byteorder, signed=signed)
+t = bigint.tobytes(len(s), byteorder=byteorder, signed=signed)
+assert s == t
+
+
+
 class TestInternalFunctions(object):
 def test__inplace_divrem1(self):
 # signs are not handled in the helpers!
@@ -950,45 +991,6 @@
 res = interpret(fn, [])
 assert res == -42.0
 
-def test_frombytes(self):
-bigint = rbigint.frombytes('', byteorder='big', signed=True)
-assert bigint.tolong() == 0
-s = "\xFF\x12\x34\x56"
-bigint = rbigint.frombytes(s, byteorder="big", signed=False)
-assert bigint.tolong() == 0xFF123456
-bigint = rbigint.frombytes(s, byteorder="little", signed=False)
-assert bigint.tolong() == 0x563412FF
-s = "\xFF\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\xFF"
-bigint = rbigint.frombytes(s, byteorder="big", signed=False)
-assert s == bigint.tobytes(16, byteorder="big", signed=False)
-py.test.raises(InvalidEndiannessError, bigint.frombytes, '\xFF', 'foo',
-   signed=True)
-bigint = rbigint.frombytes('\x82', byteorder='big', signed=True)
-assert bigint.tolong() == -126
-
-def test_tobytes(self):
-assert rbigint.fromint(0).tobytes(1, 'big', signed=True) == '\x00'
-assert rbigint.fromint(1).tobytes(2, 'big', signed=True) == '\x00\x01'
-py.test.raises(OverflowError, rbigint.fromint(255).tobytes, 1, 'big', 
signed=True)
-assert rbigint.fromint(-129).tobytes(2, 'big', signed=True) == 
'\xff\x7f'
-assert rbigint.fromint(-129).tobytes(2, 'little', signed=True) == 
'\x7f\xff'
-assert rbigint.fromint(65535).tobytes(3, 'big', signed=True) == 
'\x00\xff\xff'
-assert rbigint.fromint(-65536).tobytes(3, 'little', signed=True) == 
'\x00\x00\xff'
-assert rbigint.fromint(65535).tobytes(2, 'big', signed=False) == 
'\xff\xff'
-assert rbigint.fromint(-8388608).tobytes(3, 'little', signed=True) == 
'\x00\x00\x80'
-i = rbigint.fromint(-8388608)
-py.test.raises(InvalidEndiannessError, i.tobytes, 3, 'foo', 
signed=True)
-py.test.raises(InvalidSignednessError, i.tobytes, 3, 'little', 
signed=False)
-py.t

[pypy-commit] pypy default: tests for rbigint.ne

2018-02-04 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
Branch: 
Changeset: r93745:25474c7af9f3
Date: 2018-02-04 12:08 +0100
http://bitbucket.org/pypy/pypy/changeset/25474c7af9f3/

Log:tests for rbigint.ne

diff --git a/rpython/rlib/test/test_rbigint.py 
b/rpython/rlib/test/test_rbigint.py
--- a/rpython/rlib/test/test_rbigint.py
+++ b/rpython/rlib/test/test_rbigint.py
@@ -141,6 +141,7 @@
 r2 = op1 ** op2
 assert r1.tolong() == r2
 
+
 def test_touint(self):
 result = r_uint(sys.maxint + 42)
 rl = rbigint.fromint(sys.maxint).add(rbigint.fromint(42))
@@ -358,7 +359,7 @@
 null = rbigint.fromfloat(-0.0)
 assert null.int_eq(0)
 
-def test_eq(self):
+def test_eq_ne(self):
 x = 5858393919192332223L
 y = 58583939191923311122332332L
 f1 = rbigint.fromlong(x)
@@ -370,6 +371,12 @@
 assert not f1.eq(f2)
 assert not f1.eq(f3)
 
+assert not f1.ne(f1)
+assert not f2.ne(f2)
+assert not f3.ne(f3)
+assert f1.ne(f2)
+assert f1.ne(f3)
+
 def test_eq_fastpath(self):
 x = 1234
 y = 1234
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: remove unreachable code (it's covered by the if a.sign == 0 just above)

2018-02-04 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
Branch: 
Changeset: r93748:4c9182daefc7
Date: 2018-02-04 12:30 +0100
http://bitbucket.org/pypy/pypy/changeset/4c9182daefc7/

Log:remove unreachable code (it's covered by the if a.sign == 0 just
above)

diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -695,9 +695,7 @@
 return NULLRBIGINT
 
 if asize == 1:
-if a._digits[0] == NULLDIGIT:
-return NULLRBIGINT
-elif a._digits[0] == ONEDIGIT:
+if a._digits[0] == ONEDIGIT:
 return rbigint(b._digits[:b.size], a.sign * b.sign, b.size)
 elif bsize == 1:
 res = b.widedigit(0) * a.widedigit(0)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: more thorough tests for add, sub

2018-02-04 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
Branch: 
Changeset: r93749:0c05843a6356
Date: 2018-02-04 12:51 +0100
http://bitbucket.org/pypy/pypy/changeset/0c05843a6356/

Log:more thorough tests for add, sub

diff --git a/rpython/rlib/test/test_rbigint.py 
b/rpython/rlib/test/test_rbigint.py
--- a/rpython/rlib/test/test_rbigint.py
+++ b/rpython/rlib/test/test_rbigint.py
@@ -71,10 +71,10 @@
 
 def test_floordiv(self):
 for op1 in gen_signs(long_vals):
+rl_op1 = rbigint.fromlong(op1)
 for op2 in gen_signs(long_vals):
 if not op2:
 continue
-rl_op1 = rbigint.fromlong(op1)
 rl_op2 = rbigint.fromlong(op2)
 r1 = rl_op1.floordiv(rl_op2)
 r2 = op1 // op2
@@ -82,10 +82,10 @@
 
 def test_truediv(self):
 for op1 in gen_signs(long_vals_not_too_big):
+rl_op1 = rbigint.fromlong(op1)
 for op2 in gen_signs(long_vals):
 if not op2:
 continue
-rl_op1 = rbigint.fromlong(op1)
 rl_op2 = rbigint.fromlong(op2)
 r1 = rl_op1.truediv(rl_op2)
 r2 = op1 / op2
@@ -266,36 +266,32 @@
 assert rbigint._from_numberstring_parser(parser).tolong() == 1231231241
 
 def test_add(self):
-x = 12345678912345678900L
-y = 123858582373821923936744221L
-for i in [-1, 1]:
-for j in [-1, 1]:
-f1 = rbigint.fromlong(x * i)
-f2 = rbigint.fromlong(y * j)
+for x in gen_signs(long_vals):
+f1 = rbigint.fromlong(x)
+for y in gen_signs(long_vals):
+f2 = rbigint.fromlong(y)
 result = f1.add(f2)
-assert result.tolong() == x * i + y * j
+assert result.tolong() == x + y
 
 def test_int_add(self):
 for x in gen_signs(long_vals):
+f1 = rbigint.fromlong(x)
 for y in signed_int_vals:
-f1 = rbigint.fromlong(x)
 result = f1.int_add(y)
 assert result.tolong() == x + y
 
 def test_sub(self):
-x = 12378959520302182384345L
-y = 88961284756491823819191823L
-for i in [-1, 1]:
-for j in [-1, 1]:
-f1 = rbigint.fromlong(x * i)
-f2 = rbigint.fromlong(y * j)
+for x in gen_signs(long_vals):
+f1 = rbigint.fromlong(x)
+for y in gen_signs(long_vals):
+f2 = rbigint.fromlong(y)
 result = f1.sub(f2)
-assert result.tolong() == x * i - y * j
+assert result.tolong() == x - y
 
 def test_int_sub(self):
-for x in gen_signs([0, 12345678912345678900L, 1 << 100, 3 ** 
1]):
+for x in gen_signs(long_vals):
+f1 = rbigint.fromlong(x)
 for y in signed_int_vals:
-f1 = rbigint.fromlong(x)
 result = f1.int_sub(y)
 assert result.tolong() == x - y
 
@@ -316,8 +312,8 @@
 
 def test_int_mul(self):
 for x in gen_signs(long_vals):
+f1 = rbigint.fromlong(x)
 for y in signed_int_vals:
-f1 = rbigint.fromlong(x)
 result = f1.int_mul(y)
 assert result.tolong() == x * y
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: remove unused argument (and uncovered condition)

2018-02-04 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
Branch: 
Changeset: r93750:cfcbece09877
Date: 2018-02-04 13:00 +0100
http://bitbucket.org/pypy/pypy/changeset/cfcbece09877/

Log:remove unused argument (and uncovered condition)

diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -1823,16 +1823,14 @@
 ret._normalize()
 return ret
 
-def _inplace_divrem1(pout, pin, n, size=0):
+def _inplace_divrem1(pout, pin, n):
 """
 Divide bigint pin by non-zero digit n, storing quotient
 in pout, and returning the remainder. It's OK for pin == pout on entry.
 """
 rem = _widen_digit(0)
 assert n > 0 and n <= MASK
-if not size:
-size = pin.numdigits()
-size -= 1
+size = pin.numdigits() - 1
 while size >= 0:
 rem = (rem << SHIFT) | pin.widedigit(size)
 hi = rem // n
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: merge heads

2018-02-04 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
Branch: 
Changeset: r93753:03e7d032c07f
Date: 2018-02-04 13:52 +0100
http://bitbucket.org/pypy/pypy/changeset/03e7d032c07f/

Log:merge heads

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
@@ -23,3 +23,16 @@
 added, then the performance using mapdict is linear in the number of
 attributes. This is now fixed (by switching to a regular dict after 80
 attributes).
+
+
+.. branch: cpyext-faster-arg-passing
+
+When using cpyext, improve the speed of passing certain objects from PyPy to C
+code, most notably None, True, False, types, all instances of C-defined types.
+Before, a dict lookup was needed every time such an object crossed over, now it
+is just a field read.
+
+
+.. branch: 2634_datetime_timedelta_performance
+
+Improve datetime + timedelta performance.
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -208,6 +208,21 @@
 def _set_mapdict_storage_and_map(self, storage, map):
 raise NotImplementedError
 
+
+# ---
+# cpyext support
+# these functions will only be seen by the annotator if we translate
+# with the cpyext module
+
+def _cpyext_as_pyobj(self, space):
+from pypy.module.cpyext.pyobject import w_root_as_pyobj
+return w_root_as_pyobj(self, space)
+
+def _cpyext_attach_pyobj(self, space, py_obj):
+from pypy.module.cpyext.pyobject import w_root_attach_pyobj
+return w_root_attach_pyobj(self, space, py_obj)
+
+
 # ---
 
 def is_w(self, space, w_other):
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
@@ -1,6 +1,6 @@
 import pytest
 try:
-from hypothesis import given, strategies as st
+from hypothesis import given, strategies as st, settings
 except ImportError:
 pytest.skip("hypothesis required")
 import os
@@ -29,6 +29,7 @@
 
 @given(data=st_readline(),
mode=st.sampled_from(['\r', '\n', '\r\n', '']))
+@settings(deadline=None)
 def test_readline(space, data, mode):
 txt, limits = data
 w_stream = W_BytesIO(space)
diff --git a/pypy/module/cpyext/pyobject.py b/pypy/module/cpyext/pyobject.py
--- a/pypy/module/cpyext/pyobject.py
+++ b/pypy/module/cpyext/pyobject.py
@@ -10,6 +10,8 @@
 PyVarObject, Py_ssize_t, init_function, cts)
 from pypy.module.cpyext.state import State
 from pypy.objspace.std.typeobject import W_TypeObject
+from pypy.objspace.std.noneobject import W_NoneObject
+from pypy.objspace.std.boolobject import W_BoolObject
 from pypy.objspace.std.objectobject import W_ObjectObject
 from rpython.rlib.objectmodel import specialize, we_are_translated
 from rpython.rlib.objectmodel import keepalive_until_here
@@ -21,6 +23,52 @@
 #
 # type description
 
+class W_BaseCPyObject(W_ObjectObject):
+""" A subclass of W_ObjectObject that has one field for directly storing
+the link from the w_obj to the cpy ref. This is only used for C-defined
+types. """
+
+
+def check_true(s_arg, bookeeper):
+assert s_arg.const is True
+
+def w_root_as_pyobj(w_obj, space):
+from rpython.rlib.debug import check_annotation
+# make sure that translation crashes if we see this while not translating
+# with cpyext
+check_annotation(space.config.objspace.usemodules.cpyext, check_true)
+# default implementation of _cpyext_as_pyobj
+return rawrefcount.from_obj(PyObject, w_obj)
+
+def w_root_attach_pyobj(w_obj, space, py_obj):
+from rpython.rlib.debug import check_annotation
+check_annotation(space.config.objspace.usemodules.cpyext, check_true)
+assert space.config.objspace.usemodules.cpyext
+# default implementation of _cpyext_attach_pyobj
+rawrefcount.create_link_pypy(w_obj, py_obj)
+
+
+def add_direct_pyobj_storage(cls):
+""" Add the necessary methods to a class to store a reference to the py_obj
+on its instances directly. """
+
+cls._cpy_ref = lltype.nullptr(PyObject.TO)
+
+def _cpyext_as_pyobj(self, space):
+return self._cpy_ref
+cls._cpyext_as_pyobj = _cpyext_as_pyobj
+
+def _cpyext_attach_pyobj(self, space, py_obj):
+self._cpy_ref = py_obj
+rawrefcount.create_link_pyobj(self, py_obj)
+cls._cpyext_attach_pyobj = _cpyext_attach_pyobj
+
+add_direct_pyobj_storage(W_BaseCPyObject)
+add_direct_pyobj_storage(W_TypeObject)
+add_direct_pyobj_storage(W_NoneObject)
+add_direct_pyobj_storage(W_BoolObject)
+
+
 class BaseCpyTypedescr(object):
 basestruct = PyObject.TO
 W_BaseObject = W_ObjectObject
@@ -66,8 +114,12 @@
 
 def realize(self, sp

[pypy-commit] pypy default: test various errors

2018-02-04 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
Branch: 
Changeset: r93751:31873397de08
Date: 2018-02-04 13:10 +0100
http://bitbucket.org/pypy/pypy/changeset/31873397de08/

Log:test various errors

diff --git a/rpython/rlib/test/test_rbigint.py 
b/rpython/rlib/test/test_rbigint.py
--- a/rpython/rlib/test/test_rbigint.py
+++ b/rpython/rlib/test/test_rbigint.py
@@ -84,9 +84,10 @@
 for op1 in gen_signs(long_vals_not_too_big):
 rl_op1 = rbigint.fromlong(op1)
 for op2 in gen_signs(long_vals):
+rl_op2 = rbigint.fromlong(op2)
 if not op2:
+py.test.raises(ZeroDivisionError, rl_op1.truediv, rl_op2)
 continue
-rl_op2 = rbigint.fromlong(op2)
 r1 = rl_op1.truediv(rl_op2)
 r2 = op1 / op2
 assert r1 == r2
@@ -586,7 +587,7 @@
 assert f1.tolong() == x
 
 def test_bitwise(self):
-for x in gen_signs([0, 1, 5, 11, 42, 43, 3 ** 30]):
+for x in gen_signs(long_vals):
 for y in gen_signs([0, 1, 5, 11, 42, 43, 3 ** 30, 3 ** 31]):
 lx = rbigint.fromlong(x)
 ly = rbigint.fromlong(y)
@@ -679,9 +680,10 @@
 def test_log(self):
 from rpython.rlib.rfloat import ulps_check
 for op in long_vals:
-if not op:
-continue
 for base in [0, 2, 4, 8, 16, 10, math.e]:
+if not op:
+py.test.raises(ValueError, rbigint.fromlong(op).log, base)
+continue
 l = rbigint.fromlong(op).log(base)
 if base:
 assert ulps_check(l, math.log(op, base)) is None
@@ -786,7 +788,7 @@
 Rx = 1 << 130
 Rx2 = 1 << 150
 Ry = 1 << 127
-Ry2 = 1<< 150
+Ry2 = 1 << 150
 for i in range(10):
 x = long(randint(Rx, Rx2))
 y = long(randint(Ry, Ry2))
@@ -796,7 +798,7 @@
 _div, _rem = divmod(x, y)
 assert div.tolong() == _div
 assert rem.tolong() == _rem
-
+
 def test_divmod(self):
 x = 12345678901234567890L
 for i in range(100):
@@ -812,6 +814,7 @@
 _div, _rem = divmod(sx, sy)
 assert div.tolong() == _div
 assert rem.tolong() == _rem
+py.test.raises(ZeroDivisionError, rbigint.fromlong(x).divmod, 
rbigint.fromlong(0))
 
 # testing Karatsuba stuff
 def test__v_iadd(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: improve coverage of bitwise operators

2018-02-04 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
Branch: 
Changeset: r93752:a52fa839d674
Date: 2018-02-04 13:50 +0100
http://bitbucket.org/pypy/pypy/changeset/a52fa839d674/

Log:improve coverage of bitwise operators

diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -2548,6 +2548,8 @@
 maska ^= MASK
 maskb ^= MASK
 negz = -1
+else:
+assert 0, "unreachable"
 
 # JRH: The original logic here was to allocate the result value (z)
 # as the longer of the two operands.  However, there are some cases
diff --git a/rpython/rlib/test/test_rbigint.py 
b/rpython/rlib/test/test_rbigint.py
--- a/rpython/rlib/test/test_rbigint.py
+++ b/rpython/rlib/test/test_rbigint.py
@@ -588,8 +588,8 @@
 
 def test_bitwise(self):
 for x in gen_signs(long_vals):
-for y in gen_signs([0, 1, 5, 11, 42, 43, 3 ** 30, 3 ** 31]):
-lx = rbigint.fromlong(x)
+lx = rbigint.fromlong(x)
+for y in gen_signs(long_vals):
 ly = rbigint.fromlong(y)
 for mod in "xor and_ or_".split():
 res1 = getattr(lx, mod)(ly).tolong()
@@ -597,11 +597,9 @@
 assert res1 == res2
 
 def test_int_bitwise(self):
-for x in gen_signs([0, 1, 5, 11, 42, 43, 2 ** 30]):
-for y in gen_signs([0, 1, 5, 11, 42, 43, 3 ** 30, 2 ** 31]):
-if y != intmask(y):
-continue  # skip 'y' too large for 32-bit
-lx = rbigint.fromlong(x)
+for x in gen_signs(long_vals):
+lx = rbigint.fromlong(x)
+for y in signed_int_vals:
 for mod in "xor and_ or_".split():
 res1 = getattr(lx, 'int_' + mod)(y).tolong()
 res2 = getattr(operator, mod)(x, y)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: be a lot more systematic about testing the rbigint.int_* variants. This

2018-02-04 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
Branch: 
Changeset: r93747:f225421c6b26
Date: 2018-02-03 23:22 +0100
http://bitbucket.org/pypy/pypy/changeset/f225421c6b26/

Log:be a lot more systematic about testing the rbigint.int_* variants.
This increases test coverage

diff --git a/rpython/rlib/test/test_rbigint.py 
b/rpython/rlib/test/test_rbigint.py
--- a/rpython/rlib/test/test_rbigint.py
+++ b/rpython/rlib/test/test_rbigint.py
@@ -17,15 +17,31 @@
 
 from hypothesis import given, strategies
 
+def gen_signs(l):
+for s in l:
+if s == 0:
+yield s
+else:
+yield s
+yield -s
+
 long_vals_not_too_big = range(17) + [
-37, 50,
+37, 39, 50,
 127, 128, 129, 511, 512, 513, sys.maxint, sys.maxint + 1,
+12345678901234567890L,
 12345678912345678900L,
-]
+]
 
 long_vals = long_vals_not_too_big + [
 1 << 100, 3 ** 1]
 
+int_vals = range(33) + [
+1000,
+0x, 0x1112, ,
+, sys.maxint, 2 ** 19, 2 ** 18 - 1
+]
+signed_int_vals = list(gen_signs(int_vals)) + [-sys.maxint-1]
+
 class TestRLong(object):
 def test_simple(self):
 for op1 in [-2, -1, 0, 1, 2, 50]:
@@ -121,12 +137,14 @@
 rl_op2 = rbigint.fromlong(op2)
 r1 = rl_op1.mod(rl_op2)
 r2 = op1 % op2
-print op1, op2
+
 assert r1.tolong() == r2
 
 def test_int_mod(self):
 for x in gen_signs(long_vals):
-for y in gen_signs([1, 2, 4, 8, , sys.maxint, 2 ** 19, 2 ** 18 
- 1]):
+for y in signed_int_vals:
+if not y:
+continue
 op1 = rbigint.fromlong(x)
 r1 = op1.int_mod(y)
 r2 = x % y
@@ -158,13 +176,6 @@
 assert not (a1 == a3)
 
 
-def gen_signs(l):
-for s in l:
-if s == 0:
-yield s
-else:
-yield s
-yield -s
 
 def bigint(lst, sign):
 for digit in lst:
@@ -266,7 +277,7 @@
 
 def test_int_add(self):
 for x in gen_signs(long_vals):
-for y in gen_signs([0, 1, , sys.maxint, 2 ** 19, 2 ** 18 - 1]):
+for y in signed_int_vals:
 f1 = rbigint.fromlong(x)
 result = f1.int_add(y)
 assert result.tolong() == x + y
@@ -283,7 +294,7 @@
 
 def test_int_sub(self):
 for x in gen_signs([0, 12345678912345678900L, 1 << 100, 3 ** 
1]):
-for y in gen_signs([0, 1, , sys.maxint, 2 ** 19, 2 ** 18 - 1]):
+for y in signed_int_vals:
 f1 = rbigint.fromlong(x)
 result = f1.int_sub(y)
 assert result.tolong() == x - y
@@ -304,8 +315,8 @@
 assert result.tolong() == x * x
 
 def test_int_mul(self):
-for x in gen_signs([39, 128, 1, 12345678912345678900L, 1 
<< 100, 3 ** 1]):
-for y in gen_signs([0, 1, , sys.maxint, 2 ** 19, 2 ** 18 - 1]):
+for x in gen_signs(long_vals):
+for y in signed_int_vals:
 f1 = rbigint.fromlong(x)
 result = f1.int_mul(y)
 assert result.tolong() == x * y
@@ -394,14 +405,14 @@
 
 def test_int_comparison(self):
 for x in gen_signs(long_vals):
-for y in gen_signs([0, 1, 0x, 0x1112, , 
sys.maxint, 2 ** 19, 2 ** 18 - 1]):
+for y in signed_int_vals:
 f1 = rbigint.fromlong(x)
-assert (x < y) ==  f1.int_lt(y)
-assert (x <= y) ==  f1.int_le(y)
-assert (x > y) ==  f1.int_gt(y)
-assert (x >= y) ==  f1.int_ge(y)
-assert (x == y) ==  f1.int_eq(y)
-assert (x != y) ==  f1.int_ne(y)
+assert (x < y) == f1.int_lt(y)
+assert (x <= y) == f1.int_le(y)
+assert (x > y) == f1.int_gt(y)
+assert (x >= y) == f1.int_ge(y)
+assert (x == y) == f1.int_eq(y)
+assert (x != y) == f1.int_ne(y)
 
 def test_order(self):
 f6 = rbigint.fromint(6)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy math-improvements: merge default

2018-02-04 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
Branch: math-improvements
Changeset: r93754:4f4cee77f1c2
Date: 2018-02-04 13:56 +0100
http://bitbucket.org/pypy/pypy/changeset/4f4cee77f1c2/

Log:merge default

diff too long, truncating to 2000 out of 92474 lines

diff --git a/.hgtags b/.hgtags
--- a/.hgtags
+++ b/.hgtags
@@ -44,3 +44,10 @@
 d72f9800a42b46a8056951b1da2426d2c2d8d502 release-pypy3.5-v5.9.0
 03d614975835870da65ff0481e1edad68ebbcb8d release-pypy2.7-v5.9.0
 84a2f3e6a7f88f2fe698e473998755b3bd1a12e2 release-pypy2.7-v5.9.0
+0e7ea4fe15e82d5124e805e2e4a37cae1a402d4b release-pypy2.7-v5.10.0
+a91df6163fb76df245091f741dbf6a23ddc72374 release-pypy3.5-v5.10.0
+a91df6163fb76df245091f741dbf6a23ddc72374 release-pypy3.5-v5.10.0
+ release-pypy3.5-v5.10.0
+ release-pypy3.5-v5.10.0
+09f9160b643e3f02ccb8c843b2fbb4e5cbf54082 release-pypy3.5-v5.10.0
+3f6eaa010fce78cc7973bdc1dfdb95970f08fed2 release-pypy3.5-v5.10.1
diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -30,7 +30,7 @@
 DEALINGS IN THE SOFTWARE.
 
 
-PyPy Copyright holders 2003-2017
+PyPy Copyright holders 2003-2018
 --- 
 
 Except when otherwise stated (look for LICENSE files or information at
@@ -339,8 +339,10 @@
   Stanisław Halik
   Julien Phalip
   Roman Podoliaka
+  Steve Papanik
   Eli Stevens
   Boglarka Vezer
+  gabrielg
   PavloKapyshin
   Tomer Chachamu
   Christopher Groskopf
@@ -363,11 +365,13 @@
   Konrad Delong
   Dinu Gherman
   pizi
+  Tomáš Pružina
   James Robert
   Armin Ronacher
   Diana Popa
   Mads Kiilerich
   Brett Cannon
+  Caleb Hattingh
   aliceinwire
   Zooko Wilcox-O Hearn
   James Lan
@@ -388,6 +392,7 @@
   Jason Madden
   Yaroslav Fedevych
   Even Wiik Thomassen
+  m...@funkyhat.org
   Stefan Marr
 
   Heinrich-Heine University, Germany 
diff --git a/extra_tests/requirements.txt b/extra_tests/requirements.txt
--- a/extra_tests/requirements.txt
+++ b/extra_tests/requirements.txt
@@ -1,2 +1,3 @@
 pytest
 hypothesis
+vmprof
diff --git a/extra_tests/test_json.py b/extra_tests/test_json.py
new file mode 100644
--- /dev/null
+++ b/extra_tests/test_json.py
@@ -0,0 +1,33 @@
+import pytest
+import json
+from hypothesis import given, strategies
+
+def is_(x, y):
+return type(x) is type(y) and x == y
+
+def test_no_ensure_ascii():
+assert is_(json.dumps(u"\u1234", ensure_ascii=False), u'"\u1234"')
+assert is_(json.dumps("\xc0", ensure_ascii=False), '"\xc0"')
+with pytest.raises(UnicodeDecodeError) as excinfo:
+json.dumps((u"\u1234", "\xc0"), ensure_ascii=False)
+assert str(excinfo.value).startswith(
+"'ascii' codec can't decode byte 0xc0 ")
+with pytest.raises(UnicodeDecodeError) as excinfo:
+json.dumps(("\xc0", u"\u1234"), ensure_ascii=False)
+assert str(excinfo.value).startswith(
+"'ascii' codec can't decode byte 0xc0 ")
+
+def test_issue2191():
+assert is_(json.dumps(u"xxx", ensure_ascii=False), u'"xxx"')
+
+jsondata = strategies.recursive(
+strategies.none() |
+strategies.booleans() |
+strategies.floats(allow_nan=False) |
+strategies.text(),
+lambda children: strategies.lists(children) |
+strategies.dictionaries(strategies.text(), children))
+
+@given(jsondata)
+def test_roundtrip(d):
+assert json.loads(json.dumps(d)) == d
diff --git a/extra_tests/test_textio.py b/extra_tests/test_textio.py
new file mode 100644
--- /dev/null
+++ b/extra_tests/test_textio.py
@@ -0,0 +1,48 @@
+from hypothesis import given, strategies as st
+
+from io import BytesIO, TextIOWrapper
+import os
+
+def translate_newlines(text):
+text = text.replace('\r\n', '\n')
+text = text.replace('\r', '\n')
+return text.replace('\n', os.linesep)
+
+@st.composite
+def st_readline_universal(
+draw, st_nlines=st.integers(min_value=0, max_value=10)):
+n_lines = draw(st_nlines)
+lines = draw(st.lists(
+st.text(st.characters(blacklist_characters='\r\n')),
+min_size=n_lines, max_size=n_lines))
+limits = []
+for line in lines:
+limit = draw(st.integers(min_value=0, max_value=len(line) + 5))
+limits.append(limit)
+limits.append(-1)
+endings = draw(st.lists(
+st.sampled_from(['\n', '\r', '\r\n']),
+min_size=n_lines, max_size=n_lines))
+return (
+''.join(line + ending for line, ending in zip(lines, endings)),
+limits)
+
+@given(data=st_readline_universal(),
+   mode=st.sampled_from(['\r', '\n', '\r\n', '', None]))
+def test_readline(data, mode):
+txt, limits = data
+textio = TextIOWrapper(
+BytesIO(txt.encode('utf-8', 'surrogatepass')),
+encoding='utf-8', errors='surrogatepass', newline=mode)
+lines = []
+for limit in limits:
+line = textio.readline(limit)
+if limit >= 0:
+assert len(line) <= limit
+if line:
+lines.append(line)
+elif limit:
+break
+