From 77a4d9aba9dcd137fc772be89bcb3ecab05e95ad Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Mon, 5 Apr 2010 11:53:22 -0300 Subject: [PATCH] use a default name for spiders constructed without names --- scrapy/command/commands/fetch.py | 2 +- scrapy/shell.py | 2 +- scrapy/spider/models.py | 2 +- scrapy/tests/test_spider.py | 7 ++++--- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/scrapy/command/commands/fetch.py b/scrapy/command/commands/fetch.py index bb2df1400..b394b5e76 100644 --- a/scrapy/command/commands/fetch.py +++ b/scrapy/command/commands/fetch.py @@ -41,7 +41,7 @@ class Command(ScrapyCommand): log.msg("Could not find spider: %s" % opts.spider, log.ERROR) else: spider = scrapymanager._create_spider_for_request(request, \ - BaseSpider('default')) + BaseSpider()) scrapymanager.crawl_request(request, spider) scrapymanager.start() diff --git a/scrapy/shell.py b/scrapy/shell.py index 96dc51270..88d2b1710 100644 --- a/scrapy/shell.py +++ b/scrapy/shell.py @@ -55,7 +55,7 @@ class Shell(object): request = Request(url) spider = scrapymanager._create_spider_for_request(request, \ - BaseSpider('default'), log_multiple=True) + BaseSpider(), log_multiple=True) print "Fetching %s..." % request response = threads.blockingCallFromThread(reactor, scrapyengine.schedule, \ diff --git a/scrapy/spider/models.py b/scrapy/spider/models.py index 3adf7a470..094cd5077 100644 --- a/scrapy/spider/models.py +++ b/scrapy/spider/models.py @@ -55,7 +55,7 @@ class BaseSpider(object_ref): if not getattr(self, 'extra_domain_names', None): self.extra_domain_names = self.allowed_domains if not self.name: - raise ValueError("%s must have a name" % type(self).__name__) + self.name = 'default' def log(self, message, level=log.DEBUG): """Log the given messages at the given log level. Always use this diff --git a/scrapy/tests/test_spider.py b/scrapy/tests/test_spider.py index c488dad3b..7d93db5b5 100644 --- a/scrapy/tests/test_spider.py +++ b/scrapy/tests/test_spider.py @@ -66,9 +66,10 @@ class BaseSpiderTest(unittest.TestCase): def test_spider_without_name(self): """Constructor arguments are assigned to spider attributes""" - spider = self.spider_class('example.com') - self.assertRaises(ValueError, self.spider_class) - self.assertRaises(ValueError, self.spider_class, somearg='foo') + spider = self.spider_class() + self.assertEqual(spider.name, 'default') + spider = self.spider_class(foo='bar') + self.assertEqual(spider.foo, 'bar') class InitSpiderTest(BaseSpiderTest):