|
@@ 166-182 (lines=17) @@
|
| 163 |
|
assert result.exit_code == 2 |
| 164 |
|
|
| 165 |
|
|
| 166 |
|
def test_command_path_option(basicApp): |
| 167 |
|
def _test_command(*args, **kwargs): |
| 168 |
|
print(args) |
| 169 |
|
print(kwargs) |
| 170 |
|
|
| 171 |
|
plugin = basicApp.plugins.get("CommandPlugin") |
| 172 |
|
plugin.commands.unregister("test") |
| 173 |
|
# register a command with a path option, that must exist |
| 174 |
|
plugin.commands.register("test", "my test command", _test_command, params=[Option(["--path"], |
| 175 |
|
type=click.Path(exists=True))]) |
| 176 |
|
# call command with existing path as option -> expect ok |
| 177 |
|
result = CliRunner().invoke(basicApp.commands.get("test").click_command, ['--path', __file__]) |
| 178 |
|
assert result.exit_code == 0 |
| 179 |
|
|
| 180 |
|
# call command with non-existing path as option -> expect error |
| 181 |
|
result = CliRunner().invoke(basicApp.commands.get("test").click_command, ['--path', 'no such path']) |
| 182 |
|
assert result.exit_code == 2 |
| 183 |
|
|
| 184 |
|
|
| 185 |
|
def test_command_flag_on_off(basicApp): |
|
@@ 147-163 (lines=17) @@
|
| 144 |
|
assert result.exit_code == 0 |
| 145 |
|
|
| 146 |
|
|
| 147 |
|
def test_command_path_argument(basicApp): |
| 148 |
|
def _test_command(*args, **kwargs): |
| 149 |
|
print(args) |
| 150 |
|
print(kwargs) |
| 151 |
|
|
| 152 |
|
plugin = basicApp.plugins.get("CommandPlugin") |
| 153 |
|
plugin.commands.unregister("test") |
| 154 |
|
# register a command with a path argument, that must exist |
| 155 |
|
plugin.commands.register("test", "my test command", _test_command, params=[Argument(("man_arg",), |
| 156 |
|
type=click.Path(exists=True))]) |
| 157 |
|
# call command with existing path as argument -> expect ok |
| 158 |
|
result = CliRunner().invoke(basicApp.commands.get("test").click_command, [__file__]) |
| 159 |
|
assert result.exit_code == 0 |
| 160 |
|
|
| 161 |
|
# call command with non-existing path as argument -> expect error |
| 162 |
|
result = CliRunner().invoke(basicApp.commands.get("test").click_command, ['no such path']) |
| 163 |
|
assert result.exit_code == 2 |
| 164 |
|
|
| 165 |
|
|
| 166 |
|
def test_command_path_option(basicApp): |
|
@@ 129-144 (lines=16) @@
|
| 126 |
|
assert result.exit_code == 2 |
| 127 |
|
|
| 128 |
|
|
| 129 |
|
def test_command_optional_option(basicApp): |
| 130 |
|
def _test_command(*args, **kwargs): |
| 131 |
|
print(args) |
| 132 |
|
print(kwargs) |
| 133 |
|
|
| 134 |
|
plugin = basicApp.plugins.get("CommandPlugin") |
| 135 |
|
plugin.commands.unregister("test") |
| 136 |
|
# register a command with a mandatory option |
| 137 |
|
plugin.commands.register("test", "my test command", _test_command, params=[Option(["--opt-opt"], required=False)]) |
| 138 |
|
# call command with option --opt-opt -> expect ok |
| 139 |
|
result = CliRunner().invoke(basicApp.commands.get("test").click_command, ["--opt-opt", 123]) |
| 140 |
|
assert result.exit_code == 0 |
| 141 |
|
|
| 142 |
|
# call command with no option -> expect ok |
| 143 |
|
result = CliRunner().invoke(basicApp.commands.get("test").click_command, []) |
| 144 |
|
assert result.exit_code == 0 |
| 145 |
|
|
| 146 |
|
|
| 147 |
|
def test_command_path_argument(basicApp): |
|
@@ 111-126 (lines=16) @@
|
| 108 |
|
assert result.exit_code == 0 |
| 109 |
|
|
| 110 |
|
|
| 111 |
|
def test_command_mandatory_option(basicApp): |
| 112 |
|
def _test_command(*args, **kwargs): |
| 113 |
|
print(args) |
| 114 |
|
print(kwargs) |
| 115 |
|
|
| 116 |
|
plugin = basicApp.plugins.get("CommandPlugin") |
| 117 |
|
plugin.commands.unregister("test") |
| 118 |
|
# register a command with a mandatory option |
| 119 |
|
plugin.commands.register("test", "my test command", _test_command, params=[Option(["--man-opt"], required=True)]) |
| 120 |
|
# call command with option --man-opt -> expect ok |
| 121 |
|
result = CliRunner().invoke(basicApp.commands.get("test").click_command, ["--man-opt", 123]) |
| 122 |
|
assert result.exit_code == 0 |
| 123 |
|
|
| 124 |
|
# call command with no option -> expect error |
| 125 |
|
result = CliRunner().invoke(basicApp.commands.get("test").click_command, []) |
| 126 |
|
assert result.exit_code == 2 |
| 127 |
|
|
| 128 |
|
|
| 129 |
|
def test_command_optional_option(basicApp): |
|
@@ 93-108 (lines=16) @@
|
| 90 |
|
assert result.exit_code == 2 |
| 91 |
|
|
| 92 |
|
|
| 93 |
|
def test_command_optional_argument(basicApp): |
| 94 |
|
def _test_command(*args, **kwargs): |
| 95 |
|
print(args) |
| 96 |
|
print(kwargs) |
| 97 |
|
|
| 98 |
|
plugin = basicApp.plugins.get("CommandPlugin") |
| 99 |
|
plugin.commands.unregister("test") |
| 100 |
|
# register a command with an optional argument |
| 101 |
|
plugin.commands.register("test", "my test command", _test_command, params=[Argument(("opt_arg",), required=False)]) |
| 102 |
|
# call command with argument -> expect ok |
| 103 |
|
result = CliRunner().invoke(basicApp.commands.get("test").click_command, ["arg"]) |
| 104 |
|
assert result.exit_code == 0 |
| 105 |
|
|
| 106 |
|
# call command with no argument -> expect ok |
| 107 |
|
result = CliRunner().invoke(basicApp.commands.get("test").click_command, []) |
| 108 |
|
assert result.exit_code == 0 |
| 109 |
|
|
| 110 |
|
|
| 111 |
|
def test_command_mandatory_option(basicApp): |
|
@@ 75-90 (lines=16) @@
|
| 72 |
|
assert len(plugin2.commands.get()) == 0 |
| 73 |
|
|
| 74 |
|
|
| 75 |
|
def test_command_mandatory_argument(basicApp): |
| 76 |
|
def _test_command(*args, **kwargs): |
| 77 |
|
print(args) |
| 78 |
|
print(kwargs) |
| 79 |
|
|
| 80 |
|
plugin = basicApp.plugins.get("CommandPlugin") |
| 81 |
|
plugin.commands.unregister("test") |
| 82 |
|
# register a command with a mandatory argument |
| 83 |
|
plugin.commands.register("test", "my test command", _test_command, params=[Argument(("man_arg",), required=True)]) |
| 84 |
|
# call command with argument -> expect ok |
| 85 |
|
result = CliRunner().invoke(basicApp.commands.get("test").click_command, ["arg"]) |
| 86 |
|
assert result.exit_code == 0 |
| 87 |
|
|
| 88 |
|
# call command with no argument -> expect error |
| 89 |
|
result = CliRunner().invoke(basicApp.commands.get("test").click_command, []) |
| 90 |
|
assert result.exit_code == 2 |
| 91 |
|
|
| 92 |
|
|
| 93 |
|
def test_command_optional_argument(basicApp): |