]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-104683: `clinic.py`: Improve coverage for the `parse_converter` method (#104729)
authorAlex Waygood <Alex.Waygood@Gmail.com>
Sun, 21 May 2023 23:00:47 +0000 (00:00 +0100)
committerGitHub <noreply@github.com>
Sun, 21 May 2023 23:00:47 +0000 (23:00 +0000)
Lib/test/test_clinic.py

index f72cb0442f35ff6b5f911f36eb7943b9cfce2ef3..bea7303805567f8e4572b8e3814a80bf0877a6ff 100644 (file)
@@ -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