Python _testcapi.unicode_encodedecimal() Examples

The following are 11 code examples of _testcapi.unicode_encodedecimal(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module _testcapi , or try the search function .
Example #1
Source File: test_unicode.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def test_encode_decimal(self):
        from _testcapi import unicode_encodedecimal
        self.assertEqual(unicode_encodedecimal(u'123'),
                         b'123')
        self.assertEqual(unicode_encodedecimal(u'\u0663.\u0661\u0664'),
                         b'3.14')
        self.assertEqual(unicode_encodedecimal(u"\N{EM SPACE}3.14\N{EN SPACE}"),
                         b' 3.14 ')
        self.assertRaises(UnicodeEncodeError,
                          unicode_encodedecimal, u"123\u20ac", "strict")
        self.assertEqual(unicode_encodedecimal(u"123\u20ac", "replace"),
                         b'123?')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac", "ignore"),
                         b'123')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac", "xmlcharrefreplace"),
                         b'123€')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac", "backslashreplace"),
                         b'123\\u20ac')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac\N{EM SPACE}", "replace"),
                         b'123? ')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac\u20ac", "replace"),
                         b'123??')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac\u0660", "replace"),
                         b'123?0') 
Example #2
Source File: test_unicode.py    From BinderFilter with MIT License 6 votes vote down vote up
def test_encode_decimal(self):
        from _testcapi import unicode_encodedecimal
        self.assertEqual(unicode_encodedecimal(u'123'),
                         b'123')
        self.assertEqual(unicode_encodedecimal(u'\u0663.\u0661\u0664'),
                         b'3.14')
        self.assertEqual(unicode_encodedecimal(u"\N{EM SPACE}3.14\N{EN SPACE}"),
                         b' 3.14 ')
        self.assertRaises(UnicodeEncodeError,
                          unicode_encodedecimal, u"123\u20ac", "strict")
        self.assertEqual(unicode_encodedecimal(u"123\u20ac", "replace"),
                         b'123?')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac", "ignore"),
                         b'123')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac", "xmlcharrefreplace"),
                         b'123€')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac", "backslashreplace"),
                         b'123\\u20ac')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac\N{EM SPACE}", "replace"),
                         b'123? ')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac\u20ac", "replace"),
                         b'123??')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac\u0660", "replace"),
                         b'123?0') 
Example #3
Source File: test_unicode.py    From oss-ftp with MIT License 6 votes vote down vote up
def test_encode_decimal(self):
        from _testcapi import unicode_encodedecimal
        self.assertEqual(unicode_encodedecimal(u'123'),
                         b'123')
        self.assertEqual(unicode_encodedecimal(u'\u0663.\u0661\u0664'),
                         b'3.14')
        self.assertEqual(unicode_encodedecimal(u"\N{EM SPACE}3.14\N{EN SPACE}"),
                         b' 3.14 ')
        self.assertRaises(UnicodeEncodeError,
                          unicode_encodedecimal, u"123\u20ac", "strict")
        self.assertEqual(unicode_encodedecimal(u"123\u20ac", "replace"),
                         b'123?')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac", "ignore"),
                         b'123')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac", "xmlcharrefreplace"),
                         b'123€')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac", "backslashreplace"),
                         b'123\\u20ac')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac\N{EM SPACE}", "replace"),
                         b'123? ')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac\u20ac", "replace"),
                         b'123??')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac\u0660", "replace"),
                         b'123?0') 
Example #4
Source File: test_unicode.py    From gcblue with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_encode_decimal(self):
        from _testcapi import unicode_encodedecimal
        self.assertEqual(unicode_encodedecimal(u'123'),
                         b'123')
        self.assertEqual(unicode_encodedecimal(u'\u0663.\u0661\u0664'),
                         b'3.14')
        self.assertEqual(unicode_encodedecimal(u"\N{EM SPACE}3.14\N{EN SPACE}"),
                         b' 3.14 ')
        self.assertRaises(UnicodeEncodeError,
                          unicode_encodedecimal, u"123\u20ac", "strict")
        self.assertEqual(unicode_encodedecimal(u"123\u20ac", "replace"),
                         b'123?')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac", "ignore"),
                         b'123')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac", "xmlcharrefreplace"),
                         b'123€')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac", "backslashreplace"),
                         b'123\\u20ac')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac\N{EM SPACE}", "replace"),
                         b'123? ')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac\u20ac", "replace"),
                         b'123??')
        self.assertEqual(unicode_encodedecimal(u"123\u20ac\u0660", "replace"),
                         b'123?0') 
Example #5
Source File: test_unicode.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_encode_decimal_with_surrogates(self):
        from _testcapi import unicode_encodedecimal
        tests = [(u'\U0001f49d', '💝'),
                 (u'\ud83d', '�'),
                 (u'\udc9d', '�'),
                ]
        if u'\ud83d\udc9d' != u'\U0001f49d':
            tests += [(u'\ud83d\udc9d', '��')]
        for s, exp in tests:
            self.assertEqual(
                    unicode_encodedecimal(u"123" + s, "xmlcharrefreplace"),
                    '123' + exp) 
Example #6
Source File: test_unicode.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_encode_decimal_with_surrogates(self):
        from _testcapi import unicode_encodedecimal
        tests = [(u'\U0001f49d', '💝'),
                 (u'\ud83d', '�'),
                 (u'\udc9d', '�'),
                ]
        if u'\ud83d\udc9d' != u'\U0001f49d':
            tests += [(u'\ud83d\udc9d', '��')]
        for s, exp in tests:
            self.assertEqual(
                    unicode_encodedecimal(u"123" + s, "xmlcharrefreplace"),
                    '123' + exp) 
Example #7
Source File: test_unicode.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
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.assertRaisesRegex(
            ValueError,
            "^'decimal' codec can't encode character",
            unicode_encodedecimal, "123\u20ac", "replace") 
Example #8
Source File: test_unicode.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
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.assertRaisesRegex(
            ValueError,
            "^'decimal' codec can't encode character",
            unicode_encodedecimal, "123\u20ac", "replace") 
Example #9
Source File: test_unicode.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_encode_decimal_with_surrogates(self):
        from _testcapi import unicode_encodedecimal
        tests = [(u'\U0001f49d', '💝'),
                 (u'\ud83d', '�'),
                 (u'\udc9d', '�'),
                ]
        if u'\ud83d\udc9d' != u'\U0001f49d':
            tests += [(u'\ud83d\udc9d', '��')]
        for s, exp in tests:
            self.assertEqual(
                    unicode_encodedecimal(u"123" + s, "xmlcharrefreplace"),
                    '123' + exp) 
Example #10
Source File: test_unicode.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
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.assertRaisesRegex(
            ValueError,
            "^'decimal' codec can't encode character",
            unicode_encodedecimal, "123\u20ac", "replace") 
Example #11
Source File: test_unicode.py    From android_universal with MIT License 5 votes vote down vote up
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.assertRaisesRegex(
            ValueError,
            "^'decimal' codec can't encode character",
            unicode_encodedecimal, "123\u20ac", "replace")