summaryrefslogtreecommitdiff
path: root/Lib/test/test_utf8source.py
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2017-02-04 15:05:40 -0800
committerSteve Dower <steve.dower@microsoft.com>2017-02-04 15:05:40 -0800
commitb2fa705fd3887c326e811c418469c784353027f4 (patch)
treeb3428f73de91453edbfd4df1a5d4a212d182eb44 /Lib/test/test_utf8source.py
parent134e58fd3aaa2e91390041e143f3f0a21a60142b (diff)
parentb53654b6dbfce8318a7d4d1cdaddca7a7fec194b (diff)
downloadcpython-b2fa705fd3887c326e811c418469c784353027f4.tar.gz
Issue #29392: Prevent crash when passing invalid arguments into msvcrt module.
Diffstat (limited to 'Lib/test/test_utf8source.py')
-rw-r--r--Lib/test/test_utf8source.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/Lib/test/test_utf8source.py b/Lib/test/test_utf8source.py
new file mode 100644
index 0000000000..97dced8a62
--- /dev/null
+++ b/Lib/test/test_utf8source.py
@@ -0,0 +1,43 @@
+# This file is marked as binary in the CVS, to prevent MacCVS from recoding it.
+
+import unittest
+
+class PEP3120Test(unittest.TestCase):
+
+ def test_pep3120(self):
+ self.assertEqual(
+ "Питон".encode("utf-8"),
+ b'\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd'
+ )
+ self.assertEqual(
+ "\П".encode("utf-8"),
+ b'\\\xd0\x9f'
+ )
+
+ def test_badsyntax(self):
+ try:
+ import test.badsyntax_pep3120
+ except SyntaxError as msg:
+ msg = str(msg).lower()
+ self.assertTrue('utf-8' in msg)
+ else:
+ self.fail("expected exception didn't occur")
+
+
+class BuiltinCompileTests(unittest.TestCase):
+
+ # Issue 3574.
+ def test_latin1(self):
+ # Allow compile() to read Latin-1 source.
+ source_code = '# coding: Latin-1\nu = "Ç"\n'.encode("Latin-1")
+ try:
+ code = compile(source_code, '<dummy>', 'exec')
+ except SyntaxError:
+ self.fail("compile() cannot handle Latin-1 source")
+ ns = {}
+ exec(code, ns)
+ self.assertEqual('Ç', ns['u'])
+
+
+if __name__ == "__main__":
+ unittest.main()