Attribute accesses always get another copy of the same class. unittest.mock.call does something similar, but it's not ideal for testing as the failure mode is to eat all your RAM. This gives up after 10k levels.
| 165 | |
| 166 | |
| 167 | class SerialLiar(object): |
| 168 | """Attribute accesses always get another copy of the same class. |
| 169 | |
| 170 | unittest.mock.call does something similar, but it's not ideal for testing |
| 171 | as the failure mode is to eat all your RAM. This gives up after 10k levels. |
| 172 | """ |
| 173 | |
| 174 | def __init__(self, max_fibbing_twig, lies_told=0): |
| 175 | if lies_told > 10000: |
| 176 | raise RuntimeError("Nose too long, honesty is the best policy") |
| 177 | self.max_fibbing_twig = max_fibbing_twig |
| 178 | self.lies_told = lies_told |
| 179 | max_fibbing_twig[0] = max(max_fibbing_twig[0], lies_told) |
| 180 | |
| 181 | def __getattr__(self, item): |
| 182 | return SerialLiar(self.max_fibbing_twig, self.lies_told + 1) |
| 183 | |
| 184 | |
| 185 | # ----------------------------------------------------------------------------- |
no outgoing calls
searching dependent graphs…