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

more test fixes for Py3

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