From: Stefan Behnel Date: Thu, 26 Aug 2010 04:08:01 +0000 (+0200) Subject: extended getattr test case X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7619f0852b08110b6302c35a6f9761770994deb5;p=cython.git extended getattr test case --- diff --git a/tests/run/getattr3call.pyx b/tests/run/getattr3call.pyx index 11f79325..12589c9f 100644 --- a/tests/run/getattr3call.pyx +++ b/tests/run/getattr3call.pyx @@ -1,29 +1,49 @@ -__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 - >>> f(t, 'b') + >>> getattr2_literal_unicode(object()) 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) - 1 - >>> g(t, 'b', 2) - 2 +def getattr3_literal_unicode(a, b): + """ + >>> getattr3_literal_unicode(t, 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 - >>> h(t, 'b', 2) - 2 -""" - -def f(a, b): + >>> getattr2_simple(t, 'b') + Traceback (most recent call last): + AttributeError: 'test' object has no attribute '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) -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)