From 25759bdf5c891fa4084abe8bc8c86b56dae0a38f Mon Sep 17 00:00:00 2001 From: alexanderlukanin13 Date: Wed, 15 Jan 2014 13:09:36 +0600 Subject: [PATCH] Removed deploy test (as deploy command is deprecated and moved to scrapyd) --- scrapy/tests/test_command_deploy.py | 60 ----------------------------- scrapy/tests/test_commands.py | 27 ------------- 2 files changed, 87 deletions(-) delete mode 100644 scrapy/tests/test_command_deploy.py diff --git a/scrapy/tests/test_command_deploy.py b/scrapy/tests/test_command_deploy.py deleted file mode 100644 index e6f008099..000000000 --- a/scrapy/tests/test_command_deploy.py +++ /dev/null @@ -1,60 +0,0 @@ -import re -from six.moves import cStringIO -from mock import patch -from twisted.trial import unittest - -import scrapy.commands.deploy as deploy -from scrapy.exceptions import UsageError -from scrapy.tests.test_commands import CommandMockTest - - -@patch('urllib2.install_opener') -class DeployMockTest(CommandMockTest, unittest.TestCase): - - Command = deploy.Command - - def test_wrong_target(self, install_opener_mock): - self.assertRaisesRegexp(UsageError, r'^Unknown target: wrong$', self.run_command, ['wrong']) - - @patch('scrapy.commands.deploy._get_targets', autospec=True) - def test_list_targets(self, _get_targets_mock, install_opener_mock): - _get_targets_mock.return_value = { - 'target1': {'url': 'url1'}, - 'target2': {'url': 'url2'}, - } - stream = cStringIO() - with patch('sys.stdout') as stdout_mock: - stdout_mock.write = stream.write - self.run_command(['--list-targets']) - # We need to sort output strings and replace arbitrary number of spaces with 1 space to make comparison exact - sorted_output = '\n'.join(x for x in sorted(re.sub(r'\s{2,}', ' ', stream.getvalue()).splitlines()) if x.strip()) - self.assertEqual(sorted_output, 'target1 url1\ntarget2 url2') - - @patch('urllib2.urlopen', autospec=True) - @patch('scrapy.commands.deploy._get_targets', autospec=True) - def test_list_projects(self, _get_targets_mock, urlopen_mock, install_opener_mock): - urlopen_mock.return_value = cStringIO('{"projects": ["project1", "project2"]}') - _get_targets_mock.return_value = { - 'target1': {'url': 'http://localhost/target1'}, - 'target2': {'url': 'http://localhost/target2'}, - } - stream = cStringIO() - with patch('sys.stdout') as stdout_mock: - stdout_mock.write = stream.write - self.run_command(['--list-projects', 'target1']) - self.assertEqual(stream.getvalue().strip(), 'project1\nproject2') - - @patch('scrapy.commands.deploy._build_egg', autospec=True) - @patch('shutil.copyfile', autospec=True) - @patch('shutil.rmtree', autospec=True) - def test_build_egg(self, rmtree_mock, copyfile_mock, _build_egg_mock, install_opener_mock): - _build_egg_mock.return_value = ('egg', '/egg_temp_dir') - stream = cStringIO() - with patch('sys.stderr') as stdout_mock: - stdout_mock.write = stream.write - self.run_command(['--build-egg', '/target/egg']) - self.assertEqual(stream.getvalue().strip(), 'Writing egg to /target/egg') - self.assertEqual(copyfile_mock.call_count, 1) - self.assertEqual(copyfile_mock.call_args[0], ('egg', '/target/egg')) - self.assertEqual(rmtree_mock.call_count, 1) - self.assertEqual(rmtree_mock.call_args[0], ('/egg_temp_dir',)) diff --git a/scrapy/tests/test_commands.py b/scrapy/tests/test_commands.py index 93f57cfb3..f585ba9fc 100644 --- a/scrapy/tests/test_commands.py +++ b/scrapy/tests/test_commands.py @@ -1,4 +1,3 @@ -import optparse import os import sys import subprocess @@ -8,7 +7,6 @@ from shutil import rmtree from tempfile import mkdtemp from twisted.trial import unittest -from scrapy.settings import CrawlerSettings from scrapy.utils.python import retry_on_eintr from scrapy.utils.test import get_testenv @@ -237,28 +235,3 @@ class BenchCommandTest(CommandTest): '-s', 'CLOSESPIDER_TIMEOUT=0.01') log = p.stderr.read() self.assert_('INFO: Crawled' in log, log) - - -class CommandMockTest(object): - """This class is used to test commands and improve code coverage - without invoking actual command subprocess. - - Subclass must: - 1. Define Command = CommandClassToTest in class scope. - 2. Call super.setUp() and super.tearDown() if methods are overridden. - 3. Call run_command(argv) in test methods. - """ - - def setUp(self): - self.cmd = self.__class__.Command() - self.cmd.settings = CrawlerSettings(object()) - self.parser = optparse.OptionParser(formatter=optparse.TitledHelpFormatter(), conflict_handler='resolve') - self.cmd.add_options(self.parser) - - def tearDown(self): - pass - - def run_command(self, argv): - opts, args = self.parser.parse_args(argv) - self.cmd.process_options(args, opts) - self.cmd.run(args, opts)