mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Allow the four required arguments to be passed by position or keyword, matching CPython and fixing pytest Node.warn calls. Add regression coverage for mixed calls, warning instances, and invalid argument binding. Codex implemented the fix and regression tests, ran validation, and drafted this commit and the PR description. The contributor manually verified the warning reproducer. Assisted-by: Codex:GPT-6
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
import warnings
|
|
|
|
from testutils import assert_raises
|
|
|
|
names = ("message", "category", "filename", "lineno")
|
|
for message, category in (("probe", UserWarning), (UserWarning("probe"), None)):
|
|
values = (message, category, "probe.py", 7)
|
|
for positional_count in range(5):
|
|
with warnings.catch_warnings(record=True) as caught:
|
|
warnings.simplefilter("always")
|
|
warnings.warn_explicit(
|
|
*values[:positional_count],
|
|
**dict(zip(names[positional_count:], values[positional_count:])),
|
|
)
|
|
assert len(caught) == 1
|
|
warning = caught[0]
|
|
assert str(warning.message) == "probe"
|
|
assert warning.category is UserWarning
|
|
assert warning.filename == "probe.py"
|
|
assert warning.lineno == 7
|
|
|
|
arguments = dict(zip(names, ("probe", UserWarning, "probe.py", 7)))
|
|
for name in names:
|
|
missing = arguments.copy()
|
|
del missing[name]
|
|
with assert_raises(TypeError):
|
|
warnings.warn_explicit(**missing)
|
|
|
|
with assert_raises(TypeError):
|
|
warnings.warn_explicit("probe", **arguments)
|