diff options
author | Alex Waygood <Alex.Waygood@Gmail.com> | 2023-05-21 23:00:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-21 23:00:47 (GMT) |
commit | 64d1b44a5459605af3e8572d4febfde021315633 (patch) | |
tree | 55db2f27493363b6d17daff188b5966d77bc81f6 | |
parent | f3466bc04008660c4a5c3ed6f70144f138ae2e7f (diff) | |
download | cpython-64d1b44a5459605af3e8572d4febfde021315633.zip cpython-64d1b44a5459605af3e8572d4febfde021315633.tar.gz cpython-64d1b44a5459605af3e8572d4febfde021315633.tar.bz2 |
gh-104683: `clinic.py`: Improve coverage for the `parse_converter` method (#104729)
-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 f72cb04..bea7303 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -774,6 +774,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 test_unused_param(self): block = self.parse(""" module foo |