From 3e6d6c43ac0763adf2cd92efdb4a1dc2ba165440 Mon Sep 17 00:00:00 2001 From: nyov Date: Wed, 29 Jul 2015 15:33:52 +0000 Subject: [PATCH] PY3 fix test cmdline --- scrapy/cmdline.py | 6 +++--- scrapy/utils/testproc.py | 4 ++-- tests/py3-ignores.txt | 2 -- tests/test_cmdline/__init__.py | 5 +++-- tests/test_command_version.py | 4 +++- 5 files changed, 11 insertions(+), 10 deletions(-) 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__)