MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_generated_dunder_methods_pos_only

Function test_generated_dunder_methods_pos_only

tests/test_enum.py:280–335  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

278
279
280def test_generated_dunder_methods_pos_only():
281 for enum_type in [m.ScopedEnum, m.UnscopedEnum]:
282 for binary_op in [
283 "__eq__",
284 "__ne__",
285 "__ge__",
286 "__gt__",
287 "__lt__",
288 "__le__",
289 "__and__",
290 "__rand__",
291 # "__or__", # fail with some compilers (__doc__ = "Return self|value.")
292 # "__ror__", # fail with some compilers (__doc__ = "Return value|self.")
293 "__xor__",
294 "__rxor__",
295 "__rxor__",
296 ]:
297 method = getattr(enum_type, binary_op, None)
298 if method is not None:
299 assert (
300 re.match(
301 rf"^{binary_op}\(self: [\w\.]+, other: [\w\.]+, /\)",
302 method.__doc__,
303 )
304 is not None
305 )
306 for unary_op in [
307 "__int__",
308 "__index__",
309 "__hash__",
310 "__str__",
311 "__repr__",
312 ]:
313 method = getattr(enum_type, unary_op, None)
314 if method is not None:
315 assert (
316 re.match(
317 rf"^{unary_op}\(self: [\w\.]+, /\)",
318 method.__doc__,
319 )
320 is not None
321 )
322 assert (
323 re.match(
324 r"^__getstate__\(self: [\w\.]+, /\)",
325 enum_type.__getstate__.__doc__,
326 )
327 is not None
328 )
329 assert (
330 re.match(
331 r"^__setstate__\(self: [\w\.]+, state: [\w\. \|]+, /\)",
332 enum_type.__setstate__.__doc__,
333 )
334 is not None
335 )
336
337

Callers

nothing calls this directly

Calls 1

getattrFunction · 0.85

Tested by

no test coverage detected