Skip to content

Commit 64d1b44

Browse files
authored
gh-104683: clinic.py: Improve coverage for the parse_converter method (#104729)
1 parent f3466bc commit 64d1b44

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Lib/test/test_clinic.py

+39
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,45 @@ def test_legacy_converters(self):
774774
module, function = block.signatures
775775
self.assertIsInstance((function.parameters['path']).converter, clinic.str_converter)
776776

777+
def test_legacy_converters_non_string_constant_annotation(self):
778+
expected_failure_message = """\
779+
Error on line 0:
780+
Annotations must be either a name, a function call, or a string.
781+
"""
782+
783+
s = self.parse_function_should_fail('module os\nos.access\n path: 42')
784+
self.assertEqual(s, expected_failure_message)
785+
786+
s = self.parse_function_should_fail('module os\nos.access\n path: 42.42')
787+
self.assertEqual(s, expected_failure_message)
788+
789+
s = self.parse_function_should_fail('module os\nos.access\n path: 42j')
790+
self.assertEqual(s, expected_failure_message)
791+
792+
s = self.parse_function_should_fail('module os\nos.access\n path: b"42"')
793+
self.assertEqual(s, expected_failure_message)
794+
795+
def test_other_bizarre_things_in_annotations_fail(self):
796+
expected_failure_message = """\
797+
Error on line 0:
798+
Annotations must be either a name, a function call, or a string.
799+
"""
800+
801+
s = self.parse_function_should_fail(
802+
'module os\nos.access\n path: {"some": "dictionary"}'
803+
)
804+
self.assertEqual(s, expected_failure_message)
805+
806+
s = self.parse_function_should_fail(
807+
'module os\nos.access\n path: ["list", "of", "strings"]'
808+
)
809+
self.assertEqual(s, expected_failure_message)
810+
811+
s = self.parse_function_should_fail(
812+
'module os\nos.access\n path: (x for x in range(42))'
813+
)
814+
self.assertEqual(s, expected_failure_message)
815+
777816
def test_unused_param(self):
778817
block = self.parse("""
779818
module foo

0 commit comments

Comments
 (0)