From c3fc785a7da5ad6f0901a201bfbfffc74a0142ca Mon Sep 17 00:00:00 2001 From: Lisandro Dalcin Date: Sat, 16 May 2009 23:07:14 -0300 Subject: [PATCH] fix some tests for Python 3 --- tests/run/cdef_setitem_T284.pyx | 10 +++++----- tests/run/char_constants_T99.pyx | 4 ++-- tests/run/for_from_float_T254.pyx | 10 +++++----- tests/run/pyobjcast_T313.pyx | 9 ++++++--- tests/run/range_optimisation_T203.pyx | 28 +++++++++++++-------------- tests/run/typed_slice.pyx | 18 +++++++++-------- 6 files changed, 42 insertions(+), 37 deletions(-) diff --git a/tests/run/cdef_setitem_T284.pyx b/tests/run/cdef_setitem_T284.pyx index 81edbba4..2d1971fa 100644 --- a/tests/run/cdef_setitem_T284.pyx +++ b/tests/run/cdef_setitem_T284.pyx @@ -1,22 +1,22 @@ __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 = {} diff --git a/tests/run/char_constants_T99.pyx b/tests/run/char_constants_T99.pyx index 580c8935..401f5842 100644 --- a/tests/run/char_constants_T99.pyx +++ b/tests/run/char_constants_T99.pyx @@ -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')) diff --git a/tests/run/for_from_float_T254.pyx b/tests/run/for_from_float_T254.pyx index 3fbf50d2..4cf2093a 100644 --- a/tests/run/for_from_float_T254.pyx +++ b/tests/run/for_from_float_T254.pyx @@ -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 diff --git a/tests/run/pyobjcast_T313.pyx b/tests/run/pyobjcast_T313.pyx index 178f1d74..1a06044d 100644 --- a/tests/run/pyobjcast_T313.pyx +++ b/tests/run/pyobjcast_T313.pyx @@ -1,8 +1,11 @@ # 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 = a p2 = a return (p1, p2) diff --git a/tests/run/range_optimisation_T203.pyx b/tests/run/range_optimisation_T203.pyx index 00e94a97..38ec0e2b 100644 --- a/tests/run/range_optimisation_T203.pyx +++ b/tests/run/range_optimisation_T203.pyx @@ -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 diff --git a/tests/run/typed_slice.pyx b/tests/run/typed_slice.pyx index 3b5b04b0..4b15097e 100644 --- a/tests/run/typed_slice.pyx +++ b/tests/run/typed_slice.pyx @@ -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') -- 2.26.2