From 6fcb8ca78679fa4447468a340d6349741eb22b96 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sat, 21 Feb 2009 22:10:28 +0100 Subject: [PATCH] Py3 test fixes --- tests/run/cdef_opt.pyx | 34 ++++++++++++++++++++++++++++----- tests/run/iteratorexception.pyx | 6 ++++-- tests/run/literal_lists.pyx | 14 +++++++++----- tests/run/slice_charptr.pyx | 13 +++++++++---- tests/run/unsigned.pyx | 14 ++++++++++++-- 5 files changed, 63 insertions(+), 18 deletions(-) diff --git a/tests/run/cdef_opt.pyx b/tests/run/cdef_opt.pyx index cd03ce59..fe55fe35 100644 --- a/tests/run/cdef_opt.pyx +++ b/tests/run/cdef_opt.pyx @@ -1,13 +1,37 @@ __doc__ = u""" >>> a = A() >>> a.foo() - (True, 'yo') + (True, u'yo') >>> a.foo(False) - (False, 'yo') - >>> a.foo(10, 'yes') - (True, 'yes') + (False, u'yo') + >>> a.foo(10, u'yes') + (True, u'yes') + + >>> call0() + (True, u'yo') + >>> call1() + (False, u'yo') + >>> call2() + (False, u'go') """ +import sys + +if sys.version_info[0] >= 3: + __doc__ = __doc__.replace(u"u'", u"'") + cdef class A: - cpdef foo(self, bint a=True, b="yo"): + cpdef foo(self, bint a=True, b=u"yo"): return a, b + +def call0(): + a = A() + return a.foo() + +def call1(): + a = A() + return a.foo(False) + +def call2(): + a = A() + return a.foo(False, u"go") diff --git a/tests/run/iteratorexception.pyx b/tests/run/iteratorexception.pyx index f2726a10..3b53eccd 100644 --- a/tests/run/iteratorexception.pyx +++ b/tests/run/iteratorexception.pyx @@ -4,7 +4,9 @@ __doc__ = u""" class IteratorAndIterateable: def next(self): - raise ValueError("") + raise ValueError + def __next__(self): + raise ValueError def __iter__(self): return self @@ -12,6 +14,6 @@ def f(): try: for x in IteratorAndIterateable(): pass - assert False, "Should not reach this point, iterator has thrown exception" + assert False, u"Should not reach this point, iterator has thrown exception" except ValueError: pass diff --git a/tests/run/literal_lists.pyx b/tests/run/literal_lists.pyx index 5925c69e..f2f9359e 100644 --- a/tests/run/literal_lists.pyx +++ b/tests/run/literal_lists.pyx @@ -1,17 +1,21 @@ __doc__ = u""" >>> test_ints(100) (100, 100, 100) - >>> test_chars("yo") - ('a', 'bc', 'yo') - >>> test_chars(None) + >>> test_chars(b'yo') + (b'a', b'bc', b'yo') + >>> test_chars(None) # doctest: +ELLIPSIS Traceback (most recent call last): - ... - TypeError: expected string or Unicode object, NoneType found + TypeError: expected ... >>> test_struct(-5, -10) -5 -10 True 1 2 False """ +import sys + +if sys.version_info[0] < 3: + __doc__ = __doc__.replace(u"b'", u"'") + def test_ints(int x): cdef list L = [1,2,3,x] cdef int* Li = [1,2,3,x] diff --git a/tests/run/slice_charptr.pyx b/tests/run/slice_charptr.pyx index b7fcef0f..59346256 100644 --- a/tests/run/slice_charptr.pyx +++ b/tests/run/slice_charptr.pyx @@ -1,10 +1,15 @@ __doc__ = u""" - >>> do_slice("abcdef".encode(u"ASCII"), 2, 3) - ('c', 'cdef', 'ab', 'abcdef') - >>> do_slice("abcdef".encode(u"ASCII"), 0, 5) - ('abcde', 'abcdef', '', 'abcdef') + >>> do_slice(b"abcdef", 2, 3) + (b'c', b'cdef', b'ab', b'abcdef') + >>> do_slice(b"abcdef", 0, 5) + (b'abcde', b'abcdef', b'', b'abcdef') """ +import sys + +if sys.version_info[0] < 3: + __doc__ = __doc__.replace(u"(b'", u"('").replace(u" b'", u" '") + def do_slice(s, int i, int j): cdef char* ss = s return ss[i:j], ss[i:], ss[:i], ss[:] diff --git a/tests/run/unsigned.pyx b/tests/run/unsigned.pyx index 8fdb2c3f..45aaa112 100644 --- a/tests/run/unsigned.pyx +++ b/tests/run/unsigned.pyx @@ -1,4 +1,15 @@ -__doc__ = u""" +import sys + +if sys.version_info[0] >= 3: + __doc__ = u""" + >>> test_signed() + 3 + 9 + 6 + 12 +""" +else: + __doc__ = u""" >>> test_signed() 3 9 @@ -6,7 +17,6 @@ __doc__ = u""" 12 """ - cdef int i = 1 cdef long l = 2 cdef unsigned int ui = 4 -- 2.26.2