Commit 0427dd3d authored by Stefan Behnel's avatar Stefan Behnel

more test fixes for Py3

parent 4257453b
__doc__ = u"""
>>> class Test:
>>> class Test(object):
... def __init__(self, i):
... self.i = i
>>> b = Test(1)
......@@ -9,50 +9,50 @@ __doc__ = u"""
>>> b.spam.eggs.spam.eggs = Test(5)
>>> a = f(b)
>>> print a.i
>>> a.i
2
>>> print b.i
>>> b.i
1
>>> print a.spam.i
>>> a.spam.i
1
>>> print b.spam.i
>>> b.spam.i
2
>>> print a.spam.eggs.i
>>> a.spam.eggs.i
Traceback (most recent call last):
AttributeError: Test instance has no attribute 'eggs'
>>> print b.spam.eggs.i
AttributeError: 'Test' object has no attribute 'eggs'
>>> b.spam.eggs.i
3
>>> print a.spam.spam.i
>>> a.spam.spam.i
2
>>> print b.spam.spam.i
>>> b.spam.spam.i
1
>>> print a.spam.eggs.spam.i
>>> a.spam.eggs.spam.i
Traceback (most recent call last):
AttributeError: Test instance has no attribute 'eggs'
>>> print b.spam.eggs.spam.i
AttributeError: 'Test' object has no attribute 'eggs'
>>> b.spam.eggs.spam.i
4
>>> a = g(b)
>>> print a.i
>>> a.i
3
>>> print b.i
>>> b.i
1
>>> print a.spam.i
>>> a.spam.i
4
>>> print b.spam.i
>>> b.spam.i
2
>>> print a.spam.eggs.i
>>> a.spam.eggs.i
1
>>> print b.spam.eggs.i
>>> b.spam.eggs.i
3
>>> print a.spam.spam.i
>>> a.spam.spam.i
Traceback (most recent call last):
AttributeError: Test instance has no attribute 'spam'
>>> print b.spam.spam.i
AttributeError: 'Test' object has no attribute 'spam'
>>> b.spam.spam.i
1
>>> print a.spam.eggs.spam.i
>>> a.spam.eggs.spam.i
2
>>> print b.spam.eggs.spam.i
>>> b.spam.eggs.spam.i
4
"""
......
......@@ -10,7 +10,7 @@ __doc__ = u"""
>>> int1 ^= int2 >> int3
>>> int1 ^= int2 << int3 | int2 >> int3
>>> long1 = char1 | int1
>>> print (int1, long1) == f()
>>> (int1, long1) == f()
True
>>> f()
......
__doc__ = u"""
>>> s = Spam()
>>> print s.__class__.__name__
Spam
>>> s.__class__.__name__
'Spam'
>>> s = SpamT()
>>> print type(s).__name__
SpamT
>>> type(s).__name__
'SpamT'
"""
class Spam: pass
......
__doc__ = u"""
>>> spam == "C string 1" + "C string 2"
>>> spam == u'C string 1' + u'C string 2'
True
"""
spam = "C string 1" + "C string 2"
import sys
if sys.version_info[0] >= 3:
__doc__ = __doc__.replace(u" u'", u" '")
spam = u"C string 1" + u"C string 2"
......@@ -16,7 +16,7 @@ __doc__ = u"""
>>> f()
12.5
>>> s()
'spam'
u'spam'
>>> two()
2
>>> five()
......@@ -27,7 +27,15 @@ __doc__ = u"""
False
"""
DEF TUPLE = (1, 2, "buckle my shoe")
import sys
if sys.version_info[0] >= 3:
__doc__ = __doc__.replace(u" u'", u" '")
import sys
if sys.version_info[0] >= 3:
__doc__ = __doc__.replace(u" 042", u" 0o42")
DEF TUPLE = (1, 2, u"buckle my shoe")
DEF TRUE_FALSE = (True, False)
DEF CHAR = c'x'
......@@ -38,7 +46,7 @@ DEF INT3 = 042
DEF INT4 = -0x42
DEF LONG = 666L
DEF FLOAT = 12.5
DEF STR = "spam"
DEF STR = u"spam"
DEF TWO = TUPLE[1]
DEF FIVE = TWO + 3
DEF TRUE = TRUE_FALSE[0]
......
__doc__ = u"""
>>> e = Eggs()
>>> print type(e).__name__
Eggs
>>> type(e).__name__
'Eggs'
"""
cdef class Eggs: pass
__doc__ = u"""
>>> print type(f()).__name__
Spam
>>> type(f()).__name__
'Spam'
"""
cdef class Spam:
......
......@@ -2,13 +2,17 @@ __doc__ = u"""
>>> C().xxx(5)
5
>>> C().xxx()
'a b'
u'a b'
>>> C().xxx(42)
42
>>> C().xxx()
'a b'
u'a b'
"""
import sys
if sys.version_info[0] >= 3:
__doc__ = __doc__.replace(u" u'", u" '")
class C:
def xxx(self, p="a b"):
def xxx(self, p=u"a b"):
return p
__doc__ = u"""
>>> py_x = r'\\\\'
>>> py_x = ur'\\\\'
>>> assert x == py_x
"""
x = r'\\'
import sys
if sys.version_info[0] >= 3:
__doc__ = __doc__.replace(u" ur'", u" r'")
x = ur'\\'
__doc__ = u"""
>>> test(Exception('hi'))
Raising: Exception('hi',)
Caught: Exception('hi',)
>>> test(Exception(u'hi'))
Raising: Exception(u'hi',)
Caught: Exception(u'hi',)
"""
import sys
if sys.version_info[0] >= 3:
__doc__ = __doc__.replace(u"u'", u"'")
import sys, types
def test(obj):
print "Raising: %s%r" % (obj.__class__.__name__, obj.args)
print u"Raising: %s%r" % (obj.__class__.__name__, obj.args)
try:
raise obj
except:
......@@ -16,4 +20,4 @@ def test(obj):
assert isinstance(info[0], type)
else:
assert isinstance(info[0], types.ClassType)
print "Caught: %s%r" % (info[1].__class__.__name__, info[1].args)
print u"Caught: %s%r" % (info[1].__class__.__name__, info[1].args)
......@@ -2,7 +2,7 @@ __doc__ = u"""
>>> f()
6
>>> g()
0
2
"""
def f():
......@@ -13,8 +13,8 @@ def f():
return obj1
def g():
obj1 = 1
obj2 = 2
obj1 = 12
obj2 = 6
obj3 = 3
obj1 = obj2 / obj3
return obj1
return int(obj1)
......@@ -6,13 +6,13 @@ __doc__ = u"""
(1, 2, 3)
>>> [ str(f) for f in test(17.3, 88.6) ]
['17.3', '88.6', '105.9']
>>> test(u"eggs", u"spam")
>>> test(u'eggs', u'spam')
(u'eggs', u'spam', u'eggsspam')
"""
import sys
if sys.version_info[0] >= 3:
__doc__ = __doc__.replace(u" u'", u" '")
__doc__ = __doc__.replace(u"u'", u"'")
def add(x, y):
return x + y
......@@ -2,7 +2,7 @@ __doc__ = u"""
>>> try:
... B()
... except Exception, e:
... print "%s: %s" % (e.__class__.__name__, e)
... print("%s: %s" % (e.__class__.__name__, e))
Exception: crash-me
"""
......@@ -12,7 +12,7 @@ if sys.version_info[0] >= 3:
cdef class A:
def __cinit__(self):
raise Exception("crash-me")
raise Exception(u"crash-me")
cdef class B(A):
def __cinit__(self):
......
......@@ -2,12 +2,16 @@ __doc__ = u"""
>>> try:
... s = Spam()
... except StandardError, e:
... print "Exception:", e
... print("Exception: %s" % e)
... else:
... print "Did not raise the expected exception"
... print("Did not raise the expected exception")
Exception: This is not a spanish inquisition
"""
import sys
if sys.version_info[0] >= 3:
__doc__ = __doc__.replace(u"Exception, e", u"Exception as e")
cdef extern from "Python.h":
ctypedef class types.ListType [object PyListObject]:
pass
......
......@@ -2,12 +2,12 @@ __doc__ = u"""
>>> try:
... foo()
... except Exception, e:
... print "%s: %s" % (e.__class__.__name__, e)
... print("%s: %s" % (e.__class__.__name__, e))
ValueError:
>>> try:
... bar()
... except Exception, e:
... print "%s: %s" % (e.__class__.__name__, e)
... print("%s: %s" % (e.__class__.__name__, e))
"""
import sys
......
__doc__ = u"""
>>> s = Spam()
>>> s = Spam() #doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: function takes exactly 3 arguments (0 given)
"""
import sys, re
if sys.version_info[0] >= 3:
__doc__ = re.sub(u"Error: (.*)exactly(.*)", u"Error: \\1at most\\2", __doc__)
__doc__ = re.sub(u"Error: .*", u"Error: ...", __doc__)
cdef class Spam:
......
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