From c17037bc2373185568023b28ba8fedbc4a08d730 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sun, 6 Dec 2009 23:27:49 +0100 Subject: [PATCH] safety fixes for tests under type inference --- tests/compile/extcoerce.pyx | 1 + tests/compile/hinsen2.pyx | 2 +- tests/run/big_indices.pyx | 1 + tests/run/buffmt.pyx | 6 +++--- tests/run/builtinnames.pyx | 10 ++++++++++ tests/run/cdef_opt.pyx | 6 +++--- tests/run/cdef_setitem_T284.pyx | 4 ++-- tests/run/inop.pyx | 14 ++++++-------- tests/run/inplace.pyx | 2 +- tests/run/isinstance.pyx | 8 +------- tests/run/kwargproblems.pyx | 6 +----- tests/run/longlongindex.pyx | 2 +- tests/run/pyobjcast_T313.pyx | 2 +- tests/run/watts1.pyx | 4 ++-- 14 files changed, 34 insertions(+), 34 deletions(-) diff --git a/tests/compile/extcoerce.pyx b/tests/compile/extcoerce.pyx index 374238e0..7a850b60 100644 --- a/tests/compile/extcoerce.pyx +++ b/tests/compile/extcoerce.pyx @@ -9,6 +9,7 @@ cdef class Swallow: def f(Grail g): cdef int i = 0 cdef Swallow s + cdef object x g = x x = g g = i diff --git a/tests/compile/hinsen2.pyx b/tests/compile/hinsen2.pyx index 63540ace..390fe2b1 100644 --- a/tests/compile/hinsen2.pyx +++ b/tests/compile/hinsen2.pyx @@ -1,4 +1,4 @@ cdef class vector: def __div__(vector self, double factor): - result = vector() + cdef object result = vector() return result diff --git a/tests/run/big_indices.pyx b/tests/run/big_indices.pyx index 6eb642e6..4e86c580 100644 --- a/tests/run/big_indices.pyx +++ b/tests/run/big_indices.pyx @@ -8,6 +8,7 @@ def test(): neg pos """ + cdef object D cdef long neg = -1 cdef unsigned long pos = -2 # will be a large positive number diff --git a/tests/run/buffmt.pyx b/tests/run/buffmt.pyx index 35f3b867..3d740d61 100644 --- a/tests/run/buffmt.pyx +++ b/tests/run/buffmt.pyx @@ -177,7 +177,7 @@ def char3int(fmt): ... ValueError: Buffer dtype mismatch, expected 'int' but got end in 'Char3Int.d' """ - obj = MockBuffer(fmt, sizeof(Char3Int)) + cdef object obj = MockBuffer(fmt, sizeof(Char3Int)) cdef object[Char3Int, ndim=1] buf = obj @testcase @@ -195,7 +195,7 @@ def unpacked_struct(fmt): assert (sizeof(UnpackedStruct1) == sizeof(UnpackedStruct2) == sizeof(UnpackedStruct3) == sizeof(UnpackedStruct4)) - obj = MockBuffer(fmt, sizeof(UnpackedStruct1)) + cdef object obj = MockBuffer(fmt, sizeof(UnpackedStruct1)) cdef object[UnpackedStruct1, ndim=1] buf1 = obj cdef object[UnpackedStruct2, ndim=1] buf2 = obj cdef object[UnpackedStruct3, ndim=1] buf3 = obj @@ -218,7 +218,7 @@ def complex_test(fmt): ValueError: Buffer dtype mismatch, expected 'float' but got 'complex float' in 'ComplexFloat.imag' """ - obj = MockBuffer(fmt, sizeof(ComplexTest)) + cdef object obj = MockBuffer(fmt, sizeof(ComplexTest)) cdef object[ComplexTest] buf1 = obj diff --git a/tests/run/builtinnames.pyx b/tests/run/builtinnames.pyx index 06d425b0..46539582 100644 --- a/tests/run/builtinnames.pyx +++ b/tests/run/builtinnames.pyx @@ -46,3 +46,13 @@ def test_c(arg): print test_file_c(arg) print len(arg) print type(arg) + +def test_for_in_range(arg): + """ + >>> print(str(test_for_in_range('abc')).replace("u'", "'")) + ['r', 'a', 'n', 'g', 'e', 'a', 'b', 'c'] + """ + l = [] + for c in range(arg): + l.append(c) + return l diff --git a/tests/run/cdef_opt.pyx b/tests/run/cdef_opt.pyx index 118b2530..22c34ba9 100644 --- a/tests/run/cdef_opt.pyx +++ b/tests/run/cdef_opt.pyx @@ -23,7 +23,7 @@ def call0(): >>> call0() (True, u'yo') """ - a = A() + cdef A a = A() return a.foo() def call1(): @@ -31,7 +31,7 @@ def call1(): >>> call1() (False, u'yo') """ - a = A() + cdef A a = A() return a.foo(False) def call2(): @@ -39,5 +39,5 @@ def call2(): >>> call2() (False, u'go') """ - a = A() + cdef A a = A() return a.foo(False, u"go") diff --git a/tests/run/cdef_setitem_T284.pyx b/tests/run/cdef_setitem_T284.pyx index 987c5288..03ff384e 100644 --- a/tests/run/cdef_setitem_T284.pyx +++ b/tests/run/cdef_setitem_T284.pyx @@ -2,10 +2,10 @@ def no_cdef(): """ >>> no_cdef() """ - lst = list(range(11)) + cdef object lst = list(range(11)) ob = 10L lst[ob] = -10 - dd = {} + cdef object dd = {} dd[ob] = -10 def with_cdef(): diff --git a/tests/run/inop.pyx b/tests/run/inop.pyx index 67c15c07..df5f2aeb 100644 --- a/tests/run/inop.pyx +++ b/tests/run/inop.pyx @@ -7,7 +7,7 @@ def f(a,b): >>> f(2,(1,2,3)) True """ - result = a in b + cdef object result = a in b return result def g(a,b): @@ -19,8 +19,7 @@ def g(a,b): >>> g(2,(1,2,3)) 1 """ - cdef int result - result = a in b + cdef int result = a in b return result def h(b): @@ -30,7 +29,7 @@ def h(b): >>> h([1,3,4]) False """ - result = 2 in b + cdef object result = 2 in b return result def j(b): @@ -40,8 +39,7 @@ def j(b): >>> j([1,3,4]) 0 """ - cdef int result - result = 2 in b + cdef int result = 2 in b return result def k(a): @@ -104,8 +102,8 @@ def r(a): >>> r(2) 1 """ - l = [1,2,3,4] - l2 = [l[1:],l[:-1],l] + cdef object l = [1,2,3,4] + cdef object l2 = [l[1:],l[:-1],l] cdef int result = a in l in l2 return result diff --git a/tests/run/inplace.pyx b/tests/run/inplace.pyx index 0db3dba9..7ae65753 100644 --- a/tests/run/inplace.pyx +++ b/tests/run/inplace.pyx @@ -107,7 +107,7 @@ def test_side_effects(): c side effect 4 ([0, 11, 102, 3, 4], [0, 1, 2, 13, 104]) """ - a = list(range(5)) + cdef object a = list(range(5)) a[side_effect(1)] += 10 a[c_side_effect(2)] += 100 cdef int i diff --git a/tests/run/isinstance.pyx b/tests/run/isinstance.pyx index 9fb91f67..4b36aa4e 100644 --- a/tests/run/isinstance.pyx +++ b/tests/run/isinstance.pyx @@ -1,18 +1,12 @@ cdef class A: pass -import sys -IS_PY3 = sys.version_info[0] >= 3 - def test_all(): """ >>> test_all() True """ - if IS_PY3: - new_type = type(u'a',(),{}) - else: - new_type = type('a',(),{}) + new_type = type('a',(),{}) # Optimized tests. assert isinstance(new_type, type) diff --git a/tests/run/kwargproblems.pyx b/tests/run/kwargproblems.pyx index 97b0a4a3..50bef61b 100644 --- a/tests/run/kwargproblems.pyx +++ b/tests/run/kwargproblems.pyx @@ -1,4 +1,3 @@ -import sys def test(**kw): """ @@ -19,8 +18,5 @@ def test(**kw): >>> d {'arg': 2} """ - if sys.version_info[0] >= 3: - kw[u'arg'] = 3 - else: - kw['arg'] = 3 + kw['arg'] = 3 return kw diff --git a/tests/run/longlongindex.pyx b/tests/run/longlongindex.pyx index 22ec638e..6b739083 100644 --- a/tests/run/longlongindex.pyx +++ b/tests/run/longlongindex.pyx @@ -11,7 +11,7 @@ __doc__ = u""" ctypedef long long foo def set_longlong(long long ob, foo x, long y, val): - tank = {} + cdef object tank = {} tank[ob] = val tank[x] = val tank[y] = val diff --git a/tests/run/pyobjcast_T313.pyx b/tests/run/pyobjcast_T313.pyx index 88d61451..aac975af 100644 --- a/tests/run/pyobjcast_T313.pyx +++ b/tests/run/pyobjcast_T313.pyx @@ -14,7 +14,7 @@ cdef extern from *: def f(): cdef void* p1 cdef PyObject* p2 - a = u"teststring" + cdef object a = u"teststring" p1 = a p2 = a return (p1, p2) diff --git a/tests/run/watts1.pyx b/tests/run/watts1.pyx index 62ff80e5..b235b429 100644 --- a/tests/run/watts1.pyx +++ b/tests/run/watts1.pyx @@ -4,6 +4,6 @@ def test(): True """ cdef int a,b - foo=(55,66) - a,b=foo + cdef object foo = (55,66) + a,b = foo return a + b -- 2.26.2