diff options
author | Alex Waygood <Alex.Waygood@Gmail.com> | 2023-05-22 00:48:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-21 23:48:25 +0000 |
commit | d691de1d2d16724be75e8ae67ef6b7101e000a2d (patch) | |
tree | 2b3237b66860d4d6292b18f47d9a5cae99a7c8bf | |
parent | [3.11] gh-103606: Improve error message from logging.config.FileConfig (GH-10... (diff) | |
download | cpython-d691de1d2d16724be75e8ae67ef6b7101e000a2d.tar.gz cpython-d691de1d2d16724be75e8ae67ef6b7101e000a2d.tar.bz2 cpython-d691de1d2d16724be75e8ae67ef6b7101e000a2d.zip |
[3.11] gh-104683: `clinic.py`: Improve coverage for the `parse_converter` method (#104729) (#104730)
-rw-r--r-- | Lib/test/test_clinic.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index 02a54bf154e..8d4f92fa310 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -773,6 +773,45 @@ Not at column 0! 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) |