Code Duplication    Length = 24-27 lines in 2 locations

tests/test_commands.py 2 locations

@@ 223-249 (lines=27) @@
220
    assert result.exit_code == 2
221
222
223
def test_command_flag_on_off(basicApp):
224
    """
225
    This test case registers a command with a flag option. The assigned command handler throws an exception if
226
    the flag is not set.
227
    Then it calls that command twice: fist with the flag set; then with the flag not set.
228
229
    It is asserted, that the first call returns 0, the second one -1 - as that is exit code click's CliRunner returns
230
    in case an unhandled exception has been thrown in the command handler.
231
    """
232
    def _test_command(*args, **kwargs):
233
        print(args)
234
        print(kwargs)
235
        if not kwargs['flag_on']:
236
            raise Exception
237
238
    plugin = basicApp.plugins.get("CommandPlugin")
239
    plugin.commands.unregister("test")
240
    # register a command with an on/off flag; command throws exception if flag is off
241
    plugin.commands.register("test", "my test command", _test_command, params=[Option(["--flag-on/--flag-off"])])
242
243
    # call command with --flag-on (True) -> expect ok
244
    result = CliRunner().invoke(basicApp.commands.get("test").click_command, ['--flag-on'])
245
    assert result.exit_code == 0
246
247
    # call command with --flag-off (False)  -> expect error
248
    result = CliRunner().invoke(basicApp.commands.get("test").click_command, ['--flag-off'])
249
    assert result.exit_code == -1
250
251
252
def test_command_flag_count(basicApp):
@@ 197-220 (lines=24) @@
194
    assert result.exit_code == 2
195
196
197
def test_command_path_option(basicApp):
198
    """
199
    This test case registers a command with a path option that need to exist.
200
    Then it calls that command twice: first with an existing path (the path of this source file); then with a
201
    non-existent one.
202
203
    It is asserted, that the first call returns 0, the second one 2 as exit code.
204
    """
205
    def _test_command(*args, **kwargs):
206
        print(args)
207
        print(kwargs)
208
209
    plugin = basicApp.plugins.get("CommandPlugin")
210
    plugin.commands.unregister("test")
211
    # register a command with a path option, that must exist
212
    plugin.commands.register("test", "my test command", _test_command, params=[Option(["--path"],
213
                                                                                      type=click.Path(exists=True))])
214
    # call command with existing path as option -> expect ok
215
    result = CliRunner().invoke(basicApp.commands.get("test").click_command, ['--path', __file__])
216
    assert result.exit_code == 0
217
218
    # call command with non-existing path as option -> expect error
219
    result = CliRunner().invoke(basicApp.commands.get("test").click_command, ['--path', 'no such path'])
220
    assert result.exit_code == 2
221
222
223
def test_command_flag_on_off(basicApp):