Commit c17037bc authored by Stefan Behnel's avatar Stefan Behnel

safety fixes for tests under type inference

parent ff75036d
...@@ -9,6 +9,7 @@ cdef class Swallow: ...@@ -9,6 +9,7 @@ cdef class Swallow:
def f(Grail g): def f(Grail g):
cdef int i = 0 cdef int i = 0
cdef Swallow s cdef Swallow s
cdef object x
g = x g = x
x = g x = g
g = i g = i
......
cdef class vector: cdef class vector:
def __div__(vector self, double factor): def __div__(vector self, double factor):
result = vector() cdef object result = vector()
return result return result
...@@ -8,6 +8,7 @@ def test(): ...@@ -8,6 +8,7 @@ def test():
neg neg
pos pos
""" """
cdef object D
cdef long neg = -1 cdef long neg = -1
cdef unsigned long pos = -2 # will be a large positive number cdef unsigned long pos = -2 # will be a large positive number
......
...@@ -177,7 +177,7 @@ def char3int(fmt): ...@@ -177,7 +177,7 @@ def char3int(fmt):
... ...
ValueError: Buffer dtype mismatch, expected 'int' but got end in 'Char3Int.d' 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 cdef object[Char3Int, ndim=1] buf = obj
@testcase @testcase
...@@ -195,7 +195,7 @@ def unpacked_struct(fmt): ...@@ -195,7 +195,7 @@ def unpacked_struct(fmt):
assert (sizeof(UnpackedStruct1) == sizeof(UnpackedStruct2) assert (sizeof(UnpackedStruct1) == sizeof(UnpackedStruct2)
== sizeof(UnpackedStruct3) == sizeof(UnpackedStruct4)) == 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[UnpackedStruct1, ndim=1] buf1 = obj
cdef object[UnpackedStruct2, ndim=1] buf2 = obj cdef object[UnpackedStruct2, ndim=1] buf2 = obj
cdef object[UnpackedStruct3, ndim=1] buf3 = obj cdef object[UnpackedStruct3, ndim=1] buf3 = obj
...@@ -218,7 +218,7 @@ def complex_test(fmt): ...@@ -218,7 +218,7 @@ def complex_test(fmt):
ValueError: Buffer dtype mismatch, expected 'float' but got 'complex float' in 'ComplexFloat.imag' 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 cdef object[ComplexTest] buf1 = obj
......
...@@ -46,3 +46,13 @@ def test_c(arg): ...@@ -46,3 +46,13 @@ def test_c(arg):
print test_file_c(arg) print test_file_c(arg)
print len(arg) print len(arg)
print type(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
...@@ -23,7 +23,7 @@ def call0(): ...@@ -23,7 +23,7 @@ def call0():
>>> call0() >>> call0()
(True, u'yo') (True, u'yo')
""" """
a = A() cdef A a = A()
return a.foo() return a.foo()
def call1(): def call1():
...@@ -31,7 +31,7 @@ def call1(): ...@@ -31,7 +31,7 @@ def call1():
>>> call1() >>> call1()
(False, u'yo') (False, u'yo')
""" """
a = A() cdef A a = A()
return a.foo(False) return a.foo(False)
def call2(): def call2():
...@@ -39,5 +39,5 @@ def call2(): ...@@ -39,5 +39,5 @@ def call2():
>>> call2() >>> call2()
(False, u'go') (False, u'go')
""" """
a = A() cdef A a = A()
return a.foo(False, u"go") return a.foo(False, u"go")
...@@ -2,10 +2,10 @@ def no_cdef(): ...@@ -2,10 +2,10 @@ def no_cdef():
""" """
>>> no_cdef() >>> no_cdef()
""" """
lst = list(range(11)) cdef object lst = list(range(11))
ob = 10L ob = 10L
lst[ob] = -10 lst[ob] = -10
dd = {} cdef object dd = {}
dd[ob] = -10 dd[ob] = -10
def with_cdef(): def with_cdef():
......
...@@ -7,7 +7,7 @@ def f(a,b): ...@@ -7,7 +7,7 @@ def f(a,b):
>>> f(2,(1,2,3)) >>> f(2,(1,2,3))
True True
""" """
result = a in b cdef object result = a in b
return result return result
def g(a,b): def g(a,b):
...@@ -19,8 +19,7 @@ def g(a,b): ...@@ -19,8 +19,7 @@ def g(a,b):
>>> g(2,(1,2,3)) >>> g(2,(1,2,3))
1 1
""" """
cdef int result cdef int result = a in b
result = a in b
return result return result
def h(b): def h(b):
...@@ -30,7 +29,7 @@ def h(b): ...@@ -30,7 +29,7 @@ def h(b):
>>> h([1,3,4]) >>> h([1,3,4])
False False
""" """
result = 2 in b cdef object result = 2 in b
return result return result
def j(b): def j(b):
...@@ -40,8 +39,7 @@ def j(b): ...@@ -40,8 +39,7 @@ def j(b):
>>> j([1,3,4]) >>> j([1,3,4])
0 0
""" """
cdef int result cdef int result = 2 in b
result = 2 in b
return result return result
def k(a): def k(a):
...@@ -104,8 +102,8 @@ def r(a): ...@@ -104,8 +102,8 @@ def r(a):
>>> r(2) >>> r(2)
1 1
""" """
l = [1,2,3,4] cdef object l = [1,2,3,4]
l2 = [l[1:],l[:-1],l] cdef object l2 = [l[1:],l[:-1],l]
cdef int result = a in l in l2 cdef int result = a in l in l2
return result return result
......
...@@ -107,7 +107,7 @@ def test_side_effects(): ...@@ -107,7 +107,7 @@ def test_side_effects():
c side effect 4 c side effect 4
([0, 11, 102, 3, 4], [0, 1, 2, 13, 104]) ([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[side_effect(1)] += 10
a[c_side_effect(2)] += 100 a[c_side_effect(2)] += 100
cdef int i cdef int i
......
cdef class A: cdef class A:
pass pass
import sys
IS_PY3 = sys.version_info[0] >= 3
def test_all(): def test_all():
""" """
>>> test_all() >>> test_all()
True True
""" """
if IS_PY3: new_type = type('a',(),{})
new_type = type(u'a',(),{})
else:
new_type = type('a',(),{})
# Optimized tests. # Optimized tests.
assert isinstance(new_type, type) assert isinstance(new_type, type)
......
import sys
def test(**kw): def test(**kw):
""" """
...@@ -19,8 +18,5 @@ def test(**kw): ...@@ -19,8 +18,5 @@ def test(**kw):
>>> d >>> d
{'arg': 2} {'arg': 2}
""" """
if sys.version_info[0] >= 3: kw['arg'] = 3
kw[u'arg'] = 3
else:
kw['arg'] = 3
return kw return kw
...@@ -11,7 +11,7 @@ __doc__ = u""" ...@@ -11,7 +11,7 @@ __doc__ = u"""
ctypedef long long foo ctypedef long long foo
def set_longlong(long long ob, foo x, long y, val): def set_longlong(long long ob, foo x, long y, val):
tank = {} cdef object tank = {}
tank[ob] = val tank[ob] = val
tank[x] = val tank[x] = val
tank[y] = val tank[y] = val
......
...@@ -14,7 +14,7 @@ cdef extern from *: ...@@ -14,7 +14,7 @@ cdef extern from *:
def f(): def f():
cdef void* p1 cdef void* p1
cdef PyObject* p2 cdef PyObject* p2
a = u"teststring" cdef object a = u"teststring"
p1 = <void*>a p1 = <void*>a
p2 = <PyObject*>a p2 = <PyObject*>a
return (<object>p1, <object>p2) return (<object>p1, <object>p2)
...@@ -4,6 +4,6 @@ def test(): ...@@ -4,6 +4,6 @@ def test():
True True
""" """
cdef int a,b cdef int a,b
foo=(55,66) cdef object foo = (55,66)
a,b=foo a,b = foo
return a + b return a + b
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment