MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_excessive_getattr

Method test_excessive_getattr

Lib/test/test_rlcompleter.py:104–123  ·  view source on GitHub ↗

Ensure getattr() is invoked no more than once per attribute

(self)

Source from the content-addressed store, hash-verified

102 if x.startswith('s')])
103
104 def test_excessive_getattr(self):
105 """Ensure getattr() is invoked no more than once per attribute"""
106
107 # note the special case for @property methods below; that is why
108 # we use __dir__ and __getattr__ in class Foo to create a "magic"
109 # class attribute 'bar'. This forces `getattr` to call __getattr__
110 # (which is doesn't necessarily do).
111 class Foo:
112 calls = 0
113 bar = ''
114 def __getattribute__(self, name):
115 if name == 'bar':
116 self.calls += 1
117 return None
118 return super().__getattribute__(name)
119
120 f = Foo()
121 completer = rlcompleter.Completer(dict(f=f))
122 self.assertEqual(completer.complete('f.b', 0), 'f.bar')
123 self.assertEqual(f.calls, 1)
124
125 def test_property_method_not_called(self):
126 class Foo:

Callers

nothing calls this directly

Calls 3

completeMethod · 0.95
FooClass · 0.70
assertEqualMethod · 0.45

Tested by

no test coverage detected