# HG changeset patch # User Paul Boddie # Date 1340058597 -7200 # Node ID ea25b91e1adc9867c719b58219303b6517dcbed2 # Parent e297c6ae4b7c228e7b207d6a30e167f688f4fbc2 Fixed the docstring for the conditional attribute usage test. Added some tests of global name attribute usage. diff -r e297c6ae4b7c -r ea25b91e1adc tests/attribute_access_type_restriction_conditional.py --- a/tests/attribute_access_type_restriction_conditional.py Thu Jun 14 22:53:23 2012 +0200 +++ b/tests/attribute_access_type_restriction_conditional.py Tue Jun 19 00:29:57 2012 +0200 @@ -1,13 +1,13 @@ #!/usr/bin/env python """ -This test attempts to record the usage of 'D' in 'test_conditional' since 'f' -and 'g' are both normally required, and only 'D' provides these attributes. -Classes 'C' and 'E' should lose their methods, even 'E.f'. +This test attempts to record the usage of 'C', 'D' or 'E' in 'test_conditional' +since 'f' and 'g' might be used, but only 'f' is actually required. Although +only 'D' provides both attributes, classes 'C' and 'E' provide 'f'. """ class C: - def f(self): # unused + def f(self): # unused but retained return 1 class D: @@ -18,7 +18,7 @@ return 3 class E: - def f(self): # unused + def f(self): # unused but retained return 4 def h(self): # unused diff -r e297c6ae4b7c -r ea25b91e1adc tests/attribute_access_type_restriction_global.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/attribute_access_type_restriction_global.py Tue Jun 19 00:29:57 2012 +0200 @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +""" +This test attempts to record the usage of 'C', 'D' or 'E' in the module code +since 'f' and 'g' might be used, but only 'f' is actually required. Although +only 'D' provides both attributes, classes 'C' and 'E' provide 'f'. +""" + +class C: + def f(self): # unused but retained + return 1 + +class D: + def f(self): + return 2 + + def g(self): + return 3 + +class E: + def f(self): # unused but retained + return 4 + + def h(self): # unused + return 5 + +c = C() +d = D() +e = E() + +obj = c +obj = d + # obj: f, g; f +if obj.f(): + x = obj.g() +else: + x = 2 + +result_3 = x + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r e297c6ae4b7c -r ea25b91e1adc tests/attribute_access_type_restriction_global_reassigned.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/attribute_access_type_restriction_global_reassigned.py Tue Jun 19 00:29:57 2012 +0200 @@ -0,0 +1,46 @@ +#!/usr/bin/env python + +""" +This test attempts to demonstrate that the usage associated with the global +'obj' cannot be reliably calculated since a function exists that rebinds the +name. +""" + +class C: + def f(self): # unused but retained + return 1 + +class D: + def f(self): + return 2 + + def g(self): + return 3 + +class E: + def f(self): # unused but retained + return 4 + + def h(self): # unused + return 5 + +def change_global(): + global obj + obj = E() # changes the global, potentially invalidating usage observations + +c = C() +d = D() +e = E() + +obj = c +obj = d + +if obj.f(): + change_global() + x = obj.g() +else: + x = 2 + +result_3 = x + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r e297c6ae4b7c -r ea25b91e1adc tests/attribute_access_type_restriction_global_usage.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/attribute_access_type_restriction_global_usage.py Tue Jun 19 00:29:57 2012 +0200 @@ -0,0 +1,48 @@ +#!/usr/bin/env python + +""" +This test attempts to record the usage of 'C', 'D' or 'E' in the module code +since 'f' and 'g' might be used, but only 'f' is actually required. Although +only 'D' provides both attributes, classes 'C' and 'E' provide 'f'. + +The local usage of 'g' in the 'local_usage' function is not currently +considered. +""" + +class C: + def f(self): # unused but retained + return 1 + +class D: + def f(self): + return 2 + + def g(self): + return 3 + +class E: + def f(self): # unused but retained + return 4 + + def h(self): # unused + return 5 + +def local_usage(): + return obj.g() # would indicate D usage + +c = C() +d = D() +e = E() + +obj = c +obj = d + # obj: f, g; f +if obj.f(): + x = obj.g() +else: + x = 2 + +result1_3 = x +result2_3 = local_usage() + +# vim: tabstop=4 expandtab shiftwidth=4