Added check so that genspider cannot create a spider with the same name as the project.

This commit is contained in:
Tom Mortimer-Jones 2013-02-12 12:26:38 +00:00
parent c0a7040f16
commit 2efd859525
2 changed files with 9 additions and 0 deletions

View File

@ -56,6 +56,11 @@ class Command(ScrapyCommand):
name, domain = args[0:2]
module = sanitize_module_name(name)
if self.settings.get('BOT_NAME') == module:
print "Cannot create a spider with the same name as your project"
return
try:
spider = self.crawler.spiders.create(name)
except KeyError:

View File

@ -112,6 +112,10 @@ class GenspiderCommandTest(CommandTest):
self.assertEqual(0, self.call('genspider', '--dump=basic'))
self.assertEqual(0, self.call('genspider', '-d', 'basic'))
def test_same_name_as_project(self):
self.assertEqual(2, self.call('genspider', self.project_name))
assert not exists(join(self.proj_mod_path, 'spiders', '%s.py' % self.project_name))
class MiscCommandsTest(CommandTest):