summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErlend E. Aasland <erlend@python.org>2023-07-03 20:16:50 (GMT)
committerGitHub <noreply@github.com>2023-07-03 20:16:50 (GMT)
commit7f4c8121db62a9f72f00f2d9f73381e82f289581 (patch)
treec1bf694724264f3e620157ea1d76ada43ed2fa7b
parentbf06c6825cadeda54a9c0848fa51463a0e0b2cf8 (diff)
downloadcpython-7f4c8121db62a9f72f00f2d9f73381e82f289581.zip
cpython-7f4c8121db62a9f72f00f2d9f73381e82f289581.tar.gz
cpython-7f4c8121db62a9f72f00f2d9f73381e82f289581.tar.bz2
gh-106368: Increase Argument Clinic test coverage (#106369)
Add tests for 'self' and 'defining_class' converter requirements.
-rw-r--r--Lib/test/test_clinic.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py
index fab2d2b..51d2ac9 100644
--- a/Lib/test/test_clinic.py
+++ b/Lib/test/test_clinic.py
@@ -829,6 +829,63 @@ Annotations must be either a name, a function call, or a string.
out = self.parse_function_should_fail(fn)
self.assertEqual(out, expected_error_msg)
+ def test_self_param_placement(self):
+ expected_error_msg = (
+ "Error on line 0:\n"
+ "A 'self' parameter, if specified, must be the very first thing "
+ "in the parameter block.\n"
+ )
+ block = """
+ module foo
+ foo.func
+ a: int
+ self: self(type="PyObject *")
+ """
+ out = self.parse_function_should_fail(block)
+ self.assertEqual(out, expected_error_msg)
+
+ def test_self_param_cannot_be_optional(self):
+ expected_error_msg = (
+ "Error on line 0:\n"
+ "A 'self' parameter cannot be marked optional.\n"
+ )
+ block = """
+ module foo
+ foo.func
+ self: self(type="PyObject *") = None
+ """
+ out = self.parse_function_should_fail(block)
+ self.assertEqual(out, expected_error_msg)
+
+ def test_defining_class_param_placement(self):
+ expected_error_msg = (
+ "Error on line 0:\n"
+ "A 'defining_class' parameter, if specified, must either be the "
+ "first thing in the parameter block, or come just after 'self'.\n"
+ )
+ block = """
+ module foo
+ foo.func
+ self: self(type="PyObject *")
+ a: int
+ cls: defining_class
+ """
+ out = self.parse_function_should_fail(block)
+ self.assertEqual(out, expected_error_msg)
+
+ def test_defining_class_param_cannot_be_optional(self):
+ expected_error_msg = (
+ "Error on line 0:\n"
+ "A 'defining_class' parameter cannot be marked optional.\n"
+ )
+ block = """
+ module foo
+ foo.func
+ cls: defining_class(type="PyObject *") = None
+ """
+ out = self.parse_function_should_fail(block)
+ self.assertEqual(out, expected_error_msg)
+
def test_unused_param(self):
block = self.parse("""
module foo