Skip to content

gh-104683: clinic.py: Improve coverage for the parse_converter method #104729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,45 @@ def test_legacy_converters(self):
module, function = block.signatures
self.assertIsInstance((function.parameters['path']).converter, clinic.str_converter)

def test_legacy_converters_non_string_constant_annotation(self):
expected_failure_message = """\
Error on line 0:
Annotations must be either a name, a function call, or a string.
"""

s = self.parse_function_should_fail('module os\nos.access\n path: 42')
self.assertEqual(s, expected_failure_message)

s = self.parse_function_should_fail('module os\nos.access\n path: 42.42')
self.assertEqual(s, expected_failure_message)

s = self.parse_function_should_fail('module os\nos.access\n path: 42j')
self.assertEqual(s, expected_failure_message)

s = self.parse_function_should_fail('module os\nos.access\n path: b"42"')
self.assertEqual(s, expected_failure_message)

def test_other_bizarre_things_in_annotations_fail(self):
expected_failure_message = """\
Error on line 0:
Annotations must be either a name, a function call, or a string.
"""

s = self.parse_function_should_fail(
'module os\nos.access\n path: {"some": "dictionary"}'
)
self.assertEqual(s, expected_failure_message)

s = self.parse_function_should_fail(
'module os\nos.access\n path: ["list", "of", "strings"]'
)
self.assertEqual(s, expected_failure_message)

s = self.parse_function_should_fail(
'module os\nos.access\n path: (x for x in range(42))'
)
self.assertEqual(s, expected_failure_message)

def test_unused_param(self):
block = self.parse("""
module foo
Expand Down