Commit c3fc785a authored by Lisandro Dalcin's avatar Lisandro Dalcin

fix some tests for Python 3

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