Skip to content

Commit 45d441d

Browse files
nyovkmike
authored andcommitted
PY3 fix test loader
1 parent 34eced0 commit 45d441d

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

tests/py3-ignores.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ tests/test_command_shell.py
44
tests/test_commands.py
55
tests/test_exporters.py
66
tests/test_linkextractors.py
7-
tests/test_loader.py
87
tests/test_crawl.py
98
tests/test_crawler.py
109
tests/test_downloader_handlers.py

tests/requirements-py3.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pytest>=2.6.0
22
pytest-twisted
33
testfixtures
4+
jmespath

tests/test_loader.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
import six
23
from functools import partial
34

45
from scrapy.loader import ItemLoader
@@ -141,7 +142,7 @@ def test_replace_value(self):
141142

142143
def test_get_value(self):
143144
il = NameItemLoader()
144-
self.assertEqual(u'FOO', il.get_value([u'foo', u'bar'], TakeFirst(), unicode.upper))
145+
self.assertEqual(u'FOO', il.get_value([u'foo', u'bar'], TakeFirst(), six.text_type.upper))
145146
self.assertEqual([u'foo', u'bar'], il.get_value([u'name:foo', u'name:bar'], re=u'name:(.*)$'))
146147
self.assertEqual(u'foo', il.get_value([u'name:foo', u'name:bar'], TakeFirst(), re=u'name:(.*)$'))
147148

@@ -242,15 +243,15 @@ class IdentityDefaultedItemLoader(DefaultedItemLoader):
242243

243244
def test_extend_custom_input_processors(self):
244245
class ChildItemLoader(TestItemLoader):
245-
name_in = MapCompose(TestItemLoader.name_in, unicode.swapcase)
246+
name_in = MapCompose(TestItemLoader.name_in, six.text_type.swapcase)
246247

247248
il = ChildItemLoader()
248249
il.add_value('name', u'marta')
249250
self.assertEqual(il.get_output_value('name'), [u'mARTA'])
250251

251252
def test_extend_default_input_processors(self):
252253
class ChildDefaultedItemLoader(DefaultedItemLoader):
253-
name_in = MapCompose(DefaultedItemLoader.default_input_processor, unicode.swapcase)
254+
name_in = MapCompose(DefaultedItemLoader.default_input_processor, six.text_type.swapcase)
254255

255256
il = ChildDefaultedItemLoader()
256257
il.add_value('name', u'marta')
@@ -423,7 +424,7 @@ def test_join(self):
423424
self.assertRaises(TypeError, proc, [None, '', 'hello', 'world'])
424425
self.assertEqual(proc(['', 'hello', 'world']), u' hello world')
425426
self.assertEqual(proc(['hello', 'world']), u'hello world')
426-
self.assert_(isinstance(proc(['hello', 'world']), unicode))
427+
self.assert_(isinstance(proc(['hello', 'world']), six.text_type))
427428

428429
def test_compose(self):
429430
proc = Compose(lambda v: v[0], str.upper)
@@ -435,13 +436,13 @@ def test_compose(self):
435436

436437
def test_mapcompose(self):
437438
filter_world = lambda x: None if x == 'world' else x
438-
proc = MapCompose(filter_world, unicode.upper)
439+
proc = MapCompose(filter_world, six.text_type.upper)
439440
self.assertEqual(proc([u'hello', u'world', u'this', u'is', u'scrapy']),
440441
[u'HELLO', u'THIS', u'IS', u'SCRAPY'])
441442

442443

443444
class SelectortemLoaderTest(unittest.TestCase):
444-
response = HtmlResponse(url="", body="""
445+
response = HtmlResponse(url="", encoding='utf-8', body=b"""
445446
<html>
446447
<body>
447448
<div id="id">marta</div>

0 commit comments

Comments
 (0)