PY3 fix test loader

This commit is contained in:
nyov 2015-07-29 16:16:51 +00:00 committed by Mikhail Korobov
parent 34eced0ee8
commit 45d441d444
3 changed files with 8 additions and 7 deletions

View File

@ -4,7 +4,6 @@ tests/test_command_shell.py
tests/test_commands.py
tests/test_exporters.py
tests/test_linkextractors.py
tests/test_loader.py
tests/test_crawl.py
tests/test_crawler.py
tests/test_downloader_handlers.py

View File

@ -1,3 +1,4 @@
pytest>=2.6.0
pytest-twisted
testfixtures
jmespath

View File

@ -1,4 +1,5 @@
import unittest
import six
from functools import partial
from scrapy.loader import ItemLoader
@ -141,7 +142,7 @@ class BasicItemLoaderTest(unittest.TestCase):
def test_get_value(self):
il = NameItemLoader()
self.assertEqual(u'FOO', il.get_value([u'foo', u'bar'], TakeFirst(), unicode.upper))
self.assertEqual(u'FOO', il.get_value([u'foo', u'bar'], TakeFirst(), six.text_type.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:(.*)$'))
@ -242,7 +243,7 @@ class BasicItemLoaderTest(unittest.TestCase):
def test_extend_custom_input_processors(self):
class ChildItemLoader(TestItemLoader):
name_in = MapCompose(TestItemLoader.name_in, unicode.swapcase)
name_in = MapCompose(TestItemLoader.name_in, six.text_type.swapcase)
il = ChildItemLoader()
il.add_value('name', u'marta')
@ -250,7 +251,7 @@ class BasicItemLoaderTest(unittest.TestCase):
def test_extend_default_input_processors(self):
class ChildDefaultedItemLoader(DefaultedItemLoader):
name_in = MapCompose(DefaultedItemLoader.default_input_processor, unicode.swapcase)
name_in = MapCompose(DefaultedItemLoader.default_input_processor, six.text_type.swapcase)
il = ChildDefaultedItemLoader()
il.add_value('name', u'marta')
@ -423,7 +424,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.assert_(isinstance(proc(['hello', 'world']), unicode))
self.assert_(isinstance(proc(['hello', 'world']), six.text_type))
def test_compose(self):
proc = Compose(lambda v: v[0], str.upper)
@ -435,13 +436,13 @@ class ProcessorsTest(unittest.TestCase):
def test_mapcompose(self):
filter_world = lambda x: None if x == 'world' else x
proc = MapCompose(filter_world, unicode.upper)
proc = MapCompose(filter_world, six.text_type.upper)
self.assertEqual(proc([u'hello', u'world', u'this', u'is', u'scrapy']),
[u'HELLO', u'THIS', u'IS', u'SCRAPY'])
class SelectortemLoaderTest(unittest.TestCase):
response = HtmlResponse(url="", body="""
response = HtmlResponse(url="", encoding='utf-8', body=b"""
<html>
<body>
<div id="id">marta</div>