Author: Philip Jenvey <pjen...@underboss.org> Branch: Changeset: r69745:de74625112ee Date: 2014-03-05 17:03 -0800 http://bitbucket.org/pypy/pypy/changeset/de74625112ee/
Log: merge upstream 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 @@ -2328,6 +2328,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 @@ -58,8 +58,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_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 @@ -431,7 +431,7 @@ intlist.find(w(4), 0, 2) -class AppTestW_ListObject(object): +class AppTestListObject(object): def setup_class(cls): import platform import sys @@ -525,6 +525,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]) @@ -609,24 +621,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 = range(10) - l.sort(reverse = True) + l.sort(reverse=True) assert l == 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] def test_sort_cmp_key_reverse(self): @@ -640,6 +656,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 @@ -663,6 +690,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") @@ -675,6 +719,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] @@ -740,6 +788,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[:] @@ -777,6 +848,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]) @@ -835,6 +913,13 @@ l *= 2 assert l == [0, 1, 0, 1] + r1 = r2 = 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,) @@ -916,6 +1001,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'] @@ -1002,10 +1092,6 @@ l.append(x) assert l == range(5) - l = range(4) - l.append(4) - assert l == range(5) - l = [1,2,3] l.append("a") assert l == [1,2,3,"a"] @@ -1014,6 +1100,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 @@ -1041,6 +1143,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 = '' @@ -1053,6 +1159,7 @@ l = range(10) l.pop() assert l == range(9) + assert l.pop(0) == 0 l = [1.1, 2.2, 3.3] l.pop() @@ -1123,6 +1230,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'] @@ -1387,106 +1504,27 @@ # assert l == ["hi!", "okT", "okL", "okL", "okS", "okU"] + def test_no_len_on_range_iter(self): + iterable = range(10) + raises(TypeError, len, iter(iterable)) -class AppTestForRangeLists(AppTestW_ListObject): - spaceconfig = {"objspace.std.withrangelist": True} - - def test_range_simple_backwards(self): - x = range(5,1) - assert x == [] - - def test_range_big_start(self): - x = range(1,10) - x[22:0:-1] == range(1,10) - - def test_range_list_invalid_slice(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_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_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_slice(self): - l = [] - l2 = range(3) - l.__setslice__(0,3,l2) - assert l == [0,1,2] - - 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_append(self): - 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_pop(self): - l = range(3) - assert l.pop(0) == 0 - - def test_setitem(self): - l = range(3) - l[0] = 1 - assert l == [1,1,2] - - def test_inset(self): - l = range(3) - l.insert(1,5) - assert l == [0,5,1,2] - - def test_reverse(self): - l = range(3) - l.reverse() - assert l == [2,1,0] + def test_reduce(self): + if self.on_cpython: + skip("cpython raises TypeError") # XXX investigate + it = iter(range(10)) + assert it.next() == 0 + assert it.next() == 1 + assert it.next() == 2 + assert it.next() == 3 + seqiter_new, args = it.__reduce__() + assert it.next() == 4 + assert it.next() == 5 + it2 = seqiter_new(*args) + assert it2.next() == 4 + assert it2.next() == 5 + it3 = seqiter_new(*args) + assert it3.next() == 4 + assert it3.next() == 5 def test_issue1266(self): l = range(1) @@ -1518,7 +1556,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 @@ -6,8 +6,8 @@ from pypy.objspace.std import listobject from pypy.objspace.std.test.test_listobject import TestW_ListObject + class TestW_ListStrategies(TestW_ListObject): - def test_check_strategy(self): space = self.space w = space.wrap @@ -236,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 @@ -705,7 +704,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.wrap("a"), space.wrap("b")]) diff --git a/pypy/objspace/std/test/test_rangeobject.py b/pypy/objspace/std/test/test_rangeobject.py deleted file mode 100644 --- a/pypy/objspace/std/test/test_rangeobject.py +++ /dev/null @@ -1,156 +0,0 @@ -import py - - -class AppTestRangeListObject(object): - 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 - """) - cls.w_SORT_FORCES_LISTS = cls.space.wrap(False) - - 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_simple(self): - r = range(4) - assert r[-1] == 3 - assert r[3] == 3 - assert r[-4] == 0 - raises(IndexError, r.__getitem__, -5) - raises(IndexError, r.__getitem__, 4) - - 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_empty_range(self): - r = range(10, 10) - assert len(r) == 0 - assert list(reversed(r)) == [] - assert 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) - r = range(3) - r[0] = 1 - assert r == [1, 1, 2] - r.reverse() - assert r == [2, 1, 1] - - r = range(10) - r.sort(key=lambda x: -x) - 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] - - def test_reduce(self): - it = iter(range(10)) - assert it.next() == 0 - assert it.next() == 1 - assert it.next() == 2 - assert it.next() == 3 - seqiter_new, args = it.__reduce__() - assert it.next() == 4 - assert it.next() == 5 - it2 = seqiter_new(*args) - assert it2.next() == 4 - assert it2.next() == 5 - it3 = seqiter_new(*args) - assert it3.next() == 4 - assert it3.next() == 5 - - def test_no_len_on_range_iter(self): - iterable = range(10) - raises(TypeError, len, iter(iterable)) - - def test_inplace_add(self): - 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_inplace_mul(self): - r1 = r2 = 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] _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit