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. ...@@ -29,7 +29,7 @@ __getattribute__ and __getattr__ special methods for a single class.
cdef class just_getattribute: cdef class just_getattribute:
def __getattribute__(self,n): def __getattribute__(self,n):
if n == 'bar': if n == u'bar':
return n return n
else: else:
raise AttributeError raise AttributeError
...@@ -39,7 +39,7 @@ cdef class just_getattr: ...@@ -39,7 +39,7 @@ cdef class just_getattr:
def __init__(self): def __init__(self):
self.foo = 10 self.foo = 10
def __getattr__(self,n): def __getattr__(self,n):
if n == 'bar': if n == u'bar':
return n return n
else: else:
raise AttributeError raise AttributeError
...@@ -49,12 +49,12 @@ cdef class both: ...@@ -49,12 +49,12 @@ cdef class both:
def __init__(self): def __init__(self):
self.foo = 10 self.foo = 10
def __getattribute__(self,n): def __getattribute__(self,n):
if n == 'foo': if n == u'foo':
return self.foo return self.foo
else: else:
raise AttributeError raise AttributeError
def __getattr__(self,n): def __getattr__(self,n):
if n == 'bar': if n == u'bar':
return n return n
else: else:
raise AttributeError raise AttributeError
...@@ -5,16 +5,16 @@ getattr does not override members. ...@@ -5,16 +5,16 @@ getattr does not override members.
>>> a = getattr_boring() >>> a = getattr_boring()
>>> a.boring_member >>> a.boring_member
10 10
>>> a.resolved_by >>> print(a.resolved_by)
'getattr_boring' getattr_boring
getattribute does. getattribute does.
>>> a = getattribute_boring() >>> a = getattribute_boring()
>>> a.boring_member >>> a.boring_member
Traceback (most recent call last): Traceback (most recent call last):
AttributeError AttributeError
>>> a.resolved_by >>> print(a.resolved_by)
'getattribute_boring' getattribute_boring
Is inherited. Is inherited.
>>> a = boring_boring_getattribute() >>> a = boring_boring_getattribute()
...@@ -24,8 +24,8 @@ Is inherited. ...@@ -24,8 +24,8 @@ Is inherited.
>>> a.boring_boring_getattribute_member >>> a.boring_boring_getattribute_member
Traceback (most recent call last): Traceback (most recent call last):
AttributeError AttributeError
>>> a.resolved_by >>> print(a.resolved_by)
'_getattribute' _getattribute
__getattribute__ is always tried first, then __getattr__, regardless of where __getattribute__ is always tried first, then __getattr__, regardless of where
in the inheritance hiarchy they came from. in the inheritance hiarchy they came from.
...@@ -33,8 +33,8 @@ in the inheritance hiarchy they came from. ...@@ -33,8 +33,8 @@ in the inheritance hiarchy they came from.
>>> a.foo >>> a.foo
Traceback (most recent call last): Traceback (most recent call last):
AttributeError AttributeError
>>> a.resolved_by >>> print(a.resolved_by)
'getattribute_boring_boring_getattr' getattribute_boring_boring_getattr
>>> a.getattribute_boring_boring_getattr >>> a.getattribute_boring_boring_getattr
True True
>>> a._getattr >>> a._getattr
...@@ -44,8 +44,8 @@ in the inheritance hiarchy they came from. ...@@ -44,8 +44,8 @@ in the inheritance hiarchy they came from.
>>> a.foo >>> a.foo
Traceback (most recent call last): Traceback (most recent call last):
AttributeError AttributeError
>>> a.resolved_by >>> print(a.resolved_by)
'_getattribute' _getattribute
>>> a.getattr_boring_boring_getattribute >>> a.getattr_boring_boring_getattribute
True True
>>> a._getattribute >>> a._getattribute
...@@ -60,36 +60,36 @@ cdef class boring: ...@@ -60,36 +60,36 @@ cdef class boring:
cdef class getattr_boring(boring): cdef class getattr_boring(boring):
def __getattr__(self,n): def __getattr__(self,n):
if n == 'resolved_by': if n == u'resolved_by':
return 'getattr_boring' return u'getattr_boring'
elif n == 'getattr_boring': elif n == u'getattr_boring':
return True return True
else: else:
raise AttributeError raise AttributeError
cdef class getattribute_boring(boring): cdef class getattribute_boring(boring):
def __getattribute__(self,n): def __getattribute__(self,n):
if n == 'resolved_by': if n == u'resolved_by':
return 'getattribute_boring' return u'getattribute_boring'
elif n == 'getattribute_boring': elif n == u'getattribute_boring':
return True return True
else: else:
raise AttributeError raise AttributeError
cdef class _getattr: cdef class _getattr:
def __getattr__(self,n): def __getattr__(self,n):
if n == 'resolved_by': if n == u'resolved_by':
return '_getattr' return u'_getattr'
elif n == '_getattr': elif n == u'_getattr':
return True return True
else: else:
raise AttributeError raise AttributeError
cdef class _getattribute(boring): cdef class _getattribute(boring):
def __getattribute__(self,n): def __getattribute__(self,n):
if n == 'resolved_by': if n == u'resolved_by':
return '_getattribute' return u'_getattribute'
elif n == '_getattribute': elif n == u'_getattribute':
return True return True
else: else:
raise AttributeError raise AttributeError
...@@ -108,19 +108,18 @@ cdef class boring_boring_getattr(boring_getattr): ...@@ -108,19 +108,18 @@ cdef class boring_boring_getattr(boring_getattr):
cdef class getattribute_boring_boring_getattr(boring_boring_getattr): cdef class getattribute_boring_boring_getattr(boring_boring_getattr):
def __getattribute__(self,n): def __getattribute__(self,n):
if n == 'resolved_by': if n == u'resolved_by':
return 'getattribute_boring_boring_getattr' return u'getattribute_boring_boring_getattr'
elif n == 'getattribute_boring_boring_getattr': elif n == u'getattribute_boring_boring_getattr':
return True return True
else: else:
raise AttributeError raise AttributeError
cdef class getattr_boring_boring_getattribute(boring_boring_getattribute): cdef class getattr_boring_boring_getattribute(boring_boring_getattribute):
def __getattr__(self,n): def __getattr__(self,n):
if n == 'resolved_by': if n == u'resolved_by':
return 'getattr_boring_boring_getattribute' return u'getattr_boring_boring_getattribute'
elif n == 'getattr_boring_boring_getattribute': elif n == u'getattr_boring_boring_getattribute':
return True return True
else: else:
raise AttributeError raise AttributeError
...@@ -5,6 +5,5 @@ __doc__ = u""" ...@@ -5,6 +5,5 @@ __doc__ = u"""
tomatotomatotomatotomatotomatotomatotomato tomatotomatotomatotomatotomatotomatotomato
""" """
spam = "eggs" * 4 spam = u"eggs" * 4
grail = 7 * "tomato" grail = 7 * u"tomato"
...@@ -11,9 +11,9 @@ __doc__ = u""" ...@@ -11,9 +11,9 @@ __doc__ = u"""
>>> len(constant()) >>> len(constant())
2 2
>>> constant()['parrot'] >>> print(constant()['parrot'])
'resting' resting
>>> constant()['answer'] >>> print(constant()['answer'])
42 42
""" """
...@@ -34,6 +34,5 @@ def keyvalues2(key1, value1, key2, value2): ...@@ -34,6 +34,5 @@ def keyvalues2(key1, value1, key2, value2):
return d return d
def constant(): def constant():
d = {"parrot":"resting", "answer":42} d = {u"parrot":u"resting", u"answer":42}
return d return d
...@@ -12,13 +12,18 @@ __doc__ = u""" ...@@ -12,13 +12,18 @@ __doc__ = u"""
>>> d >>> d
{} {}
>>> d = {'arg' : 2} >>> d = {'arg' : 2} # this should be u'arg', but Py2 can't handle it...
>>> test(**d) >>> test(**d)
{'arg': 3} {'arg': 3}
>>> d >>> d
{'arg': 2} {'arg': 2}
""" """
import sys
def test(**kw): def test(**kw):
if sys.version_info[0] >= 3:
kw[u'arg'] = 3
else:
kw['arg'] = 3 kw['arg'] = 3
return kw return kw
...@@ -3,19 +3,22 @@ __doc__ = u""" ...@@ -3,19 +3,22 @@ __doc__ = u"""
>>> g >>> g
42 42
>>> x >>> x
'spam' u'spam'
>>> y >>> y
'eggs' u'eggs'
>>> z >>> z
'spameggs' u'spameggs'
""" """
import sys
if sys.version_info[0] >= 3:
__doc__ = __doc__.replace(u" u'", u" '")
def f(): def f():
pass pass
g = 42 g = 42
x = "spam" x = u"spam"
y = "eggs" y = u"eggs"
if g: if g:
z = x + y z = x + y
...@@ -11,5 +11,4 @@ def f(a, b): ...@@ -11,5 +11,4 @@ def f(a, b):
print a print a
print a, b print a, b
print a, b, print a, b,
print 42, "spam" print 42, u"spam"
...@@ -9,9 +9,9 @@ __doc__ = u""" ...@@ -9,9 +9,9 @@ __doc__ = u"""
def swallow(name = None, airspeed = None, coconuts = None): def swallow(name = None, airspeed = None, coconuts = None):
if name is not None: if name is not None:
print "This swallow is called", name print u"This swallow is called", name
if airspeed is not None: 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: 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: ...@@ -18,10 +18,10 @@ cdef class Foo:
cdef class Fee(Foo): cdef class Fee(Foo):
def bof(self): def bof(self):
print 'Fee bof', self.val print u'Fee bof', self.val
cdef class Faa(Fee): cdef class Faa(Fee):
def bof(self): def bof(self):
print 'Foo bof', self.val print u'Foo bof', self.val
...@@ -17,8 +17,8 @@ cdef extern from "complexobject.h": ...@@ -17,8 +17,8 @@ cdef extern from "complexobject.h":
cdef Py_complex cval cdef Py_complex cval
def spam(complex c): def spam(complex c):
print "Real:", c.cval.real print u"Real:", c.cval.real
print "Imag:", c.cval.imag print u"Imag:", c.cval.imag
def eggs(): def eggs():
return complex(17, 42) return complex(17, 42)
...@@ -33,7 +33,7 @@ __doc__ = u""" ...@@ -33,7 +33,7 @@ __doc__ = u"""
cdef class Swallow: cdef class Swallow:
def __init__(self, name, airspeed, *args, **kwds): def __init__(self, name, airspeed, *args, **kwds):
print "Name:", name print u"Name:", name
print "Airspeed:", airspeed print u"Airspeed:", airspeed
print "Extra args:", args print u"Extra args:", args
print "Extra keywords:", kwds print u"Extra keywords:", kwds
...@@ -9,5 +9,5 @@ __doc__ = u""" ...@@ -9,5 +9,5 @@ __doc__ = u"""
def go(): def go():
for i in range(5): for i in range(5):
print "Spam!" print u"Spam!"
...@@ -8,7 +8,7 @@ __doc__ = u""" ...@@ -8,7 +8,7 @@ __doc__ = u"""
cdef class Parrot: cdef class Parrot:
cdef void describe(self): cdef void describe(self):
print "This parrot is resting." print u"This parrot is resting."
def describe_python(self): def describe_python(self):
self.describe() self.describe()
...@@ -16,7 +16,7 @@ cdef class Parrot: ...@@ -16,7 +16,7 @@ cdef class Parrot:
cdef class Norwegian(Parrot): cdef class Norwegian(Parrot):
cdef void describe(self): cdef void describe(self):
print "Lovely plumage!" print u"Lovely plumage!"
def test(): def test():
cdef Parrot p1, p2 cdef Parrot p1, p2
......
...@@ -4,5 +4,5 @@ __doc__ = u""" ...@@ -4,5 +4,5 @@ __doc__ = u"""
""" """
def frighten(): def frighten():
print "NOBODY", "expects", "the Spanish Inquisition!" print u"NOBODY", u"expects", u"the Spanish Inquisition!"
...@@ -9,7 +9,7 @@ class Spam: ...@@ -9,7 +9,7 @@ class Spam:
self.weight = w self.weight = w
def serve(self): def serve(self):
print self.weight, "tons of spam!" print self.weight, u"tons of spam!"
def order(): def order():
s = Spam(42) s = Spam(42)
......
...@@ -12,8 +12,8 @@ class CoconutCarrier: ...@@ -12,8 +12,8 @@ class CoconutCarrier:
def swallow(self, name = None, airspeed = None, coconuts = None): def swallow(self, name = None, airspeed = None, coconuts = None):
if name is not None: if name is not None:
print "This swallow is called", name print u"This swallow is called", name
if airspeed is not None: 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: 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: ...@@ -17,7 +17,7 @@ cdef class Spam:
self.tons = 17 self.tons = 17
def __dealloc__(self): def __dealloc__(self):
print self.tons, "tons of spam is history." print self.tons, u"tons of spam is history."
def get_tons(self): def get_tons(self):
return self.tons return self.tons
......
...@@ -5,9 +5,9 @@ __doc__ = u""" ...@@ -5,9 +5,9 @@ __doc__ = u"""
""" """
def spam(a, b, c): def spam(a, b, c):
print "Args:", a, b, c print u"Args:", a, b, c
def eggs(): def eggs():
spam(*(1,2,3)) spam(*(1,2,3))
spam(*["buckle","my","shoe"]) spam(*[u"buckle",u"my",u"shoe"])
...@@ -18,7 +18,7 @@ __doc__ = u""" ...@@ -18,7 +18,7 @@ __doc__ = u"""
import sys import sys
if sys.version_info[0] >= 3: if sys.version_info[0] >= 3:
encoding = {'encoding' : 'ASCII'} encoding = {u'encoding' : u'ASCII'}
else: else:
encoding = {} encoding = {}
__doc__ = __doc__.replace(u" b'", u" '") __doc__ = __doc__.replace(u" b'", u" '")
......
...@@ -19,7 +19,7 @@ __doc__ = r""" ...@@ -19,7 +19,7 @@ __doc__ = r"""
u'S\xf8k ik\xfc\xd6\xe4abc' u'S\xf8k ik\xfc\xd6\xe4abc'
>>> null >>> null
u'\x00' u'\x00'
""".decode("ASCII") + """ """.decode(u"ASCII") + """
>>> len(sa) >>> len(sa)
3 3
>>> len(ua) >>> len(ua)
...@@ -38,7 +38,7 @@ __doc__ = r""" ...@@ -38,7 +38,7 @@ __doc__ = r"""
12 12
>>> len(null) >>> len(null)
1 1
""".decode("ASCII") + u""" """.decode(u"ASCII") + u"""
>>> sa == 'abc' >>> sa == 'abc'
True True
>>> ua == u'abc' >>> ua == u'abc'
...@@ -76,5 +76,5 @@ d = u'üÖä' ...@@ -76,5 +76,5 @@ d = u'üÖä'
e = u'\x03\x67\xf8\uf8d2Søk ik' e = u'\x03\x67\xf8\uf8d2Søk ik'
f = u'\xf8' f = u'\xf8'
add = u'Søk ik' + u'üÖä' + 'abc' add = u'Søk ik' + u'üÖä' + u'abc'
null = u'\x00' null = u'\x00'
...@@ -25,7 +25,7 @@ __doc__ = r""" ...@@ -25,7 +25,7 @@ __doc__ = r"""
u'S\xf8k ik\xfc\xd6\xe4abc' u'S\xf8k ik\xfc\xd6\xe4abc'
>>> null >>> null
u'\x00' u'\x00'
""".decode("ASCII") + """ """.decode(u"ASCII") + """
>>> len(sa) >>> len(sa)
3 3
>>> len(ua) >>> len(ua)
...@@ -44,7 +44,7 @@ __doc__ = r""" ...@@ -44,7 +44,7 @@ __doc__ = r"""
12 12
>>> len(null) >>> len(null)
1 1
""".decode("ASCII") + u""" """.decode(u"ASCII") + u"""
>>> sa == 'abc' >>> sa == 'abc'
True True
>>> ua == u'abc' >>> ua == u'abc'
...@@ -82,5 +82,5 @@ d = u'üÖä' ...@@ -82,5 +82,5 @@ d = u'üÖä'
e = u'\x03\x67\xf8\uf8d2Søk ik' e = u'\x03\x67\xf8\uf8d2Søk ik'
f = u'\xf8' f = u'\xf8'
add = u'Søk ik' + u'üÖä' + 'abc' add = u'Søk ik' + u'üÖä' + u'abc'
null = u'\x00' null = u'\x00'
...@@ -19,7 +19,7 @@ __doc__ = r""" ...@@ -19,7 +19,7 @@ __doc__ = r"""
u'S\xf8k ik\xfc\xd6\xe4abc' u'S\xf8k ik\xfc\xd6\xe4abc'
>>> null >>> null
u'\x00' u'\x00'
""".decode("ASCII") + """ """.decode(u"ASCII") + """
>>> len(sa) >>> len(sa)
3 3
>>> len(ua) >>> len(ua)
...@@ -38,7 +38,7 @@ __doc__ = r""" ...@@ -38,7 +38,7 @@ __doc__ = r"""
12 12
>>> len(null) >>> len(null)
1 1
""".decode("ASCII") + u""" """.decode(u"ASCII") + u"""
>>> sa == 'abc' >>> sa == 'abc'
True True
>>> ua == u'abc' >>> ua == u'abc'
...@@ -76,5 +76,5 @@ d = u' ...@@ -76,5 +76,5 @@ d = u'
e = u'\x03\x67\xf8\uf8d2Sk ik' e = u'\x03\x67\xf8\uf8d2Sk ik'
f = u'\xf8' f = u'\xf8'
add = u'Sk ik' + u'' + 'abc' add = u'Sk ik' + u'' + u'abc'
null = u'\x00' 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