2013-08-18 11:59:44 +02:00
|
|
|
import pytest
|
2017-05-16 12:16:30 +02:00
|
|
|
from mock import Mock
|
2017-06-13 14:17:00 +02:00
|
|
|
|
2018-07-23 09:27:44 +02:00
|
|
|
from pip._internal.cli.basecommand import ERROR, SUCCESS
|
2017-08-31 17:48:18 +02:00
|
|
|
from pip._internal.commands import commands_dict as commands
|
|
|
|
from pip._internal.commands.help import HelpCommand
|
|
|
|
from pip._internal.exceptions import CommandError
|
2011-08-02 19:41:31 +02:00
|
|
|
|
|
|
|
|
2015-12-26 23:58:23 +01:00
|
|
|
def test_run_method_should_return_success_when_finds_command_name():
|
2011-08-02 19:41:31 +02:00
|
|
|
"""
|
|
|
|
Test HelpCommand.run for existing command
|
|
|
|
"""
|
|
|
|
options_mock = Mock()
|
|
|
|
args = ('freeze',)
|
2013-09-17 07:21:15 +02:00
|
|
|
help_cmd = HelpCommand()
|
2011-08-02 19:41:31 +02:00
|
|
|
status = help_cmd.run(options_mock, args)
|
|
|
|
assert status == SUCCESS
|
|
|
|
|
2012-01-30 07:26:12 +01:00
|
|
|
|
2015-12-26 23:58:23 +01:00
|
|
|
def test_run_method_should_return_success_when_command_name_not_specified():
|
2011-08-02 19:41:31 +02:00
|
|
|
"""
|
|
|
|
Test HelpCommand.run when there are no args
|
|
|
|
"""
|
|
|
|
options_mock = Mock()
|
|
|
|
args = ()
|
2013-09-17 07:21:15 +02:00
|
|
|
help_cmd = HelpCommand()
|
2011-08-02 19:41:31 +02:00
|
|
|
status = help_cmd.run(options_mock, args)
|
|
|
|
assert status == SUCCESS
|
|
|
|
|
2012-01-30 07:26:12 +01:00
|
|
|
|
2011-08-02 19:41:31 +02:00
|
|
|
def test_run_method_should_raise_command_error_when_command_does_not_exist():
|
|
|
|
"""
|
|
|
|
Test HelpCommand.run for non-existing command
|
|
|
|
"""
|
|
|
|
options_mock = Mock()
|
|
|
|
args = ('mycommand',)
|
2013-09-17 07:21:15 +02:00
|
|
|
help_cmd = HelpCommand()
|
2013-08-18 11:59:44 +02:00
|
|
|
|
|
|
|
with pytest.raises(CommandError):
|
|
|
|
help_cmd.run(options_mock, args)
|
2011-08-02 19:41:31 +02:00
|
|
|
|
2012-01-30 07:26:12 +01:00
|
|
|
|
2013-08-22 06:40:46 +02:00
|
|
|
def test_help_command_should_exit_status_ok_when_command_exists(script):
|
2011-08-02 19:41:31 +02:00
|
|
|
"""
|
|
|
|
Test `help` command for existing command
|
|
|
|
"""
|
2013-08-21 11:16:07 +02:00
|
|
|
result = script.pip('help', 'freeze')
|
2011-08-02 19:41:31 +02:00
|
|
|
assert result.returncode == SUCCESS
|
|
|
|
|
2012-01-30 07:26:12 +01:00
|
|
|
|
2013-08-22 06:40:46 +02:00
|
|
|
def test_help_command_should_exit_status_ok_when_no_cmd_is_specified(script):
|
2011-08-02 19:41:31 +02:00
|
|
|
"""
|
|
|
|
Test `help` command for no command
|
|
|
|
"""
|
2013-08-21 11:16:07 +02:00
|
|
|
result = script.pip('help')
|
2011-08-02 19:41:31 +02:00
|
|
|
assert result.returncode == SUCCESS
|
|
|
|
|
2012-01-30 07:26:12 +01:00
|
|
|
|
2013-08-22 06:40:46 +02:00
|
|
|
def test_help_command_should_exit_status_error_when_cmd_does_not_exist(script):
|
2011-08-02 19:41:31 +02:00
|
|
|
"""
|
|
|
|
Test `help` command for non-existing command
|
|
|
|
"""
|
2013-08-21 11:16:07 +02:00
|
|
|
result = script.pip('help', 'mycommand', expect_error=True)
|
2011-08-02 19:41:31 +02:00
|
|
|
assert result.returncode == ERROR
|
2012-11-10 05:15:45 +01:00
|
|
|
|
2013-08-22 06:40:46 +02:00
|
|
|
|
2017-03-26 17:17:02 +02:00
|
|
|
def test_help_commands_equally_functional(in_memory_pip):
|
2012-11-10 05:15:45 +01:00
|
|
|
"""
|
2012-12-14 13:45:46 +01:00
|
|
|
Test if `pip help` and 'pip --help' behave the same way.
|
2012-11-10 05:15:45 +01:00
|
|
|
"""
|
2017-03-26 17:17:02 +02:00
|
|
|
results = list(map(in_memory_pip.pip, ('help', '--help')))
|
|
|
|
results.append(in_memory_pip.pip())
|
2012-11-10 05:15:45 +01:00
|
|
|
|
|
|
|
out = map(lambda x: x.stdout, results)
|
|
|
|
ret = map(lambda x: x.returncode, results)
|
|
|
|
|
2012-12-14 13:45:46 +01:00
|
|
|
msg = '"pip --help" != "pip help" != "pip"'
|
|
|
|
assert len(set(out)) == 1, 'output of: ' + msg
|
|
|
|
assert sum(ret) == 0, 'exit codes of: ' + msg
|
2017-03-26 16:54:32 +02:00
|
|
|
assert all(len(o) > 0 for o in out)
|
2012-12-14 13:45:46 +01:00
|
|
|
|
|
|
|
for name, cls in commands.items():
|
2014-01-28 15:17:51 +01:00
|
|
|
if cls.hidden:
|
|
|
|
continue
|
|
|
|
|
|
|
|
assert (
|
2017-03-26 17:17:02 +02:00
|
|
|
in_memory_pip.pip('help', name).stdout ==
|
|
|
|
in_memory_pip.pip(name, '--help').stdout != ""
|
2014-01-28 15:17:51 +01:00
|
|
|
)
|