From e990db848ed569b0c0e8590932c80ac77f513b73 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Fri, 16 May 2008 20:07:49 +0200 Subject: [PATCH] more test fixes --- tests/run/__getattribute__.pyx | 8 ++-- tests/run/__getattribute_subclasses__.pyx | 57 +++++++++++------------ tests/run/cstringmul.pyx | 5 +- tests/run/dict.pyx | 9 ++-- tests/run/kwargproblems.pyx | 9 +++- tests/run/modbody.pyx | 15 +++--- tests/run/print.pyx | 3 +- tests/run/r_argdefault.pyx | 6 +-- tests/run/r_bishop3.pyx | 4 +- tests/run/r_extcomplex2.pyx | 4 +- tests/run/r_extstarargs.pyx | 8 ++-- tests/run/r_forloop.pyx | 2 +- tests/run/r_jiba1.pyx | 4 +- tests/run/r_print.pyx | 2 +- tests/run/r_pyclass.pyx | 2 +- tests/run/r_pyclassdefault.pyx | 6 +-- tests/run/r_spamtype.pyx | 2 +- tests/run/r_starargcall.pyx | 4 +- tests/run/strfunction.pyx | 2 +- tests/run/unicodeliterals.pyx | 6 +-- tests/run/unicodeliteralsdefault.pyx | 6 +-- tests/run/unicodeliteralslatin1.pyx | 6 +-- 22 files changed, 87 insertions(+), 83 deletions(-) diff --git a/tests/run/__getattribute__.pyx b/tests/run/__getattribute__.pyx index ea71bc2c..da4c1772 100644 --- a/tests/run/__getattribute__.pyx +++ b/tests/run/__getattribute__.pyx @@ -29,7 +29,7 @@ __getattribute__ and __getattr__ special methods for a single class. cdef class just_getattribute: def __getattribute__(self,n): - if n == 'bar': + if n == u'bar': return n else: raise AttributeError @@ -39,7 +39,7 @@ cdef class just_getattr: def __init__(self): self.foo = 10 def __getattr__(self,n): - if n == 'bar': + if n == u'bar': return n else: raise AttributeError @@ -49,12 +49,12 @@ cdef class both: def __init__(self): self.foo = 10 def __getattribute__(self,n): - if n == 'foo': + if n == u'foo': return self.foo else: raise AttributeError def __getattr__(self,n): - if n == 'bar': + if n == u'bar': return n else: raise AttributeError diff --git a/tests/run/__getattribute_subclasses__.pyx b/tests/run/__getattribute_subclasses__.pyx index a64f3a3c..68906710 100644 --- a/tests/run/__getattribute_subclasses__.pyx +++ b/tests/run/__getattribute_subclasses__.pyx @@ -5,16 +5,16 @@ getattr does not override members. >>> a = getattr_boring() >>> a.boring_member 10 - >>> a.resolved_by - 'getattr_boring' + >>> print(a.resolved_by) + getattr_boring getattribute does. >>> a = getattribute_boring() >>> a.boring_member Traceback (most recent call last): AttributeError - >>> a.resolved_by - 'getattribute_boring' + >>> print(a.resolved_by) + getattribute_boring Is inherited. >>> a = boring_boring_getattribute() @@ -24,8 +24,8 @@ Is inherited. >>> a.boring_boring_getattribute_member Traceback (most recent call last): AttributeError - >>> a.resolved_by - '_getattribute' + >>> print(a.resolved_by) + _getattribute __getattribute__ is always tried first, then __getattr__, regardless of where in the inheritance hiarchy they came from. @@ -33,8 +33,8 @@ in the inheritance hiarchy they came from. >>> a.foo Traceback (most recent call last): AttributeError - >>> a.resolved_by - 'getattribute_boring_boring_getattr' + >>> print(a.resolved_by) + getattribute_boring_boring_getattr >>> a.getattribute_boring_boring_getattr True >>> a._getattr @@ -44,8 +44,8 @@ in the inheritance hiarchy they came from. >>> a.foo Traceback (most recent call last): AttributeError - >>> a.resolved_by - '_getattribute' + >>> print(a.resolved_by) + _getattribute >>> a.getattr_boring_boring_getattribute True >>> a._getattribute @@ -60,36 +60,36 @@ cdef class boring: cdef class getattr_boring(boring): def __getattr__(self,n): - if n == 'resolved_by': - return 'getattr_boring' - elif n == 'getattr_boring': + if n == u'resolved_by': + return u'getattr_boring' + elif n == u'getattr_boring': return True else: raise AttributeError cdef class getattribute_boring(boring): def __getattribute__(self,n): - if n == 'resolved_by': - return 'getattribute_boring' - elif n == 'getattribute_boring': + if n == u'resolved_by': + return u'getattribute_boring' + elif n == u'getattribute_boring': return True else: raise AttributeError cdef class _getattr: def __getattr__(self,n): - if n == 'resolved_by': - return '_getattr' - elif n == '_getattr': + if n == u'resolved_by': + return u'_getattr' + elif n == u'_getattr': return True else: raise AttributeError cdef class _getattribute(boring): def __getattribute__(self,n): - if n == 'resolved_by': - return '_getattribute' - elif n == '_getattribute': + if n == u'resolved_by': + return u'_getattribute' + elif n == u'_getattribute': return True else: raise AttributeError @@ -108,19 +108,18 @@ cdef class boring_boring_getattr(boring_getattr): cdef class getattribute_boring_boring_getattr(boring_boring_getattr): def __getattribute__(self,n): - if n == 'resolved_by': - return 'getattribute_boring_boring_getattr' - elif n == 'getattribute_boring_boring_getattr': + if n == u'resolved_by': + return u'getattribute_boring_boring_getattr' + elif n == u'getattribute_boring_boring_getattr': return True else: raise AttributeError cdef class getattr_boring_boring_getattribute(boring_boring_getattribute): def __getattr__(self,n): - if n == 'resolved_by': - return 'getattr_boring_boring_getattribute' - elif n == 'getattr_boring_boring_getattribute': + if n == u'resolved_by': + return u'getattr_boring_boring_getattribute' + elif n == u'getattr_boring_boring_getattribute': return True else: raise AttributeError - diff --git a/tests/run/cstringmul.pyx b/tests/run/cstringmul.pyx index c4c638b8..cf40b039 100644 --- a/tests/run/cstringmul.pyx +++ b/tests/run/cstringmul.pyx @@ -5,6 +5,5 @@ __doc__ = u""" tomatotomatotomatotomatotomatotomatotomato """ -spam = "eggs" * 4 -grail = 7 * "tomato" - +spam = u"eggs" * 4 +grail = 7 * u"tomato" diff --git a/tests/run/dict.pyx b/tests/run/dict.pyx index 6058a952..360d77cc 100644 --- a/tests/run/dict.pyx +++ b/tests/run/dict.pyx @@ -11,9 +11,9 @@ __doc__ = u""" >>> len(constant()) 2 - >>> constant()['parrot'] - 'resting' - >>> constant()['answer'] + >>> print(constant()['parrot']) + resting + >>> print(constant()['answer']) 42 """ @@ -34,6 +34,5 @@ def keyvalues2(key1, value1, key2, value2): return d def constant(): - d = {"parrot":"resting", "answer":42} + d = {u"parrot":u"resting", u"answer":42} return d - diff --git a/tests/run/kwargproblems.pyx b/tests/run/kwargproblems.pyx index e22651cb..346baaab 100644 --- a/tests/run/kwargproblems.pyx +++ b/tests/run/kwargproblems.pyx @@ -12,13 +12,18 @@ __doc__ = u""" >>> d {} - >>> d = {'arg' : 2} + >>> d = {'arg' : 2} # this should be u'arg', but Py2 can't handle it... >>> test(**d) {'arg': 3} >>> d {'arg': 2} """ +import sys + def test(**kw): - kw['arg'] = 3 + if sys.version_info[0] >= 3: + kw[u'arg'] = 3 + else: + kw['arg'] = 3 return kw diff --git a/tests/run/modbody.pyx b/tests/run/modbody.pyx index 82a152a0..76d2869f 100644 --- a/tests/run/modbody.pyx +++ b/tests/run/modbody.pyx @@ -3,19 +3,22 @@ __doc__ = u""" >>> g 42 >>> x - 'spam' + u'spam' >>> y - 'eggs' + u'eggs' >>> z - 'spameggs' + u'spameggs' """ +import sys +if sys.version_info[0] >= 3: + __doc__ = __doc__.replace(u" u'", u" '") + def f(): pass g = 42 -x = "spam" -y = "eggs" +x = u"spam" +y = u"eggs" if g: z = x + y - diff --git a/tests/run/print.pyx b/tests/run/print.pyx index afcb7829..9937dc3e 100644 --- a/tests/run/print.pyx +++ b/tests/run/print.pyx @@ -11,5 +11,4 @@ def f(a, b): print a print a, b print a, b, - print 42, "spam" - + print 42, u"spam" diff --git a/tests/run/r_argdefault.pyx b/tests/run/r_argdefault.pyx index d321d2ab..4d887703 100644 --- a/tests/run/r_argdefault.pyx +++ b/tests/run/r_argdefault.pyx @@ -9,9 +9,9 @@ __doc__ = u""" def swallow(name = None, airspeed = None, coconuts = None): if name is not None: - print "This swallow is called", name + print u"This swallow is called", name if airspeed is not None: - print "This swallow is flying at", airspeed, "furlongs per fortnight" + print u"This swallow is flying at", airspeed, u"furlongs per fortnight" if coconuts is not None: - print "This swallow is carrying", coconuts, "coconuts" + print u"This swallow is carrying", coconuts, u"coconuts" diff --git a/tests/run/r_bishop3.pyx b/tests/run/r_bishop3.pyx index d4aa7b36..8d2133e6 100644 --- a/tests/run/r_bishop3.pyx +++ b/tests/run/r_bishop3.pyx @@ -18,10 +18,10 @@ cdef class Foo: cdef class Fee(Foo): def bof(self): - print 'Fee bof', self.val + print u'Fee bof', self.val cdef class Faa(Fee): def bof(self): - print 'Foo bof', self.val + print u'Foo bof', self.val diff --git a/tests/run/r_extcomplex2.pyx b/tests/run/r_extcomplex2.pyx index 53292ff5..fa1ef232 100644 --- a/tests/run/r_extcomplex2.pyx +++ b/tests/run/r_extcomplex2.pyx @@ -17,8 +17,8 @@ cdef extern from "complexobject.h": cdef Py_complex cval def spam(complex c): - print "Real:", c.cval.real - print "Imag:", c.cval.imag + print u"Real:", c.cval.real + print u"Imag:", c.cval.imag def eggs(): return complex(17, 42) diff --git a/tests/run/r_extstarargs.pyx b/tests/run/r_extstarargs.pyx index 0c474427..a2a8aa44 100644 --- a/tests/run/r_extstarargs.pyx +++ b/tests/run/r_extstarargs.pyx @@ -33,7 +33,7 @@ __doc__ = u""" cdef class Swallow: def __init__(self, name, airspeed, *args, **kwds): - print "Name:", name - print "Airspeed:", airspeed - print "Extra args:", args - print "Extra keywords:", kwds + print u"Name:", name + print u"Airspeed:", airspeed + print u"Extra args:", args + print u"Extra keywords:", kwds diff --git a/tests/run/r_forloop.pyx b/tests/run/r_forloop.pyx index 7fb8dbcf..4dc7b376 100644 --- a/tests/run/r_forloop.pyx +++ b/tests/run/r_forloop.pyx @@ -9,5 +9,5 @@ __doc__ = u""" def go(): for i in range(5): - print "Spam!" + print u"Spam!" diff --git a/tests/run/r_jiba1.pyx b/tests/run/r_jiba1.pyx index f1bfed64..35596d1d 100644 --- a/tests/run/r_jiba1.pyx +++ b/tests/run/r_jiba1.pyx @@ -8,7 +8,7 @@ __doc__ = u""" cdef class Parrot: cdef void describe(self): - print "This parrot is resting." + print u"This parrot is resting." def describe_python(self): self.describe() @@ -16,7 +16,7 @@ cdef class Parrot: cdef class Norwegian(Parrot): cdef void describe(self): - print "Lovely plumage!" + print u"Lovely plumage!" def test(): cdef Parrot p1, p2 diff --git a/tests/run/r_print.pyx b/tests/run/r_print.pyx index 6a904ad2..ea716dff 100644 --- a/tests/run/r_print.pyx +++ b/tests/run/r_print.pyx @@ -4,5 +4,5 @@ __doc__ = u""" """ def frighten(): - print "NOBODY", "expects", "the Spanish Inquisition!" + print u"NOBODY", u"expects", u"the Spanish Inquisition!" diff --git a/tests/run/r_pyclass.pyx b/tests/run/r_pyclass.pyx index 8ed93e0e..68342245 100644 --- a/tests/run/r_pyclass.pyx +++ b/tests/run/r_pyclass.pyx @@ -9,7 +9,7 @@ class Spam: self.weight = w def serve(self): - print self.weight, "tons of spam!" + print self.weight, u"tons of spam!" def order(): s = Spam(42) diff --git a/tests/run/r_pyclassdefault.pyx b/tests/run/r_pyclassdefault.pyx index 234ac86b..bc83f49f 100644 --- a/tests/run/r_pyclassdefault.pyx +++ b/tests/run/r_pyclassdefault.pyx @@ -12,8 +12,8 @@ class CoconutCarrier: def swallow(self, name = None, airspeed = None, coconuts = None): if name is not None: - print "This swallow is called", name + print u"This swallow is called", name if airspeed is not None: - print "This swallow is flying at", airspeed, "furlongs per fortnight" + print u"This swallow is flying at", airspeed, "furlongs per fortnight" if coconuts is not None: - print "This swallow is carrying", coconuts, "coconuts" + print u"This swallow is carrying", coconuts, "coconuts" diff --git a/tests/run/r_spamtype.pyx b/tests/run/r_spamtype.pyx index 70d85ea0..cfa94fbb 100644 --- a/tests/run/r_spamtype.pyx +++ b/tests/run/r_spamtype.pyx @@ -17,7 +17,7 @@ cdef class Spam: self.tons = 17 def __dealloc__(self): - print self.tons, "tons of spam is history." + print self.tons, u"tons of spam is history." def get_tons(self): return self.tons diff --git a/tests/run/r_starargcall.pyx b/tests/run/r_starargcall.pyx index 97fbeb42..dbd47ee1 100644 --- a/tests/run/r_starargcall.pyx +++ b/tests/run/r_starargcall.pyx @@ -5,9 +5,9 @@ __doc__ = u""" """ def spam(a, b, c): - print "Args:", a, b, c + print u"Args:", a, b, c def eggs(): spam(*(1,2,3)) - spam(*["buckle","my","shoe"]) + spam(*[u"buckle",u"my",u"shoe"]) diff --git a/tests/run/strfunction.pyx b/tests/run/strfunction.pyx index b0bc01d0..3f0ca9d5 100644 --- a/tests/run/strfunction.pyx +++ b/tests/run/strfunction.pyx @@ -18,7 +18,7 @@ __doc__ = u""" import sys if sys.version_info[0] >= 3: - encoding = {'encoding' : 'ASCII'} + encoding = {u'encoding' : u'ASCII'} else: encoding = {} __doc__ = __doc__.replace(u" b'", u" '") diff --git a/tests/run/unicodeliterals.pyx b/tests/run/unicodeliterals.pyx index 7c271b73..2d08606e 100644 --- a/tests/run/unicodeliterals.pyx +++ b/tests/run/unicodeliterals.pyx @@ -19,7 +19,7 @@ __doc__ = r""" u'S\xf8k ik\xfc\xd6\xe4abc' >>> null u'\x00' -""".decode("ASCII") + """ +""".decode(u"ASCII") + """ >>> len(sa) 3 >>> len(ua) @@ -38,7 +38,7 @@ __doc__ = r""" 12 >>> len(null) 1 -""".decode("ASCII") + u""" +""".decode(u"ASCII") + u""" >>> sa == 'abc' True >>> ua == u'abc' @@ -76,5 +76,5 @@ d = u'üÖä' e = u'\x03\x67\xf8\uf8d2Søk ik' f = u'\xf8' -add = u'Søk ik' + u'üÖä' + 'abc' +add = u'Søk ik' + u'üÖä' + u'abc' null = u'\x00' diff --git a/tests/run/unicodeliteralsdefault.pyx b/tests/run/unicodeliteralsdefault.pyx index 7123ee32..05129fd3 100644 --- a/tests/run/unicodeliteralsdefault.pyx +++ b/tests/run/unicodeliteralsdefault.pyx @@ -25,7 +25,7 @@ __doc__ = r""" u'S\xf8k ik\xfc\xd6\xe4abc' >>> null u'\x00' -""".decode("ASCII") + """ +""".decode(u"ASCII") + """ >>> len(sa) 3 >>> len(ua) @@ -44,7 +44,7 @@ __doc__ = r""" 12 >>> len(null) 1 -""".decode("ASCII") + u""" +""".decode(u"ASCII") + u""" >>> sa == 'abc' True >>> ua == u'abc' @@ -82,5 +82,5 @@ d = u'üÖä' e = u'\x03\x67\xf8\uf8d2Søk ik' f = u'\xf8' -add = u'Søk ik' + u'üÖä' + 'abc' +add = u'Søk ik' + u'üÖä' + u'abc' null = u'\x00' diff --git a/tests/run/unicodeliteralslatin1.pyx b/tests/run/unicodeliteralslatin1.pyx index 2ab8a20a..ed0817dc 100644 --- a/tests/run/unicodeliteralslatin1.pyx +++ b/tests/run/unicodeliteralslatin1.pyx @@ -19,7 +19,7 @@ __doc__ = r""" u'S\xf8k ik\xfc\xd6\xe4abc' >>> null u'\x00' -""".decode("ASCII") + """ +""".decode(u"ASCII") + """ >>> len(sa) 3 >>> len(ua) @@ -38,7 +38,7 @@ __doc__ = r""" 12 >>> len(null) 1 -""".decode("ASCII") + u""" +""".decode(u"ASCII") + u""" >>> sa == 'abc' True >>> ua == u'abc' @@ -76,5 +76,5 @@ d = u' e = u'\x03\x67\xf8\uf8d2Søk ik' f = u'\xf8' -add = u'Søk ik' + u'üÖä' + 'abc' +add = u'Søk ik' + u'üÖä' + u'abc' null = u'\x00' -- 2.26.2