Commit e990db84 authored by Stefan Behnel's avatar Stefan Behnel

more test fixes

parent 2895952e
......@@ -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
......@@ -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
......@@ -5,6 +5,5 @@ __doc__ = u"""
tomatotomatotomatotomatotomatotomatotomato
"""
spam = "eggs" * 4
grail = 7 * "tomato"
spam = u"eggs" * 4
grail = 7 * u"tomato"
......@@ -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
......@@ -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
......@@ -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
......@@ -11,5 +11,4 @@ def f(a, b):
print a
print a, b
print a, b,
print 42, "spam"
print 42, u"spam"
......@@ -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"
......@@ -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
......@@ -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)
......@@ -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
......@@ -9,5 +9,5 @@ __doc__ = u"""
def go():
for i in range(5):
print "Spam!"
print u"Spam!"
......@@ -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
......
......@@ -4,5 +4,5 @@ __doc__ = u"""
"""
def frighten():
print "NOBODY", "expects", "the Spanish Inquisition!"
print u"NOBODY", u"expects", u"the Spanish Inquisition!"
......@@ -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)
......
......@@ -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"
......@@ -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
......
......@@ -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"])
......@@ -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" '")
......
......@@ -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'
......@@ -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'
......@@ -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\uf8d2Sk ik'
f = u'\xf8'
add = u'Sk ik' + u'' + 'abc'
add = u'Sk ik' + u'' + u'abc'
null = u'\x00'
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