Exemple #1
0
 def test_to_encoding_unicode_not_ascii(self):
   # 'Hello' in Russian cyrillic: 'privet'.
   test = u'\u043f\u0440\u0438\u0432\u0435\u0442'
   # It's not convertible to ASCII.
   with self.assertRaises(UnicodeEncodeError):
     tokens.to_encoding(test, 'ascii')
   # Fine in UTF-8.
   result = tokens.to_encoding(test, 'utf-8')
   self.assertTrue(isinstance(result, str))
   self.assertEqual('\xd0\xbf\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82', result)
Exemple #2
0
 def test_to_encoding_unicode_not_ascii(self):
   # 'Hello' in Russian cyrillic: 'privet'.
   test = u'\u043f\u0440\u0438\u0432\u0435\u0442'
   # It's not convertible to ASCII.
   with self.assertRaises(UnicodeEncodeError):
     tokens.to_encoding(test, 'ascii')
   # Fine in UTF-8.
   result = tokens.to_encoding(test, 'utf-8')
   self.assertTrue(isinstance(result, str))
   self.assertEqual('\xd0\xbf\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82', result)
Exemple #3
0
 def test_to_encoding_not_a_string(self):
     with self.assertRaises(TypeError):
         tokens.to_encoding(None, 'ascii')
     with self.assertRaises(TypeError):
         tokens.to_encoding(123, 'ascii')
Exemple #4
0
 def test_to_encoding_unicode_ascii(self):
     result = tokens.to_encoding(u'abc', 'ascii')
     self.assertTrue(isinstance(result, str))
     self.assertEqual('abc', result)
Exemple #5
0
 def test_to_encoding_not_a_string(self):
   with self.assertRaises(TypeError):
     tokens.to_encoding(None, 'ascii')
   with self.assertRaises(TypeError):
     tokens.to_encoding(123, 'ascii')
Exemple #6
0
 def test_to_encoding_unicode_ascii(self):
   result = tokens.to_encoding(u'abc', 'ascii')
   self.assertTrue(isinstance(result, str))
   self.assertEqual('abc', result)
Exemple #7
0
 def test_to_encoding_unicode_ascii(self):
     result = tokens.to_encoding(u"abc", "ascii")
     self.assertTrue(isinstance(result, str))
     self.assertEqual("abc", result)