Commit 6fcb8ca7 authored by Stefan Behnel's avatar Stefan Behnel

Py3 test fixes

parent f630c04f
__doc__ = u""" __doc__ = u"""
>>> a = A() >>> a = A()
>>> a.foo() >>> a.foo()
(True, 'yo') (True, u'yo')
>>> a.foo(False) >>> a.foo(False)
(False, 'yo') (False, u'yo')
>>> a.foo(10, 'yes') >>> a.foo(10, u'yes')
(True, '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: cdef class A:
cpdef foo(self, bint a=True, b="yo"): cpdef foo(self, bint a=True, b=u"yo"):
return a, b 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")
...@@ -4,7 +4,9 @@ __doc__ = u""" ...@@ -4,7 +4,9 @@ __doc__ = u"""
class IteratorAndIterateable: class IteratorAndIterateable:
def next(self): def next(self):
raise ValueError("") raise ValueError
def __next__(self):
raise ValueError
def __iter__(self): def __iter__(self):
return self return self
...@@ -12,6 +14,6 @@ def f(): ...@@ -12,6 +14,6 @@ def f():
try: try:
for x in IteratorAndIterateable(): for x in IteratorAndIterateable():
pass 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: except ValueError:
pass pass
__doc__ = u""" __doc__ = u"""
>>> test_ints(100) >>> test_ints(100)
(100, 100, 100) (100, 100, 100)
>>> test_chars("yo") >>> test_chars(b'yo')
('a', 'bc', 'yo') (b'a', b'bc', b'yo')
>>> test_chars(None) >>> test_chars(None) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... TypeError: expected ...
TypeError: expected string or Unicode object, NoneType found
>>> test_struct(-5, -10) >>> test_struct(-5, -10)
-5 -10 True -5 -10 True
1 2 False 1 2 False
""" """
import sys
if sys.version_info[0] < 3:
__doc__ = __doc__.replace(u"b'", u"'")
def test_ints(int x): def test_ints(int x):
cdef list L = [1,2,3,x] cdef list L = [1,2,3,x]
cdef int* Li = [1,2,3,x] cdef int* Li = [1,2,3,x]
......
__doc__ = u""" __doc__ = u"""
>>> do_slice("abcdef".encode(u"ASCII"), 2, 3) >>> do_slice(b"abcdef", 2, 3)
('c', 'cdef', 'ab', 'abcdef') (b'c', b'cdef', b'ab', b'abcdef')
>>> do_slice("abcdef".encode(u"ASCII"), 0, 5) >>> do_slice(b"abcdef", 0, 5)
('abcde', 'abcdef', '', 'abcdef') (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): def do_slice(s, int i, int j):
cdef char* ss = s cdef char* ss = s
return ss[i:j], ss[i:], ss[:i], ss[:] return ss[i:j], ss[i:], ss[:i], ss[:]
......
__doc__ = u""" import sys
if sys.version_info[0] >= 3:
__doc__ = u"""
>>> test_signed()
3 <class 'int'>
9 <class 'int'>
6 <class 'int'>
12 <class 'int'>
"""
else:
__doc__ = u"""
>>> test_signed() >>> test_signed()
3 <type 'int'> 3 <type 'int'>
9 <type 'long'> 9 <type 'long'>
...@@ -6,7 +17,6 @@ __doc__ = u""" ...@@ -6,7 +17,6 @@ __doc__ = u"""
12 <type 'long'> 12 <type 'long'>
""" """
cdef int i = 1 cdef int i = 1
cdef long l = 2 cdef long l = 2
cdef unsigned int ui = 4 cdef unsigned int ui = 4
......
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