Commit c3fc785a authored by Lisandro Dalcin's avatar Lisandro Dalcin

fix some tests for Python 3

parent a8a6cd02
__doc__ = u'''
>>> no_cdef()
>>> with_cdef()
>>> test_list(range(11), -2, None)
>>> test_list(list(range(11)), -2, None)
[0, 1, 2, 3, 4, 5, 6, 7, 8, None, 10]
>>> test_list(range(11), "invalid index", None)
>>> test_list(list(range(11)), "invalid index", None) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
TypeError: list indices must be integers
TypeError: list indices must be integers...
'''
def no_cdef():
lst = range(11)
lst = list(range(11))
ob = 10L
lst[ob] = -10
dd = {}
dd[ob] = -10
def with_cdef():
cdef list lst = range(11)
cdef list lst = list(range(11))
ob = 10L
lst[ob] = -10
cdef dict dd = {}
......
......@@ -14,11 +14,11 @@ cdef char* s = 'abcdef'
def global_c_and_s():
pys = s
print c
print pys.decode('ASCII')
print (pys.decode(u'ASCII'))
def local_c_and_s():
cdef char c = 'b'
cdef char* s = 'bcdefg'
pys = s
print c
print pys.decode('ASCII')
print (pys.decode(u'ASCII'))
......@@ -32,29 +32,29 @@ __doc__ = u"""
def double_target(a, b):
cdef double x
for x from a <= x < b:
print "at", x
print u"at", x
return x
def double_step(a, b, dx):
cdef double x
for x from a <= x < b by dx:
print "at", x
print u"at", x
return x
def double_step_typed(a, b, double dx):
cdef double x
for x from a <= x < b by dx:
print "at", x
print u"at", x
return x
def double_step_py_target(a, b, double dx):
cdef object x
for x from a <= x < b by dx:
print "at", x
print u"at", x
return x
def int_step_py_target(a, b, int dx):
cdef object x
for x from a <= x < b by dx:
print "at", x
print u"at", x
return x
# Ensure casting still works to void*
"""
>>> f()
('teststring', 'teststring')
>>> o = f()
>>> print(o[0])
teststring
>>> print(o[1])
teststring
"""
cdef extern from *:
......@@ -11,7 +14,7 @@ cdef extern from *:
def f():
cdef void* p1
cdef PyObject* p2
a = "teststring"
a = u"teststring"
p1 = <void*>a
p2 = <PyObject*>a
return (<object>p1, <object>p2)
......
......@@ -74,66 +74,66 @@ at 4
5
"""
cdef int get_bound(int m):
print "get_bound(%s)"%m
print u"get_bound(%s)"%m
return m
def for_from_range(a, b):
cdef int i = 100
print "range(%s)" % a
print u"range(%s)" % a
for i in range(a):
print "at", i
print "range(%s, %s)" % (a, b)
print u"at", i
print u"range(%s, %s)" % (a, b)
for i in range(a, b):
print "at", i
print "range(%s, %s, %s)" % (a, b, 2)
print u"at", i
print u"range(%s, %s, %s)" % (a, b, 2)
for i in range(a, b, 2):
print "at", i
print u"at", i
return i
def for_from_bound_reassignment(int bound, int fake_bound):
cdef int i = 100
for i from 0 <= i < bound:
print "at", i
print u"at", i
bound = fake_bound
return i
def for_from_step_reassignment(int bound, int step, int fake_step):
cdef int i = 100
for i from 0 <= i < bound by step:
print "at", i
print u"at", i
step = fake_step
return i
def for_from_target_reassignment(int bound, int factor):
cdef int i = 100
for i from 0 <= i < bound:
print "at", i
print u"at", i
i *= factor
return i
def for_from_py_target_reassignment(int bound, int factor):
cdef object i
for i from 0 <= i < bound:
print "at", i
print u"at", i
i *= factor
return i
def for_from_py_global_target_reassignment(int bound, int factor):
global g_var
for g_var from 0 <= g_var < bound:
print "at", g_var
print u"at", g_var
g_var *= factor
return g_var
def for_in_target_reassignment(int bound, int factor):
cdef int i = 100
for i in range(bound):
print "at", i
print u"at", i
i *= factor
return i
def test_func(int n):
cdef int i = 100
for i from 0 <= i < get_bound(n):
print "at", i
print u"at", i
return i
......@@ -22,10 +22,10 @@ __doc__ = u"""
>>> slice_list_assign(l2, dict(zip(l,l)))
[1, 1, 2, 3, 4, 4]
>>> slice_charp('abcdefg')
'bc'
>>> slice_charp_repeat('abcdefg')
'cd'
>>> print("%s" % slice_charp('abcdefg'))
bc
>>> print("%s" % slice_charp_repeat('abcdefg'))
cd
"""
def slice_list(list l):
......@@ -51,12 +51,14 @@ def slice_list_assign(list l, value):
return l
def slice_charp(str py_string):
def slice_charp(py_string_arg):
cdef str py_string = py_string_arg.encode(u'ASCII')
cdef char* s = py_string
return s[1:3]
return s[1:3].decode(u'ASCII')
def slice_charp_repeat(str py_string):
def slice_charp_repeat(py_string_arg):
cdef str py_string = py_string_arg.encode(u'ASCII')
cdef char* s = py_string
cdef str slice_val = s[1:6]
s = slice_val
return s[1:3]
return s[1:3].decode(u'ASCII')
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