MCPcopy Create free account
hub / github.com/ipython/ipython / SerialLiar

Class SerialLiar

IPython/core/tests/test_oinspect.py:148–162  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

146
147
148class SerialLiar(object):
149 """Attribute accesses always get another copy of the same class.
150
151 unittest.mock.call does something similar, but it's not ideal for testing
152 as the failure mode is to eat all your RAM. This gives up after 10k levels.
153 """
154 def __init__(self, max_fibbing_twig, lies_told=0):
155 if lies_told > 10000:
156 raise RuntimeError('Nose too long, honesty is the best policy')
157 self.max_fibbing_twig = max_fibbing_twig
158 self.lies_told = lies_told
159 max_fibbing_twig[0] = max(max_fibbing_twig[0], lies_told)
160
161 def __getattr__(self, item):
162 return SerialLiar(self.max_fibbing_twig, self.lies_told + 1)
163
164#-----------------------------------------------------------------------------
165# Tests

Callers 2

__getattr__Method · 0.85
test_info_serialliarFunction · 0.85

Calls

no outgoing calls

Tested by 2

__getattr__Method · 0.68
test_info_serialliarFunction · 0.68