Commit 481d7bec authored by Stefan Behnel's avatar Stefan Behnel

lots of test fixes for Py3

parent 315de331
......@@ -6,6 +6,10 @@ __doc__ = u"""
Exception: crash-me
"""
import sys
if sys.version_info[0] >= 3:
__doc__ = __doc__.replace(u"Exception, e'", u"Exception as e")
cdef class A:
def __cinit__(self):
raise Exception("crash-me")
......
__doc__ = u"""
>>> print f(100)
>>> f(100)
101
>>> print g(3000000000)
>>> g(3000000000)
3000000001
"""
......
__doc__ = u"""
>>> f.__doc__
'This is a function docstring.'
u'This is a function docstring.'
>>> C.__doc__
'This is a class docstring.'
u'This is a class docstring.'
>>> CS.__doc__
'This is a subclass docstring.'
>>> print CSS.__doc__
u'This is a subclass docstring.'
>>> print(CSS.__doc__)
None
>>> T.__doc__
'This is an extension type docstring.'
u'This is an extension type docstring.'
>>> TS.__doc__
'This is an extension subtype docstring.'
u'This is an extension subtype docstring.'
>>> TSS.__doc__
Compare with standard Python:
......@@ -20,7 +20,7 @@ Compare with standard Python:
>>> def f():
... 'This is a function docstring.'
>>> f.__doc__
'This is a function docstring.'
u'This is a function docstring.'
>>> class C:
... 'This is a class docstring.'
......@@ -30,29 +30,33 @@ Compare with standard Python:
... pass
>>> C.__doc__
'This is a class docstring.'
u'This is a class docstring.'
>>> CS.__doc__
'This is a subclass docstring.'
u'This is a subclass docstring.'
>>> CSS.__doc__
"""
import sys
if sys.version_info[0] >= 3:
__doc__ = __doc__.replace(u" u'", u" '")
def f():
"This is a function docstring."
u"This is a function docstring."
class C:
"This is a class docstring."
u"This is a class docstring."
class CS(C):
"This is a subclass docstring."
u"This is a subclass docstring."
class CSS(CS):
pass
cdef class T:
"This is an extension type docstring."
u"This is an extension type docstring."
cdef class TS(T):
"This is an extension subtype docstring."
u"This is an extension subtype docstring."
cdef class TSS(TS):
pass
__doc__ = u"""
>>> c = eggs()
>>> print "eggs returned:", c
eggs returned: (17+42j)
>>> c
(17+42j)
>>> spam(c)
Real: 17.0
Imag: 42.0
......
......@@ -10,6 +10,10 @@ ValueError:
... print "%s: %s" % (e.__class__.__name__, e)
"""
import sys
if sys.version_info[0] >= 3:
__doc__ = __doc__.replace(u"Exception, e'", u"Exception as e")
def bar():
try:
raise TypeError
......
__doc__ = u"""
>>> boolExpressionsFail()
'Not 2b'
u'Not 2b'
"""
import sys
if sys.version_info[0] >= 3:
__doc__ = __doc__.replace(u" u'", u" '")
def boolExpressionsFail():
dict = {1: 1}
if not dict.has_key("2b"):
return "Not 2b"
if not "2b" in dict:
return u"Not 2b"
else:
return "2b?"
return u"2b?"
__doc__ = u"""
>>> print primes(20)
>>> primes(20)
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]
"""
......
__doc__ = u"""
>>> x = spam()
>>> print repr(x)
'Ftang\\x00Ftang!'
>>> print(repr(x))
b'Ftang\\x00Ftang!'
"""
import sys
if sys.version_info[0] < 3:
__doc__ = __doc__.replace(u" b'", u" '")
cdef extern from "string.h":
void memcpy(char *d, char *s, int n)
......
__doc__ = u"""
>>> s = Spam()
>>> print s.get_tons()
>>> s.get_tons()
17
>>> s.set_tons(42)
>>> print s.get_tons()
>>> s.get_tons()
42
>>> s = None
42 tons of spam is history.
......
__doc__ = u"""
__doc__ = """# disabled in Py3
>>> test(0)
0L
>>> test(1)
......
__doc__ = u"""
>>> z(1,9.2,'test')
>>> z(1,9.2, b'test')
>>> failtype()
Traceback (most recent call last):
TypeError: an integer is required
......@@ -13,6 +13,10 @@ __doc__ = u"""
TypeError: function takes exactly 2 arguments (1 given)
"""
import sys
if sys.version_info[0] < 3:
__doc__ = __doc__.replace(u" b'", u" '")
def f(x, y):
x = y
......
__doc__ = u"""
>>> class Test(object):
... def __setitem__(self, key, value):
... print key, value
... print((key, value))
... def __getitem__(self, key):
... print key
... print(key)
... return self
>>> ellipsis(Test())
......@@ -23,7 +23,7 @@ __doc__ = u"""
slice(1, 2, 3)
>>> set(Test(), -11)
slice(1, 2, 3) -11
(slice(1, 2, 3), -11)
"""
def ellipsis(o):
......
......@@ -85,7 +85,7 @@ __doc__ = u"""
"""
cdef sorteditems(d):
l = d.items()
l = list(d.items())
l.sort()
return tuple(l)
......
__doc__ = u"""
>>> c = C()
>>> print c.x
>>> print(c.x)
foo
"""
......
__doc__ = u"""
>>> s('test')
'test'
>>> s('test', **encoding)
b'test'
>>> z
'test'
b'test'
>>> c('testing')
'testing'
b'testing'
>>> sub('testing a subtype')
'testing a subtype'
>>> subs('testing a subtype')
'testing a subtype'
b'testing a subtype'
>>> subs('testing a subtype', **encoding)
b'testing a subtype'
# >>> csub('testing a subtype')
# 'testing a subtype'
......@@ -21,6 +21,7 @@ if sys.version_info[0] >= 3:
encoding = {'encoding' : 'ASCII'}
else:
encoding = {}
__doc__ = __doc__.replace(u" b'", u" '")
s = str
z = str('test', **encoding)
......
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