[Python-checkins] gh-104683: `clinic.py`: Improve coverage for the `parse_converter` method (#104729)

AlexWaygood webhook-mailer at python.org
Sun May 21 19:00:54 EDT 2023


https://github.com/python/cpython/commit/64d1b44a5459605af3e8572d4febfde021315633
commit: 64d1b44a5459605af3e8572d4febfde021315633
branch: main
author: Alex Waygood <Alex.Waygood at Gmail.com>
committer: AlexWaygood <Alex.Waygood at Gmail.com>
date: 2023-05-21T23:00:47Z
summary:

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

files:
M Lib/test/test_clinic.py

diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py
index f72cb0442f35..bea730380556 100644
--- a/Lib/test/test_clinic.py
+++ b/Lib/test/test_clinic.py
@@ -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



More information about the Python-checkins mailing list