def test_extra_args_registered(self): argv = ["croud", "print-region", "--region", "westeurope.azure"] croud_cmd = CMD(self.commands) func, args = croud_cmd.resolve(argv) assert func == print_region assert args == Namespace(env=None, region="westeurope.azure")
def test_sub_commands_registered(self): argv = ["croud", "print", "hello"] croud_cmd = CMD(self.commands) func, args = croud_cmd.resolve(argv) assert func == print_hello assert args == Namespace(env=None)
def test_commands_have_env_arg(self): argv = ["croud", "print-env", "--env", "dev"] croud_cmd = CMD(self.commands) func, args = croud_cmd.resolve(argv) assert func == print_env assert args == Namespace(env="dev")
def main(): Configuration.create() colorama.init() croud = CMD(command_tree) resolver, arguments = croud.resolve(sys.argv) if resolver: resolver(arguments)
def test_version(self): argv = ["croud", "--version"] croud_cmd = CMD(self.commands) with mock.patch("sys.stdout.write") as stdout: with pytest.raises(SystemExit) as ex_info: croud_cmd.resolve(argv) assert ex_info.value.code == 0 assert stdout.call_args == mock.call("croud " + __version__ + "\n")
def test_no_args(self): argv = ["croud"] croud_cmd = CMD(self.commands) with mock.patch("sys.stdout.write") as stdout: fn, args = croud_cmd.resolve(argv) assert fn is None assert args is None stdout.assert_called_once() assert stdout.call_args[0][0].startswith("Usage: croud") is True
def test_help(self): argv = ["croud", "--help"] croud_cmd = CMD(self.commands) with mock.patch("sys.stdout.write") as stdout: with pytest.raises(SystemExit) as ex_info: croud_cmd.resolve(argv) stdout.assert_called_once() assert stdout.call_args[0][0].startswith( "Usage: croud") is True assert ex_info.value.code == 0
class CommandTestCase: croud = CMD(command_tree) def assertGql(self, mock_run, argv, expected_body, expected_vars=None): func, args = self.croud.resolve(argv) func(args) mock_run.assert_called_once_with(expected_body, expected_vars)