TST fix to_bytes and to_unicode tests in Python 3.x

This commit is contained in:
Mikhail Korobov 2015-07-23 17:35:23 +02:00
parent 887936ebf6
commit 41bcae5d00
1 changed files with 7 additions and 7 deletions

View File

@ -12,10 +12,10 @@ __doctests__ = ['scrapy.utils.python']
class ToUnicodeTest(unittest.TestCase):
def test_converting_an_utf8_encoded_string_to_unicode(self):
self.assertEqual(to_unicode('lel\xc3\xb1e'), u'lel\xf1e')
self.assertEqual(to_unicode(b'lel\xc3\xb1e'), u'lel\xf1e')
def test_converting_a_latin_1_encoded_string_to_unicode(self):
self.assertEqual(to_unicode('lel\xf1e', 'latin-1'), u'lel\xf1e')
self.assertEqual(to_unicode(b'lel\xf1e', 'latin-1'), u'lel\xf1e')
def test_converting_a_unicode_to_unicode_should_return_the_same_object(self):
self.assertEqual(to_unicode(u'\xf1e\xf1e\xf1e'), u'\xf1e\xf1e\xf1e')
@ -24,24 +24,24 @@ class ToUnicodeTest(unittest.TestCase):
self.assertRaises(TypeError, to_unicode, 423)
def test_check_errors_argument_works(self):
self.assertIn(u'\ufffd', to_unicode('a\xedb', 'utf-8', errors='replace'))
self.assertIn(u'\ufffd', to_unicode(b'a\xedb', 'utf-8', errors='replace'))
class ToBytesTest(unittest.TestCase):
def test_converting_a_unicode_object_to_an_utf_8_encoded_string(self):
self.assertEqual(to_bytes(u'\xa3 49'), '\xc2\xa3 49')
self.assertEqual(to_bytes(u'\xa3 49'), b'\xc2\xa3 49')
def test_converting_a_unicode_object_to_a_latin_1_encoded_string(self):
self.assertEqual(to_bytes(u'\xa3 49', 'latin-1'), '\xa3 49')
self.assertEqual(to_bytes(u'\xa3 49', 'latin-1'), b'\xa3 49')
def test_converting_a_regular_string_to_string_should_return_the_same_object(self):
self.assertEqual(to_bytes('lel\xf1e'), 'lel\xf1e')
self.assertEqual(to_bytes(b'lel\xf1e'), b'lel\xf1e')
def test_converting_a_strange_object_should_raise_TypeError(self):
self.assertRaises(TypeError, to_bytes, unittest)
def test_check_errors_argument_works(self):
self.assertIn('?', to_bytes(u'a\ufffdb', 'latin-1', errors='replace'))
self.assertIn(b'?', to_bytes(u'a\ufffdb', 'latin-1', errors='replace'))
class UtilsPythonTestCase(unittest.TestCase):