[3.10] bpo-45822: Respect PEP 263's coding cookies in the parser even if flags are not provided (GH-29582) (GH-29586)

(cherry picked from commit da20d7401de97b425897d3069f71f77b039eb16f)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index 6ed5ecd..974e3d0 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -1013,6 +1013,14 @@ def test_state_access(self):
                 with self.assertRaises(TypeError):
                     increment_count(1, 2, 3)
 
+    def test_Py_CompileString(self):
+        # Check that Py_CompileString respects the coding cookie
+        _compile = _testcapi.Py_CompileString
+        code = b"# -*- coding: latin1 -*-\nprint('\xc2\xa4')\n"
+        result = _compile(code)
+        expected = compile(code, "<string>", "exec")
+        self.assertEqual(result.co_consts, expected.co_consts)
+
 
 if __name__ == "__main__":
     unittest.main()