2012-02-27 | Paul Boddie | file changeset files shortlog | Added general attribute usage recording for attribute assignments on self, even though specific attribute usage is also recorded. This prevents usage from being inadvertently incomplete. Added tests demonstrating the contribution of attribute assignments to usage observations. |
paul@297 | 1 | #!/usr/bin/env python |
paul@297 | 2 | |
paul@297 | 3 | """ |
paul@297 | 4 | This test attempts to guard 'obj' in 'test_one' with only an instance check for |
paul@297 | 5 | D instances. In the process, the unused methods should be discarded. |
paul@297 | 6 | """ |
paul@297 | 7 | |
paul@297 | 8 | class C: |
paul@297 | 9 | def f(self): # unused |
paul@297 | 10 | return 1 |
paul@297 | 11 | |
paul@297 | 12 | class D: |
paul@297 | 13 | def f(self): |
paul@297 | 14 | return 2 |
paul@297 | 15 | |
paul@297 | 16 | def __init__(self, g): |
paul@297 | 17 | self.g = g |
paul@297 | 18 | |
paul@297 | 19 | class E: |
paul@297 | 20 | def f(self): # unused |
paul@297 | 21 | return 4 |
paul@297 | 22 | |
paul@297 | 23 | def h(self): # unused |
paul@297 | 24 | return 5 |
paul@297 | 25 | |
paul@297 | 26 | def test_one(obj): |
paul@380 | 27 | # obj: f, g |
paul@380 | 28 | obj.f() |
paul@380 | 29 | return obj.g |
paul@297 | 30 | |
paul@297 | 31 | c = C() |
paul@297 | 32 | d = D(4) |
paul@297 | 33 | e = E() |
paul@297 | 34 | result1_4 = test_one(d) |
paul@297 | 35 | |
paul@297 | 36 | # vim: tabstop=4 expandtab shiftwidth=4 |