summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_unicode.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-09-11 00:54:47 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-09-11 00:54:47 (GMT)
commit1205f2774e00d38d3229a3a2742c2fcbc767bdde (patch)
tree8f5756aa974326bf503dfaad7512aff103bde9bb /Lib/test/test_unicode.py
parentcd419abe42b42c626d91d5f839d53bdbde9852e0 (diff)
downloadcpython-1205f2774e00d38d3229a3a2742c2fcbc767bdde.zip
cpython-1205f2774e00d38d3229a3a2742c2fcbc767bdde.tar.gz
cpython-1205f2774e00d38d3229a3a2742c2fcbc767bdde.tar.bz2
Issue #9738: PyUnicode_FromFormat() and PyErr_Format() raise an error on
a non-ASCII byte in the format string. Document also the encoding.
Diffstat (limited to 'Lib/test/test_unicode.py')
-rw-r--r--Lib/test/test_unicode.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index ae5f53d..0c23daa 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -1385,6 +1385,20 @@ class UnicodeTest(string_tests.CommonTest,
self.assertEquals("%s" % s, '__str__ overridden')
self.assertEquals("{}".format(s), '__str__ overridden')
+ def test_from_format(self):
+ # Ensure that PyUnicode_FromFormat() raises an error for a non-ascii
+ # format string.
+ from _testcapi import format_unicode
+
+ # ascii format, non-ascii argument
+ text = format_unicode(b'ascii\x7f=%U', 'unicode\xe9')
+ self.assertEqual(text, 'ascii\x7f=unicode\xe9')
+
+ # non-ascii format, ascii argument
+ self.assertRaisesRegexp(ValueError,
+ '^PyUnicode_FromFormatV\(\) expects an ASCII-encoded format '
+ 'string, got a non-ascii byte: 0xe9$',
+ format_unicode, b'unicode\xe9=%s', 'ascii')
def test_main():
support.run_unittest(__name__)