MCPcopy
hub / github.com/pydantic/pydantic / test_functools

Function test_functools

tests/test_computed_fields.py:260–284  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

258
259
260def test_functools():
261 class Model(BaseModel, frozen=True):
262 x: int
263
264 @lru_cache
265 def x_pow(self, p):
266 return self.x**p
267
268 @singledispatchmethod
269 def neg(self, arg):
270 raise NotImplementedError('Cannot negate a')
271
272 @neg.register
273 def _(self, arg: int):
274 return -arg
275
276 @neg.register
277 def _(self, arg: bool):
278 return not arg
279
280 m = Model(x=2)
281 assert m.x_pow(1) == 2
282 assert m.x_pow(2) == 4
283 assert m.neg(1) == -1
284 assert m.neg(True) is False
285
286
287def test_include_exclude():

Callers

nothing calls this directly

Calls 3

x_powMethod · 0.95
negMethod · 0.95
ModelClass · 0.70

Tested by

no test coverage detected