Commit 9a90900d authored by Victor Stinner's avatar Victor Stinner

PyUnicode_FromFormatV(): Fix %A format

It was not completly implemented. Add a test.
parent 0410656b
......@@ -1380,20 +1380,23 @@ class UnicodeTest(string_tests.CommonTest,
self.assertEqual("{}".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
# non-ascii format, ascii argument: ensure that PyUnicode_FromFormat()
# raises an error for a non-ascii format string.
self.assertRaisesRegexp(ValueError,
'^PyUnicode_FromFormatV\(\) expects an ASCII-encoded format '
'string, got a non-ASCII byte: 0xe9$',
format_unicode, b'unicode\xe9=%s', 'ascii')
# other tests
text = format_unicode(b'%%A:%A', 'abc\xe9\uabcd\U0010ffff')
self.assertEqual(text, r"%A:'abc\xe9\uabcd\U0010ffff'")
# Test PyUnicode_AsWideChar()
def test_aswidechar(self):
from _testcapi import unicode_aswidechar
......
......@@ -1074,6 +1074,7 @@ PyUnicode_FromFormatV(const char *format, va_list vargs)
}
case 'S':
case 'R':
case 'A':
{
Py_UNICODE *ucopy;
Py_ssize_t usize;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment