mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-06 11:00:46 +00:00
Fix _pop_command_name (#6606)
This commit is contained in:
parent
98ba61256d
commit
1c1e83895c
@ -96,10 +96,9 @@ def _get_project_only_cmds(settings: BaseSettings) -> set[str]:
|
||||
|
||||
|
||||
def _pop_command_name(argv: list[str]) -> str | None:
|
||||
for i, arg in enumerate(argv[1:]):
|
||||
if not arg.startswith("-"):
|
||||
del argv[i]
|
||||
return arg
|
||||
for i in range(1, len(argv)):
|
||||
if not argv[i].startswith("-"):
|
||||
return argv.pop(i)
|
||||
return None
|
||||
|
||||
|
||||
|
@ -23,7 +23,7 @@ from pytest import mark
|
||||
from twisted.trial import unittest
|
||||
|
||||
import scrapy
|
||||
from scrapy.cmdline import _print_unknown_command_msg
|
||||
from scrapy.cmdline import _pop_command_name, _print_unknown_command_msg
|
||||
from scrapy.commands import ScrapyCommand, ScrapyHelpFormatter, view
|
||||
from scrapy.commands.startproject import IGNORE
|
||||
from scrapy.settings import Settings
|
||||
@ -1163,3 +1163,29 @@ class HelpMessageTest(CommandTest):
|
||||
for command in self.commands:
|
||||
_, out, _ = self.proc(command, "-h")
|
||||
self.assertIn("Usage", out)
|
||||
|
||||
|
||||
class PopCommandNameTest(unittest.TestCase):
|
||||
def test_valid_command(self):
|
||||
argv = ["scrapy", "crawl", "my_spider"]
|
||||
command = _pop_command_name(argv)
|
||||
self.assertEqual(command, "crawl")
|
||||
self.assertEqual(argv, ["scrapy", "my_spider"])
|
||||
|
||||
def test_no_command(self):
|
||||
argv = ["scrapy"]
|
||||
command = _pop_command_name(argv)
|
||||
self.assertIsNone(command)
|
||||
self.assertEqual(argv, ["scrapy"])
|
||||
|
||||
def test_option_before_command(self):
|
||||
argv = ["scrapy", "-h", "crawl"]
|
||||
command = _pop_command_name(argv)
|
||||
self.assertEqual(command, "crawl")
|
||||
self.assertEqual(argv, ["scrapy", "-h"])
|
||||
|
||||
def test_option_after_command(self):
|
||||
argv = ["scrapy", "crawl", "-h"]
|
||||
command = _pop_command_name(argv)
|
||||
self.assertEqual(command, "crawl")
|
||||
self.assertEqual(argv, ["scrapy", "-h"])
|
||||
|
Loading…
x
Reference in New Issue
Block a user