Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

PY3 fix test cmdline

nyov3e6d6c43ac07
diff --git a/scrapy/cmdline.py b/scrapy/cmdline.py
index a619c349a..35050c13d 100644
--- a/scrapy/cmdline.py
+++ b/scrapy/cmdline.py
@@ -18,10 +18,10 @@ def _iter_command_classes(module_name):
# TODO: add `name` attribute to commands and and merge this function with
# scrapy.utils.spider.iter_spider_classes
for module in walk_modules(module_name):
- for obj in vars(module).itervalues():
+ for obj in vars(module).values():
if inspect.isclass(obj) and \
- issubclass(obj, ScrapyCommand) and \
- obj.__module__ == module.__name__:
+ issubclass(obj, ScrapyCommand) and \
+ obj.__module__ == module.__name__:
yield obj
def _get_commands_from_module(module, inproject):
diff --git a/scrapy/utils/testproc.py b/scrapy/utils/testproc.py
index adddad093..f268e91ff 100644
--- a/scrapy/utils/testproc.py
+++ b/scrapy/utils/testproc.py
@@ -35,8 +35,8 @@ class TestProcessProtocol(protocol.ProcessProtocol):
def __init__(self):
self.deferred = defer.Deferred()
- self.out = ''
- self.err = ''
+ self.out = b''
+ self.err = b''
self.exitcode = None
def outReceived(self, data):
diff --git a/tests/py3-ignores.txt b/tests/py3-ignores.txt
index 038f715a6..d0f9e9e91 100644
--- a/tests/py3-ignores.txt
+++ b/tests/py3-ignores.txt
@@ -1,9 +1,7 @@
tests/test_closespider.py
-tests/test_cmdline/__init__.py
tests/test_command_fetch.py
tests/test_command_shell.py
tests/test_commands.py
-tests/test_command_version.py
tests/test_exporters.py
tests/test_linkextractors.py
tests/test_loader.py
diff --git a/tests/test_cmdline/__init__.py b/tests/test_cmdline/__init__.py
index 00fce2fbc..28ba76827 100644
--- a/tests/test_cmdline/__init__.py
+++ b/tests/test_cmdline/__init__.py
@@ -11,10 +11,11 @@ class CmdlineTest(unittest.TestCase):
self.env['SCRAPY_SETTINGS_MODULE'] = 'tests.test_cmdline.settings'
def _execute(self, *new_args, **kwargs):
+ encoding = getattr(sys.stdout, 'encoding') or 'utf-8'
args = (sys.executable, '-m', 'scrapy.cmdline') + new_args
proc = Popen(args, stdout=PIPE, stderr=PIPE, env=self.env, **kwargs)
- comm = proc.communicate()
- return comm[0].strip()
+ comm = proc.communicate()[0].strip()
+ return comm.decode(encoding)
def test_default_settings(self):
self.assertEqual(self._execute('settings', '--get', 'TEST1'), \
diff --git a/tests/test_command_version.py b/tests/test_command_version.py
index 6f0380d77..420713d87 100644
--- a/tests/test_command_version.py
+++ b/tests/test_command_version.py
@@ -1,3 +1,4 @@
+import sys
from twisted.trial import unittest
from twisted.internet import defer
@@ -11,5 +12,6 @@ class VersionTest(ProcessTest, unittest.TestCase):
@defer.inlineCallbacks
def test_output(self):
+ encoding = getattr(sys.stdout, 'encoding') or 'utf-8'
_, out, _ = yield self.execute([])
- self.assertEqual(out.strip(), "Scrapy %s" % scrapy.__version__)
+ self.assertEqual(out.strip().decode(encoding), "Scrapy %s" % scrapy.__version__)