mirror of https://github.com/scrapy/scrapy.git
Remove six.text_type from tests
This commit is contained in:
parent
ac62524824
commit
5d8abdde59
|
|
@ -79,7 +79,7 @@ class BaseItemExporterTest(unittest.TestCase):
|
|||
|
||||
ie = self._get_exporter(fields_to_export=['name'], encoding='latin-1')
|
||||
_, name = list(ie._get_serialized_fields(self.i))[0]
|
||||
assert isinstance(name, six.text_type)
|
||||
assert isinstance(name, str)
|
||||
self.assertEqual(name, u'John\xa3')
|
||||
|
||||
def test_field_custom_serializer(self):
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ class BaseResponseTest(unittest.TestCase):
|
|||
self.assertEqual(r4.flags, [])
|
||||
|
||||
def _assert_response_values(self, response, encoding, body):
|
||||
if isinstance(body, six.text_type):
|
||||
if isinstance(body, str):
|
||||
body_unicode = body
|
||||
body_bytes = body.encode(encoding)
|
||||
else:
|
||||
|
|
@ -110,7 +110,7 @@ class BaseResponseTest(unittest.TestCase):
|
|||
body_bytes = body
|
||||
|
||||
assert isinstance(response.body, bytes)
|
||||
assert isinstance(response.text, six.text_type)
|
||||
assert isinstance(response.text, str)
|
||||
self._assert_response_encoding(response, encoding)
|
||||
self.assertEqual(response.body, body_bytes)
|
||||
self.assertEqual(response.body_as_unicode(), body_unicode)
|
||||
|
|
@ -220,11 +220,11 @@ class TextResponseTest(BaseResponseTest):
|
|||
r1 = self.response_class('http://www.example.com', body=original_string, encoding='cp1251')
|
||||
|
||||
# check body_as_unicode
|
||||
self.assertTrue(isinstance(r1.body_as_unicode(), six.text_type))
|
||||
self.assertTrue(isinstance(r1.body_as_unicode(), str))
|
||||
self.assertEqual(r1.body_as_unicode(), unicode_string)
|
||||
|
||||
# check response.text
|
||||
self.assertTrue(isinstance(r1.text, six.text_type))
|
||||
self.assertTrue(isinstance(r1.text, str))
|
||||
self.assertEqual(r1.text, unicode_string)
|
||||
|
||||
def test_encoding(self):
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ class BasicItemLoaderTest(unittest.TestCase):
|
|||
|
||||
def test_get_value(self):
|
||||
il = NameItemLoader()
|
||||
self.assertEqual(u'FOO', il.get_value([u'foo', u'bar'], TakeFirst(), six.text_type.upper))
|
||||
self.assertEqual(u'FOO', il.get_value([u'foo', u'bar'], TakeFirst(), str.upper))
|
||||
self.assertEqual([u'foo', u'bar'], il.get_value([u'name:foo', u'name:bar'], re=u'name:(.*)$'))
|
||||
self.assertEqual(u'foo', il.get_value([u'name:foo', u'name:bar'], TakeFirst(), re=u'name:(.*)$'))
|
||||
|
||||
|
|
@ -258,7 +258,7 @@ class BasicItemLoaderTest(unittest.TestCase):
|
|||
|
||||
def test_extend_custom_input_processors(self):
|
||||
class ChildItemLoader(TestItemLoader):
|
||||
name_in = MapCompose(TestItemLoader.name_in, six.text_type.swapcase)
|
||||
name_in = MapCompose(TestItemLoader.name_in, str.swapcase)
|
||||
|
||||
il = ChildItemLoader()
|
||||
il.add_value('name', u'marta')
|
||||
|
|
@ -266,7 +266,7 @@ class BasicItemLoaderTest(unittest.TestCase):
|
|||
|
||||
def test_extend_default_input_processors(self):
|
||||
class ChildDefaultedItemLoader(DefaultedItemLoader):
|
||||
name_in = MapCompose(DefaultedItemLoader.default_input_processor, six.text_type.swapcase)
|
||||
name_in = MapCompose(DefaultedItemLoader.default_input_processor, str.swapcase)
|
||||
|
||||
il = ChildDefaultedItemLoader()
|
||||
il.add_value('name', u'marta')
|
||||
|
|
@ -689,7 +689,7 @@ class ProcessorsTest(unittest.TestCase):
|
|||
self.assertRaises(TypeError, proc, [None, '', 'hello', 'world'])
|
||||
self.assertEqual(proc(['', 'hello', 'world']), u' hello world')
|
||||
self.assertEqual(proc(['hello', 'world']), u'hello world')
|
||||
self.assertIsInstance(proc(['hello', 'world']), six.text_type)
|
||||
self.assertIsInstance(proc(['hello', 'world']), str)
|
||||
|
||||
def test_compose(self):
|
||||
proc = Compose(lambda v: v[0], str.upper)
|
||||
|
|
@ -704,12 +704,12 @@ class ProcessorsTest(unittest.TestCase):
|
|||
def test_mapcompose(self):
|
||||
def filter_world(x):
|
||||
return None if x == 'world' else x
|
||||
proc = MapCompose(filter_world, six.text_type.upper)
|
||||
proc = MapCompose(filter_world, str.upper)
|
||||
self.assertEqual(proc([u'hello', u'world', u'this', u'is', u'scrapy']),
|
||||
[u'HELLO', u'THIS', u'IS', u'SCRAPY'])
|
||||
proc = MapCompose(filter_world, six.text_type.upper)
|
||||
proc = MapCompose(filter_world, str.upper)
|
||||
self.assertEqual(proc(None), [])
|
||||
proc = MapCompose(filter_world, six.text_type.upper)
|
||||
proc = MapCompose(filter_world, str.upper)
|
||||
self.assertRaises(ValueError, proc, [1])
|
||||
proc = MapCompose(filter_world, lambda x: x + 1)
|
||||
self.assertRaises(ValueError, proc, 'hello')
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ class LoggingContribTest(unittest.TestCase):
|
|||
logkws = self.formatter.dropped(item, exception, response, self.spider)
|
||||
logline = logkws['msg'] % logkws['args']
|
||||
lines = logline.splitlines()
|
||||
assert all(isinstance(x, six.text_type) for x in lines)
|
||||
assert all(isinstance(x, str) for x in lines)
|
||||
self.assertEqual(lines, [u"Dropped: \u2018", '{}'])
|
||||
|
||||
def test_scraped(self):
|
||||
|
|
@ -69,7 +69,7 @@ class LoggingContribTest(unittest.TestCase):
|
|||
logkws = self.formatter.scraped(item, response, self.spider)
|
||||
logline = logkws['msg'] % logkws['args']
|
||||
lines = logline.splitlines()
|
||||
assert all(isinstance(x, six.text_type) for x in lines)
|
||||
assert all(isinstance(x, str) for x in lines)
|
||||
self.assertEqual(lines, [u"Scraped from <200 http://www.example.com>", u'name: \xa3'])
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import scrapy
|
|||
class ToplevelTestCase(TestCase):
|
||||
|
||||
def test_version(self):
|
||||
self.assertIs(type(scrapy.__version__), six.text_type)
|
||||
self.assertIs(type(scrapy.__version__), str)
|
||||
|
||||
def test_version_info(self):
|
||||
self.assertIs(type(scrapy.version_info), tuple)
|
||||
|
|
|
|||
|
|
@ -255,8 +255,8 @@ class UtilsCsvTestCase(unittest.TestCase):
|
|||
|
||||
# explicit type check cuz' we no like stinkin' autocasting! yarrr
|
||||
for result_row in result:
|
||||
self.assertTrue(all((isinstance(k, six.text_type) for k in result_row.keys())))
|
||||
self.assertTrue(all((isinstance(v, six.text_type) for v in result_row.values())))
|
||||
self.assertTrue(all((isinstance(k, str) for k in result_row.keys())))
|
||||
self.assertTrue(all((isinstance(v, str) for v in result_row.values())))
|
||||
|
||||
def test_csviter_delimiter(self):
|
||||
body = get_testdata('feeds', 'feed-sample3.csv').replace(b',', b'\t')
|
||||
|
|
|
|||
|
|
@ -169,8 +169,8 @@ class UtilsPythonTestCase(unittest.TestCase):
|
|||
d2 = stringify_dict(d, keys_only=False)
|
||||
self.assertEqual(d, d2)
|
||||
self.assertIsNot(d, d2) # shouldn't modify in place
|
||||
self.assertFalse(any(isinstance(x, six.text_type) for x in d2.keys()))
|
||||
self.assertFalse(any(isinstance(x, six.text_type) for x in d2.values()))
|
||||
self.assertFalse(any(isinstance(x, str) for x in d2.keys()))
|
||||
self.assertFalse(any(isinstance(x, str) for x in d2.values()))
|
||||
|
||||
@unittest.skipUnless(six.PY2, "deprecated function")
|
||||
def test_stringify_dict_tuples(self):
|
||||
|
|
@ -179,8 +179,8 @@ class UtilsPythonTestCase(unittest.TestCase):
|
|||
d2 = stringify_dict(tuples, keys_only=False)
|
||||
self.assertEqual(d, d2)
|
||||
self.assertIsNot(d, d2) # shouldn't modify in place
|
||||
self.assertFalse(any(isinstance(x, six.text_type) for x in d2.keys()), d2.keys())
|
||||
self.assertFalse(any(isinstance(x, six.text_type) for x in d2.values()))
|
||||
self.assertFalse(any(isinstance(x, str) for x in d2.keys()), d2.keys())
|
||||
self.assertFalse(any(isinstance(x, str) for x in d2.values()))
|
||||
|
||||
@unittest.skipUnless(six.PY2, "deprecated function")
|
||||
def test_stringify_dict_keys_only(self):
|
||||
|
|
@ -188,7 +188,7 @@ class UtilsPythonTestCase(unittest.TestCase):
|
|||
d2 = stringify_dict(d)
|
||||
self.assertEqual(d, d2)
|
||||
self.assertIsNot(d, d2) # shouldn't modify in place
|
||||
self.assertFalse(any(isinstance(x, six.text_type) for x in d2.keys()))
|
||||
self.assertFalse(any(isinstance(x, str) for x in d2.keys()))
|
||||
|
||||
def test_get_func_args(self):
|
||||
def f1(a, b, c):
|
||||
|
|
@ -227,12 +227,12 @@ class UtilsPythonTestCase(unittest.TestCase):
|
|||
|
||||
if platform.python_implementation() == 'CPython':
|
||||
# TODO: how do we fix this to return the actual argument names?
|
||||
self.assertEqual(get_func_args(six.text_type.split), [])
|
||||
self.assertEqual(get_func_args(str.split), [])
|
||||
self.assertEqual(get_func_args(" ".join), [])
|
||||
self.assertEqual(get_func_args(operator.itemgetter(2)), [])
|
||||
else:
|
||||
self.assertEqual(
|
||||
get_func_args(six.text_type.split, True), ['sep', 'maxsplit'])
|
||||
get_func_args(str.split, True), ['sep', 'maxsplit'])
|
||||
self.assertEqual(get_func_args(" ".join, True), ['list'])
|
||||
self.assertEqual(
|
||||
get_func_args(operator.itemgetter(2), True), ['obj'])
|
||||
|
|
|
|||
Loading…
Reference in New Issue