Пример #1
0
 def test_to_unicode(self):
     if six.PY3:
         self.assertEqual(utils.to_unicode('plugh'), 'plugh')
         self.assertEqual(utils.to_unicode('áéíóúý'), 'áéíóúý')
         un = '\u4e2d\u56fd\u8a9e (\u7e41\u4f53)'  # pylint: disable=anomalous-unicode-escape-in-string
         ut = bytes((0xe4, 0xb8, 0xad, 0xe5, 0x9b, 0xbd, 0xe8, 0xaa, 0x9e, 0x20, 0x28, 0xe7, 0xb9, 0x81, 0xe4, 0xbd, 0x93, 0x29))
         self.assertEqual(utils.to_unicode(ut, 'utf-8'), un)
         self.assertEqual(utils.to_unicode(bytearray(ut), 'utf-8'), un)
     else:
         self.assertEqual(utils.to_unicode('xyzzy', 'utf-8'), u'xyzzy')
         ut = '\xe4\xb8\xad\xe5\x9b\xbd\xe8\xaa\x9e (\xe7\xb9\x81\xe4\xbd\x93)'
         un = u'\u4e2d\u56fd\u8a9e (\u7e41\u4f53)'
         self.assertEqual(utils.to_unicode(ut, 'utf-8'), un)
Пример #2
0
 def test_to_unicode(self):
     if six.PY3:
         self.assertEqual(utils.to_unicode('plugh'), 'plugh')
         self.assertEqual(utils.to_unicode('áéíóúý'), 'áéíóúý')
         un = '\u4e2d\u56fd\u8a9e (\u7e41\u4f53)'  # pylint: disable=anomalous-unicode-escape-in-string
         ut = bytes((0xe4, 0xb8, 0xad, 0xe5, 0x9b, 0xbd, 0xe8, 0xaa, 0x9e, 0x20, 0x28, 0xe7, 0xb9, 0x81, 0xe4, 0xbd, 0x93, 0x29))
         self.assertEqual(utils.to_unicode(ut, 'utf-8'), un)
         self.assertEqual(utils.to_unicode(bytearray(ut), 'utf-8'), un)
     else:
         self.assertEqual(utils.to_unicode('xyzzy', 'utf-8'), u'xyzzy')
         ut = '\xe4\xb8\xad\xe5\x9b\xbd\xe8\xaa\x9e (\xe7\xb9\x81\xe4\xbd\x93)'
         un = u'\u4e2d\u56fd\u8a9e (\u7e41\u4f53)'
         self.assertEqual(utils.to_unicode(ut, 'utf-8'), un)