Commit 7619f085 authored by Stefan Behnel's avatar Stefan Behnel

extended getattr test case

parent a998bfe5
__doc__ = u"""
>>> class test(object): a = 1
>>> t = test()
>>> f(t, 'a') class test(object):
a = 1
t = test()
def getattr2_literal_unicode(a):
"""
>>> getattr2_literal_unicode(t)
1 1
>>> f(t, 'b') >>> getattr2_literal_unicode(object())
Traceback (most recent call last): Traceback (most recent call last):
AttributeError: 'test' object has no attribute 'b' AttributeError: 'object' object has no attribute 'a'
"""
return getattr(a, u"a")
>>> g(t, 'a', 2) def getattr3_literal_unicode(a, b):
1 """
>>> g(t, 'b', 2) >>> getattr3_literal_unicode(t, 2)
2 (1, 2)
"""
return getattr(a, u"a", b), getattr(a, u"b", b)
>>> h(t, 'a', 2) def getattr2_simple(a, b):
"""
>>> getattr2_simple(t, 'a')
1 1
>>> h(t, 'b', 2) >>> getattr2_simple(t, 'b')
2 Traceback (most recent call last):
""" AttributeError: 'test' object has no attribute 'b'
"""
def f(a, b):
return getattr(a, b) return getattr(a, b)
def g(a, b, c): def getattr3_explicit(a, b, c):
"""
>>> getattr3_explicit(t, 'a', 2)
1
>>> getattr3_explicit(t, 'b', 2)
2
"""
return getattr3(a, b, c) return getattr3(a, b, c)
def h(a, b, c): def getattr3_args(a, b, c):
"""
>>> getattr3_args(t, 'a', 2)
1
>>> getattr3_args(t, 'b', 2)
2
"""
return getattr(a, b, c) return getattr(a, b, c)
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