summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-11-22 00:45:37 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-11-22 00:45:37 (GMT)
commitab1d16b4561390022efc0a45fae1ce6cbb119a58 (patch)
treee7307b10973f0167102e0baf7d0363815af0fe25 /Lib/test
parent58fcf9f801d590b999401533154b63f4eb26ce6c (diff)
downloadcpython-ab1d16b4561390022efc0a45fae1ce6cbb119a58.zip
cpython-ab1d16b4561390022efc0a45fae1ce6cbb119a58.tar.gz
cpython-ab1d16b4561390022efc0a45fae1ce6cbb119a58.tar.bz2
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
* Add tests for PyUnicode_EncodeDecimal() and PyUnicode_TransformDecimalToASCII() * Remove the unused "e" variable in replace()
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_unicode.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 591a297..259a181 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -1767,6 +1767,42 @@ class StringModuleTest(unittest.TestCase):
]])
self.assertRaises(TypeError, _string.formatter_field_name_split, 1)
+ def test_encode_decimal(self):
+ from _testcapi import unicode_encodedecimal
+ self.assertEqual(unicode_encodedecimal('123'),
+ b'123')
+ self.assertEqual(unicode_encodedecimal('\u0663.\u0661\u0664'),
+ b'3.14')
+ self.assertEqual(unicode_encodedecimal("\N{EM SPACE}3.14\N{EN SPACE}"),
+ b' 3.14 ')
+ self.assertRaises(UnicodeEncodeError,
+ unicode_encodedecimal, "123\u20ac", "strict")
+ self.assertEqual(unicode_encodedecimal("123\u20ac", "replace"),
+ b'123?')
+ self.assertEqual(unicode_encodedecimal("123\u20ac", "ignore"),
+ b'123')
+ self.assertEqual(unicode_encodedecimal("123\u20ac", "xmlcharrefreplace"),
+ b'123&#8364;')
+ self.assertEqual(unicode_encodedecimal("123\u20ac", "backslashreplace"),
+ b'123\\u20ac')
+ self.assertEqual(unicode_encodedecimal("123\u20ac\N{EM SPACE}", "replace"),
+ b'123? ')
+ self.assertEqual(unicode_encodedecimal("123\u20ac\u20ac", "replace"),
+ b'123??')
+ self.assertEqual(unicode_encodedecimal("123\u20ac\u0660", "replace"),
+ b'123?0')
+
+ def test_transform_decimal(self):
+ from _testcapi import unicode_transformdecimaltoascii as transform_decimal
+ self.assertEqual(transform_decimal('123'),
+ '123')
+ self.assertEqual(transform_decimal('\u0663.\u0661\u0664'),
+ '3.14')
+ self.assertEqual(transform_decimal("\N{EM SPACE}3.14\N{EN SPACE}"),
+ "\N{EM SPACE}3.14\N{EN SPACE}")
+ self.assertEqual(transform_decimal('123\u20ac'),
+ '123\u20ac')
+
def test_main():
support.run_unittest(__name__)