Skip to content

Commit

Permalink
pythongh-104683: clinic.py: Improve coverage for the `parse_convert…
Browse files Browse the repository at this point in the history
…er` method (python#104729)
  • Loading branch information
AlexWaygood committed May 21, 2023
1 parent 2ade563 commit b59fb65
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Lib/test/test_clinic.py
Expand Up @@ -773,6 +773,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 parse(self, text):
c = FakeClinic()
parser = DSLParser(c)
Expand Down

0 comments on commit b59fb65

Please sign in to comment.