diff options
author | Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com> | 2020-05-22 20:40:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-22 20:40:17 (GMT) |
commit | b5cc2089cc354469f12eabc7ba54280e85fdd6dc (patch) | |
tree | 288c14c85592ce4672fbf50d47a94c7daf47f0b0 /Lib/test/test_call.py | |
parent | 7c30d12bd5359b0f66c4fbc98aa055398bcc8a7e (diff) | |
download | cpython-b5cc2089cc354469f12eabc7ba54280e85fdd6dc.zip cpython-b5cc2089cc354469f12eabc7ba54280e85fdd6dc.tar.gz cpython-b5cc2089cc354469f12eabc7ba54280e85fdd6dc.tar.bz2 |
bpo-40679: Use the function's qualname in certain TypeErrors (GH-20236)
Patch by Dennis Sweeney.
Diffstat (limited to 'Lib/test/test_call.py')
-rw-r--r-- | Lib/test/test_call.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/Lib/test/test_call.py b/Lib/test/test_call.py index 451a717..3f45922 100644 --- a/Lib/test/test_call.py +++ b/Lib/test/test_call.py @@ -8,6 +8,7 @@ import struct import collections import itertools import gc +import contextlib class FunctionCalls(unittest.TestCase): @@ -665,5 +666,52 @@ class TestPEP590(unittest.TestCase): self.assertEqual(expected, wrapped(*args, **kwargs)) +class A: + def method_two_args(self, x, y): + pass + + @staticmethod + def static_no_args(): + pass + + @staticmethod + def positional_only(arg, /): + pass + +@cpython_only +class TestErrorMessagesUseQualifiedName(unittest.TestCase): + + @contextlib.contextmanager + def check_raises_type_error(self, message): + with self.assertRaises(TypeError) as cm: + yield + self.assertEqual(str(cm.exception), message) + + def test_missing_arguments(self): + msg = "A.method_two_args() missing 1 required positional argument: 'y'" + with self.check_raises_type_error(msg): + A().method_two_args("x") + + def test_too_many_positional(self): + msg = "A.static_no_args() takes 0 positional arguments but 1 was given" + with self.check_raises_type_error(msg): + A.static_no_args("oops it's an arg") + + def test_positional_only_passed_as_keyword(self): + msg = "A.positional_only() got some positional-only arguments passed as keyword arguments: 'arg'" + with self.check_raises_type_error(msg): + A.positional_only(arg="x") + + def test_unexpected_keyword(self): + msg = "A.method_two_args() got an unexpected keyword argument 'bad'" + with self.check_raises_type_error(msg): + A().method_two_args(bad="x") + + def test_multiple_values(self): + msg = "A.method_two_args() got multiple values for argument 'x'" + with self.check_raises_type_error(msg): + A().method_two_args("x", "y", x="oops") + + if __name__ == "__main__": unittest.main() |