From: Stefan Behnel Date: Thu, 15 May 2008 06:00:29 +0000 (+0200) Subject: more test fixes for Py3 X-Git-Tag: 0.9.8rc1~37^2~68 X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=0427dd3dc2c9787631914b49ed4e854e92e7d129;p=cython.git more test fixes for Py3 --- diff --git a/tests/run/attr.pyx b/tests/run/attr.pyx index dc01568d..922503b1 100644 --- a/tests/run/attr.pyx +++ b/tests/run/attr.pyx @@ -1,5 +1,5 @@ __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 """ diff --git a/tests/run/cintop.pyx b/tests/run/cintop.pyx index e0a277c9..57da2ecf 100644 --- a/tests/run/cintop.pyx +++ b/tests/run/cintop.pyx @@ -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() diff --git a/tests/run/classpass.pyx b/tests/run/classpass.pyx index 9ac48f5a..2648fc00 100644 --- a/tests/run/classpass.pyx +++ b/tests/run/classpass.pyx @@ -1,11 +1,11 @@ __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 diff --git a/tests/run/concatcstrings.pyx b/tests/run/concatcstrings.pyx index ededa0f9..ca5abe69 100644 --- a/tests/run/concatcstrings.pyx +++ b/tests/run/concatcstrings.pyx @@ -1,7 +1,11 @@ __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" diff --git a/tests/run/ct_DEF.pyx b/tests/run/ct_DEF.pyx index be7588d8..39e577b9 100644 --- a/tests/run/ct_DEF.pyx +++ b/tests/run/ct_DEF.pyx @@ -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] diff --git a/tests/run/extclasspass.pyx b/tests/run/extclasspass.pyx index 4529fada..6f6082bd 100644 --- a/tests/run/extclasspass.pyx +++ b/tests/run/extclasspass.pyx @@ -1,7 +1,7 @@ __doc__ = u""" >>> e = Eggs() - >>> print type(e).__name__ - Eggs + >>> type(e).__name__ + 'Eggs' """ cdef class Eggs: pass diff --git a/tests/run/extinstantiate.pyx b/tests/run/extinstantiate.pyx index d88f80f6..8f9f21db 100644 --- a/tests/run/extinstantiate.pyx +++ b/tests/run/extinstantiate.pyx @@ -1,6 +1,6 @@ __doc__ = u""" - >>> print type(f()).__name__ - Spam + >>> type(f()).__name__ + 'Spam' """ cdef class Spam: diff --git a/tests/run/ishimoto2.pyx b/tests/run/ishimoto2.pyx index 99957853..1e8c12b6 100644 --- a/tests/run/ishimoto2.pyx +++ b/tests/run/ishimoto2.pyx @@ -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 diff --git a/tests/run/jarausch1.pyx b/tests/run/jarausch1.pyx index 0dd91bb4..8132bba2 100644 --- a/tests/run/jarausch1.pyx +++ b/tests/run/jarausch1.pyx @@ -1,6 +1,10 @@ __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'\\' diff --git a/tests/run/new_style_exceptions.pyx b/tests/run/new_style_exceptions.pyx index 3d5c3dba..9daada22 100644 --- a/tests/run/new_style_exceptions.pyx +++ b/tests/run/new_style_exceptions.pyx @@ -1,13 +1,17 @@ __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) diff --git a/tests/run/pynumop.pyx b/tests/run/pynumop.pyx index 19da90af..5f7f0028 100644 --- a/tests/run/pynumop.pyx +++ b/tests/run/pynumop.pyx @@ -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) diff --git a/tests/run/r_addint.pyx b/tests/run/r_addint.pyx index 399e6d75..098ef5b2 100644 --- a/tests/run/r_addint.pyx +++ b/tests/run/r_addint.pyx @@ -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 diff --git a/tests/run/r_barbieri1.pyx b/tests/run/r_barbieri1.pyx index 46815df3..c072e61d 100644 --- a/tests/run/r_barbieri1.pyx +++ b/tests/run/r_barbieri1.pyx @@ -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): diff --git a/tests/run/r_hordijk1.pyx b/tests/run/r_hordijk1.pyx index 76164558..3786dd53 100644 --- a/tests/run/r_hordijk1.pyx +++ b/tests/run/r_hordijk1.pyx @@ -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 diff --git a/tests/run/r_huss3.pyx b/tests/run/r_huss3.pyx index cb78d051..7fc83010 100644 --- a/tests/run/r_huss3.pyx +++ b/tests/run/r_huss3.pyx @@ -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 diff --git a/tests/run/r_toofewargs.pyx b/tests/run/r_toofewargs.pyx index 735fe86f..6479ca81 100644 --- a/tests/run/r_toofewargs.pyx +++ b/tests/run/r_toofewargs.pyx @@ -1,12 +1,12 @@ __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: