Author: Philip Jenvey <pjen...@underboss.org> Branch: py3k Changeset: r69747:10973dec5068 Date: 2014-03-05 17:12 -0800 http://bitbucket.org/pypy/pypy/changeset/10973dec5068/
Log: merge default 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 @@ -99,3 +99,6 @@ Implements SimpleRangeListStrategy for case range(n) where n is a positive number. Makes some traces nicer by getting rid of multiplication for calculating loop counter and propagates that n > 0 further to get rid of guards. + +.. branch: popen-pclose +Provide an exit status for popen'ed RFiles via pclose diff --git a/pypy/interpreter/special.py b/pypy/interpreter/special.py --- a/pypy/interpreter/special.py +++ b/pypy/interpreter/special.py @@ -2,16 +2,10 @@ class Ellipsis(W_Root): - def __init__(self, space): - self.space = space - - def descr__repr__(self): - return self.space.wrap('Ellipsis') + def descr__repr__(self, space): + return space.wrap('Ellipsis') class NotImplemented(W_Root): - def __init__(self, space): - self.space = space - - def descr__repr__(self): - return self.space.wrap('NotImplemented') + def descr__repr__(self, space): + return space.wrap('NotImplemented') diff --git a/pypy/module/micronumpy/compile.py b/pypy/module/micronumpy/compile.py --- a/pypy/module/micronumpy/compile.py +++ b/pypy/module/micronumpy/compile.py @@ -71,8 +71,8 @@ def __init__(self): """NOT_RPYTHON""" self.fromcache = InternalSpaceCache(self).getorbuild - self.w_Ellipsis = special.Ellipsis(self) - self.w_NotImplemented = special.NotImplemented(self) + self.w_Ellipsis = special.Ellipsis() + self.w_NotImplemented = special.NotImplemented() def _freeze_(self): return True diff --git a/pypy/module/micronumpy/test/test_ndarray.py b/pypy/module/micronumpy/test/test_ndarray.py --- a/pypy/module/micronumpy/test/test_ndarray.py +++ b/pypy/module/micronumpy/test/test_ndarray.py @@ -2319,6 +2319,16 @@ a[...] = 4 assert (a == [4, 4, 4]).all() + b = np.arange(24).reshape(2,3,4) + b[...] = 100 + assert (b == 100).all() + assert b.shape == (2, 3, 4) + b[...] = [10, 20, 30, 40] + assert (b[:,:,0] == 10).all() + assert (b[0,0,:] == [10, 20, 30, 40]).all() + assert b.shape == b[...].shape + assert (b == b[...]).all() + class AppTestNumArrayFromBuffer(BaseNumpyAppTest): spaceconfig = dict(usemodules=["micronumpy", "array", "mmap"]) diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py --- a/pypy/objspace/std/objspace.py +++ b/pypy/objspace/std/objspace.py @@ -59,8 +59,8 @@ self.w_None = W_NoneObject.w_None self.w_False = W_BoolObject.w_False self.w_True = W_BoolObject.w_True - self.w_NotImplemented = self.wrap(special.NotImplemented(self)) - self.w_Ellipsis = self.wrap(special.Ellipsis(self)) + self.w_NotImplemented = self.wrap(special.NotImplemented()) + self.w_Ellipsis = self.wrap(special.Ellipsis()) # types self.builtin_types = {} diff --git a/pypy/objspace/std/test/test_intobject.py b/pypy/objspace/std/test/test_intobject.py --- a/pypy/objspace/std/test/test_intobject.py +++ b/pypy/objspace/std/test/test_intobject.py @@ -543,10 +543,13 @@ assert a == 9007199254740991 a = operator.truediv(x, 7) assert a == 9007199254740991.0 - exec("from __future__ import division; " - "a = x / 7; b = operator.truediv(x, 7)") - assert a == 9007199254740991.0 - assert b == 9007199254740991.0 + + def test_truediv_future(self): + ns = dict(x=63050394783186940) + exec("from __future__ import division; import operator; " + "a = x / 7; b = operator.truediv(x, 7)", ns) + assert ns['a'] == 9007199254740991.0 + assert ns['b'] == 9007199254740991.0 class AppTestIntShortcut(AppTestInt): diff --git a/pypy/objspace/std/test/test_listobject.py b/pypy/objspace/std/test/test_listobject.py --- a/pypy/objspace/std/test/test_listobject.py +++ b/pypy/objspace/std/test/test_listobject.py @@ -433,7 +433,7 @@ intlist.find(w(4), 0, 2) -class AppTestW_ListObject(object): +class AppTestListObject(object): def setup_class(cls): import platform import sys @@ -526,6 +526,18 @@ l.__init__(assignment) assert l == list(assignment) + def test_range_init(self): + x = range(5,1) + assert x == [] + + x = range(1,10) + x[22:0:-1] == range(1,10) + + r = range(10, 10) + assert len(r) == 0 + assert list(reversed(r)) == [] + assert r[:] == [] + def test_extend_list(self): l = l0 = [1] l.extend([2]) @@ -598,24 +610,28 @@ def test_sort_key(self): def lower(x): return x.lower() l = ['a', 'C', 'b'] - l.sort(key = lower) + l.sort(key=lower) assert l == ['a', 'b', 'C'] l = [] - l.sort(key = lower) + l.sort(key=lower) assert l == [] - l = [ 'a' ] - l.sort(key = lower) - assert l == [ 'a' ] + l = ['a'] + l.sort(key=lower) + assert l == ['a'] + + r = range(10) + r.sort(key=lambda x: -x) + assert r == range(9, -1, -1) def test_sort_reversed(self): l = list(range(10)) - l.sort(reverse = True) + l.sort(reverse=True) assert l == list(range(9, -1, -1)) l = [] - l.sort(reverse = True) + l.sort(reverse=True) assert l == [] l = [1] - l.sort(reverse = True) + l.sort(reverse=True) assert l == [1] raises(TypeError, sorted, [], None, lambda x, y: 0) @@ -630,6 +646,17 @@ l.sort() assert l == ["a", "b", "c", "d"] + def test_sort_range(self): + l = range(3, 10, 3) + l.sort() + assert l == [3, 6, 9] + l.sort(reverse=True) + assert l == [9, 6, 3] + l.sort(reverse=True) + assert l == [9, 6, 3] + l.sort() + assert l == [3, 6, 9] + def test_getitem(self): l = [1, 2, 3, 4, 5, 6, 9] assert l[0] == 1 @@ -653,6 +680,23 @@ l = [] raises(IndexError, "l[1]") + def test_getitem_range(self): + l = range(5) + raises(IndexError, "l[-6]") + raises(IndexError, "l[5]") + assert l[0] == 0 + assert l[-1] == 4 + assert l[-2] == 3 + assert l[-5] == 0 + + l = range(1, 5) + raises(IndexError, "l[-5]") + raises(IndexError, "l[4]") + assert l[0] == 1 + assert l[-1] == 4 + assert l[-2] == 3 + assert l[-4] == 1 + def test_setitem(self): l = [] raises(IndexError, "l[1] = 2") @@ -665,6 +709,10 @@ l[0] = "2" assert l == ["2",3] + l = range(3) + l[0] = 1 + assert l == [1,1,2] + def test_delitem(self): l = [1, 2, 3, 4, 5, 6, 9] del l[0] @@ -730,6 +778,29 @@ assert l[1:0:None] == [] assert l[1:0] == [] + def test_getslice_invalid(self): + x = [1,2,3,4] + assert x[10:0] == [] + assert x[10:0:None] == [] + + x = range(1,5) + assert x[10:0] == [] + assert x[10:0:None] == [] + + assert x[0:22] == [1,2,3,4] + assert x[-1:10] == [4] + + assert x[0:22:None] == [1,2,3,4] + assert x[-1:10:None] == [4] + + def test_getslice_range_backwards(self): + x = range(1,10) + assert x[22:-10] == [] + assert x[22:-10:-1] == [9,8,7,6,5,4,3,2,1] + assert x[10:3:-1] == [9,8,7,6,5] + assert x[10:3:-2] == [9,7,5] + assert x[1:5:-1] == [] + def test_delall(self): l = l0 = [1,2,3] del l[:] @@ -763,6 +834,13 @@ l1 += [0] assert l1 == ['a', 'b', 'c', 0] + r1 = r2 = range(5) + assert r1 is r2 + r1 += [15] + assert r1 is r2 + assert r1 == [0, 1, 2, 3, 4, 15] + assert r2 == [0, 1, 2, 3, 4, 15] + def test_iadd_iterable(self): l = l0 = [1,2,3] l += iter([4,5]) @@ -813,6 +891,17 @@ assert l is l0 assert l == [1.1, 2.2, 1.1, 2.2] + l = list(range(2)) + l *= 2 + assert l == [0, 1, 0, 1] + + r1 = r2 = list(range(3)) + assert r1 is r2 + r1 *= 2 + assert r1 is r2 + assert r1 == [0, 1, 2, 0, 1, 2] + assert r2 == [0, 1, 2, 0, 1, 2] + def test_mul_errors(self): try: [1, 2, 3] * (3,) @@ -894,6 +983,11 @@ assert l == [] assert l is l0 + l = [] + l2 = range(3) + l.__setslice__(0,3,l2) + assert l == [0,1,2] + def test_assign_extended_slice(self): l = l0 = ['a', 'b', 'c'] l[::-1] = ['a', 'b', 'c'] @@ -980,10 +1074,6 @@ l.append(x) assert l == list(range(5)) - l = list(range(4)) - l.append(4) - assert l == list(range(5)) - l = [1,2,3] l.append("a") assert l == [1,2,3,"a"] @@ -992,6 +1082,22 @@ l.append(4.4) assert l == [1.1, 2.2, 3.3, 4.4] + l = range(4) + l.append(4) + assert l == range(5) + + l = range(5) + l.append(26) + assert l == [0,1,2,3,4,26] + + l = range(5) + l.append("a") + assert l == [0,1,2,3,4,"a"] + + l = range(5) + l.append(5) + assert l == [0,1,2,3,4,5] + def test_count(self): c = list('hello') assert c.count('l') == 2 @@ -1019,6 +1125,10 @@ l.insert(0,"a") assert l == ["a", 1, 2, 3] + l = range(3) + l.insert(1,5) + assert l == [0,5,1,2] + def test_pop(self): c = list('hello world') s = '' @@ -1031,6 +1141,7 @@ l = list(range(10)) l.pop() assert l == list(range(9)) + assert l.pop(0) == 0 l = [1.1, 2.2, 3.3] l.pop() @@ -1101,6 +1212,16 @@ c.reverse() assert ''.join(c) == 'dlrow olleh' + l = range(3) + l.reverse() + assert l == [2,1,0] + + r = range(3) + r[0] = 1 + assert r == [1, 1, 2] + r.reverse() + assert r == [2, 1, 1] + def test_reversed(self): assert list(list('hello').__reversed__()) == ['o', 'l', 'l', 'e', 'h'] assert list(reversed(list('hello'))) == ['o', 'l', 'l', 'e', 'h'] @@ -1377,7 +1498,114 @@ assert item11 in l[::11] -class AppTestWithoutStrategies(object): +class AppTestListObjectWithRangeList(AppTestListObject): + """Run the list object tests with range lists enabled. Tests should go in + AppTestListObject so they can be run -A against CPython as well. + """ + spaceconfig = {"objspace.std.withrangelist": True} + + +class AppTestRangeListForcing: + """Tests for range lists that test forcing. Regular tests should go in + AppTestListObject so they can be run -A against CPython as well. Separate + from AppTestListObjectWithRangeList so we don't silently overwrite tests + with the same names. + """ + spaceconfig = {"objspace.std.withrangelist": True} + + def setup_class(cls): + if cls.runappdirect: + py.test.skip("__pypy__.internal_repr() cannot be used to see " + "if a range list was forced on top of pypy-c") + cls.w_not_forced = cls.space.appexec([], """(): + import __pypy__ + def f(r): + return (isinstance(r, list) and + "RangeListStrategy" in __pypy__.internal_repr(r)) + return f + """) + + def test_simple(self): + result = [] + r = range(1, 8, 2) + for i in r: + result.append(i) + assert result == [1, 3, 5, 7] + assert self.not_forced(r) + + def test_getitem_slice(self): + result = [] + r = range(1, 100, 2) + for i in r[10:15]: + result.append(i) + assert result == [21, 23, 25, 27, 29] + assert not self.not_forced(r) + + def test_getitem_extended_slice(self): + result = [] + r = range(1, 100, 2) + for i in r[40:30:-2]: + result.append(i) + assert result == [81, 77, 73, 69, 65] + assert not self.not_forced(r) + + def test_repr(self): + r = range(5) + assert repr(r) == "[0, 1, 2, 3, 4]" + assert self.not_forced(r) + + def test_force(self): + r = range(10) + r[0] = 42 + assert not self.not_forced(r) + assert r == [42, 1, 2, 3, 4, 5, 6, 7, 8, 9] + + def test_reverse(self): + r = range(10) + r.reverse() + assert not self.not_forced(r) + assert r == range(9, -1, -1) + + def test_pop(self): + # RangeListStrategy + r = range(1, 10) + res = r.pop() + assert res == 9 + assert self.not_forced(r) + assert repr(r) == repr(range(1, 9)) + res = r.pop(0) + assert res == 1 + assert self.not_forced(r) + assert repr(r) == repr(range(2, 9)) + res = r.pop(len(r) - 1) + assert res == 8 + assert self.not_forced(r) + assert repr(r) == repr(range(2, 8)) + res = r.pop(2) + assert res == 4 + assert not self.not_forced(r) + assert r == [2, 3, 5, 6, 7] + res = r.pop(2) + assert res == 5 + assert not self.not_forced(r) + assert r == [2, 3, 6, 7] + + # SimpleRangeListStrategy + r = range(10) + res = r.pop() + assert res == 9 + assert self.not_forced(r) + res = r.pop() + assert res == 8 + assert repr(r) == repr(range(8)) + assert self.not_forced(r) + res = r.pop(0) + assert res == 0 + assert not self.not_forced(r) + assert r == [1, 2, 3, 4, 5, 6, 7] + + +class AppTestWithoutStrategies: spaceconfig = {"objspace.std.withliststrategies": False} def test_no_shared_empty_list(self): diff --git a/pypy/objspace/std/test/test_liststrategies.py b/pypy/objspace/std/test/test_liststrategies.py --- a/pypy/objspace/std/test/test_liststrategies.py +++ b/pypy/objspace/std/test/test_liststrategies.py @@ -10,7 +10,6 @@ py.test.py3k_skip("XXX: strategies are currently broken") class TestW_ListStrategies(TestW_ListObject): - def test_check_strategy(self): space = self.space w = space.wrap @@ -237,7 +236,6 @@ l.setslice(0, 1, 2, make_range_list(space, 5, 1, 4)) assert isinstance(l.strategy, IntegerListStrategy) - def test_setslice_List(self): space = self.space @@ -710,7 +708,6 @@ w_l2.sort(False) assert space.eq_w(w_l, w_l2) - def test_listview_bytes_list(self): space = self.space w_l = W_ListObject(space, [space.wrapbytes("a"), space.wrapbytes("b")]) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit