# HG changeset patch # User Paul Boddie # Date 1367443945 -7200 # Node ID c52c50dca9dc6c72b509977c4254bde392897af8 # Parent b9e902f5020dd6ad8f061b4150d0d34918754dfb Added some tests of dynamic attribute access using getattr and string constants. diff -r b9e902f5020d -r c52c50dca9dc tests/getattr_instance_methods_dynamic.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/getattr_instance_methods_dynamic.py Wed May 01 23:32:25 2013 +0200 @@ -0,0 +1,19 @@ +#!/usr/bin/env python + +class C: + def x(self): + return 1 + +class D: + def x(self): + return 2 + +def f(obj, attrname): + return getattr(obj, attrname) + +c = C() +d = D() +result_1 = f(c, "x")() +result_2 = f(d, "x")() + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r b9e902f5020d -r c52c50dca9dc tests/getattr_instance_methods_dynamic_chained.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/getattr_instance_methods_dynamic_chained.py Wed May 01 23:32:25 2013 +0200 @@ -0,0 +1,25 @@ +#!/usr/bin/env python + +class C: + def x(self, obj): + return getattr(obj, "y")(obj) + + def y(self, obj): + return getattr(obj, "z")(obj) + + def z(self, obj): + return 1 + +class D: + def x(self): + return 2 + +def f(obj, attrname): + return getattr(obj, attrname)(obj) + +c = C() +d = D() +result_1 = f(c, "x")() +result_2 = f(d, "x")() + +# vim: tabstop=4 expandtab shiftwidth=4