mirror of https://github.com/scrapy/scrapy.git
Added tests for str_to_unicode and unicode_to_str
--HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40547
This commit is contained in:
parent
86aa3bcb65
commit
b9360f659e
|
|
@ -0,0 +1,27 @@
|
|||
import unittest
|
||||
|
||||
from scrapy.utils.python import str_to_unicode, unicode_to_str
|
||||
|
||||
class UtilsPythonTestCase(unittest.TestCase):
|
||||
def test_str_to_unicode(self):
|
||||
# converting an utf-8 encoded string to unicode
|
||||
self.assertEqual(str_to_unicode('lel\xc3\xb1e'), u'lel\xf1e')
|
||||
|
||||
# converting a unicode to unicode should return the same object
|
||||
self.assertEqual(str_to_unicode(u'\xf1e\xf1e\xf1e'), u'\xf1e\xf1e\xf1e')
|
||||
|
||||
# converting a strange object should raise TypeError
|
||||
self.assertRaises(TypeError, str_to_unicode, 423)
|
||||
|
||||
def test_unicode_to_str(self):
|
||||
# converting a unicode object to an utf-8 encoded string
|
||||
self.assertEqual(unicode_to_str(u'\xa3 49'), '\xc2\xa3 49')
|
||||
|
||||
# converting a regular string to string should return the same object
|
||||
self.assertEqual(unicode_to_str('lel\xf1e'), 'lel\xf1e')
|
||||
|
||||
# converting a strange object should raise TypeError
|
||||
self.assertRaises(TypeError, unicode_to_str, unittest)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
Reference in New Issue