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:
def f(Grail g):
cdef int i = 0
cdef Swallow s
cdef object x
g = x
x = g
g = i
......
cdef class vector:
def __div__(vector self, double factor):
result = vector()
cdef object result = vector()
return result
......@@ -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
......
......@@ -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
......
......@@ -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
......@@ -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")
......@@ -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():
......
......@@ -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
......
......@@ -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
......
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)
......
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
......@@ -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
......
......@@ -14,7 +14,7 @@ cdef extern from *:
def f():
cdef void* p1
cdef PyObject* p2
a = u"teststring"
cdef object a = u"teststring"
p1 = <void*>a
p2 = <PyObject*>a
return (<object>p1, <object>p2)
......@@ -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
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