gh-106368: Increase Argument Clinic test coverage (#106728)

- improve output_parameter() coverage
- improve coverage for Function.kind
This commit is contained in:
Erlend E. Aasland 2023-07-14 00:18:32 +02:00 committed by GitHub
parent f014f1567c
commit ec45c513d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 590 additions and 0 deletions

View file

@ -1013,6 +1013,43 @@ class ClinicParserTest(TestCase):
out = self.parse_function_should_fail(block)
self.assertEqual(out, expected_error_msg)
def test_slot_methods_cannot_access_defining_class(self):
block = """
module foo
class Foo "" ""
Foo.__init__
cls: defining_class
a: object
"""
msg = "Slot methods cannot access their defining class."
with self.assertRaisesRegex(ValueError, msg):
self.parse_function(block)
def test_new_must_be_a_class_method(self):
expected_error_msg = (
"Error on line 0:\n"
"__new__ must be a class method!\n"
)
out = self.parse_function_should_fail("""
module foo
class Foo "" ""
Foo.__new__
""")
self.assertEqual(out, expected_error_msg)
def test_init_must_be_a_normal_method(self):
expected_error_msg = (
"Error on line 0:\n"
"__init__ must be a normal method, not a class or static method!\n"
)
out = self.parse_function_should_fail("""
module foo
class Foo "" ""
@classmethod
Foo.__init__
""")
self.assertEqual(out, expected_error_msg)
def test_unused_param(self):
block = self.parse("""
module foo