From b9360f659ebb02887ed8e7524b70391093bd2af7 Mon Sep 17 00:00:00 2001 From: elpolilla Date: Wed, 24 Dec 2008 14:14:03 +0000 Subject: [PATCH] Added tests for str_to_unicode and unicode_to_str --HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40547 --- .../trunk/scrapy/tests/test_utils_python.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 scrapy/trunk/scrapy/tests/test_utils_python.py diff --git a/scrapy/trunk/scrapy/tests/test_utils_python.py b/scrapy/trunk/scrapy/tests/test_utils_python.py new file mode 100644 index 000000000..92e76781c --- /dev/null +++ b/scrapy/trunk/scrapy/tests/test_utils_python.py @@ -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()