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@304 | 1 | #!/usr/bin/env python |
paul@304 | 2 | |
paul@304 | 3 | """ |
paul@304 | 4 | This test attempts to cause the recording of the usage of 'C' in the function |
paul@318 | 5 | 'f', alongside the expectation that 'D' might be used instead with the function |
paul@318 | 6 | 'g'. A guard cannot therefore be generated. Meanwhile, the method 'E.h' should |
paul@318 | 7 | be eliminated. |
paul@304 | 8 | """ |
paul@304 | 9 | |
paul@304 | 10 | class C: |
paul@304 | 11 | def f(self): |
paul@304 | 12 | return 1 |
paul@304 | 13 | |
paul@304 | 14 | class D: |
paul@304 | 15 | def g(self): |
paul@304 | 16 | return 2 |
paul@304 | 17 | |
paul@304 | 18 | class E: |
paul@304 | 19 | def h(self): # unused |
paul@304 | 20 | return 3 |
paul@304 | 21 | |
paul@304 | 22 | def f(c): |
paul@304 | 23 | if 1: |
paul@304 | 24 | return c.f() |
paul@304 | 25 | return c.g() |
paul@304 | 26 | |
paul@304 | 27 | c = C() |
paul@304 | 28 | d = D() |
paul@304 | 29 | e = E() |
paul@304 | 30 | result1_1 = f(c) |
paul@304 | 31 | |
paul@304 | 32 | # vim: tabstop=4 expandtab shiftwidth=4 |