Beispiel #1
0
def test_execute_from_config_prints_description_if_defined(
        mock_plz_config, mock_exit, capfd):
    # Arrange
    config = {
        "commands": {
            "foo": {
                "cmd": "echo bar",
                "description": "a description"
            }
        }
    }
    mock_plz_config.return_value = (config, None)

    # Act
    main.execute_from_config("foo", [])
    out, err = capfd.readouterr()

    # Assert
    assert (out == textwrap.dedent("""
        \x1b[36m
        Description: a description\x1b[0m
        \x1b[36m\x1b[2m
        ===============================================================================
        Running command: echo bar
        ===============================================================================
        \x1b[0m
        bar

        \x1b[36m\x1b[2m[INFO] Process complete\x1b[0m
        """).lstrip())
Beispiel #2
0
def test_execute_from_config_with_invalid_cmd(mock_plz_config, mock_exit):
    # Arrange
    args = ['args']
    mock_plz_config.return_value = ([{'id': 'testcmd', 'cmd': 'derp'}], None)

    # Act
    execute_from_config('badcmd', args)

    # Assert
    mock_exit.assert_called_with(1)
Beispiel #3
0
def test_execute_from_config_with_invalid_cmd(mock_plz_config, mock_exit):
    # Arrange
    args = ["args"]
    config = get_sample_config()
    mock_plz_config.return_value = (config, None)

    # Act
    main.execute_from_config("badcmd", args)

    # Assert
    mock_exit.assert_called_with(1)
Beispiel #4
0
def test_execute_from_config_with_dir(mock_plz_config, mock_gather, mock_exit):
    # Arrange
    args = ["args"]
    config = get_sample_config(dir="foo")
    mock_plz_config.return_value = (config, None)

    # Act
    main.execute_from_config("testcmd", args)

    # Assert
    mock_gather.assert_called_with("derp", cwd="foo", args=args, shortcuts={})
Beispiel #5
0
def test_execute_from_config_with_valid_cmd_and_cwd(mock_plz_config,
                                                    mock_gather, mock_exit):
    # Arrange
    args = ['args']
    cwd = '/root/path'
    mock_plz_config.return_value = ([{'id': 'testcmd', 'cmd': 'derp'}], cwd)

    # Act
    execute_from_config('testcmd', args)

    # Assert
    mock_gather.assert_called_with('derp', cwd=cwd, args=args)
Beispiel #6
0
def test_execute_from_config_with_valid_cmd_and_cwd(mock_plz_config,
                                                    mock_gather, mock_exit):
    # Arrange
    args = ["args"]
    cwd = "/root/path"
    config = get_sample_config()
    mock_plz_config.return_value = (config, cwd)

    # Act
    main.execute_from_config("testcmd", args)

    # Assert
    mock_gather.assert_called_with("derp", cwd=cwd, args=args, shortcuts={})
Beispiel #7
0
def test_execute_from_config_with_valid_cmd_with_no_inner_cmd(
        mock_plz_config, mock_exit):
    # Arrange
    args = ["args"]
    config = get_sample_config()
    cmd = config["commands"]["testcmd"]
    cmd["noncmd"] = cmd.pop("cmd")
    mock_plz_config.return_value = (config, None)

    # Act
    main.execute_from_config("testcmd", args)

    # Assert
    mock_exit.assert_called_with(1)
Beispiel #8
0
def test_execute_from_config_passes_shortcuts_dict_if_defined(
        mock_plz_config, mock_gather, mock_exit):
    # Arrange
    args = ["args"]
    shortcuts = {"foo": "bar"}
    config = get_sample_config()
    config["shortcuts"] = shortcuts
    mock_plz_config.return_value = (config, None)

    # Act
    main.execute_from_config("testcmd", args)

    # Assert
    mock_gather.assert_called_with(ANY, cwd=ANY, args=ANY, shortcuts=shortcuts)
Beispiel #9
0
def test_execute_from_config_with_complex_cmd(mock_plz_config, mock_gather,
                                              mock_exit):
    # Arrange
    args = ['args']
    mock_plz_config.return_value = ([{
        'id': 'testcmd',
        'cmd': ['derp', 'herp']
    }], None)

    # Act
    execute_from_config('testcmd', args)

    # Assert
    mock_gather.assert_called_with(['derp', 'herp'], cwd=None, args=args)
Beispiel #10
0
def test_execute_from_config_with_complex_cmd(mock_plz_config, mock_gather,
                                              mock_exit):
    # Arrange
    args = ["args"]
    config = get_sample_config(cmd=["derp", "herp"])
    mock_plz_config.return_value = (config, None)

    # Act
    main.execute_from_config("testcmd", args)

    # Assert
    mock_gather.assert_called_with(["derp", "herp"],
                                   cwd=None,
                                   args=args,
                                   shortcuts={})
Beispiel #11
0
def test_execute_from_config_handles_string_command(mock_plz_config,
                                                    mock_gather, mock_exit):
    # Arrange
    args = ["args"]
    config = get_sample_config()
    config["commands"]["testcmd"] = "test string"
    mock_plz_config.return_value = (config, None)

    # Act
    main.execute_from_config("testcmd", args)

    # Assert
    mock_gather.assert_called_with("test string",
                                   cwd=None,
                                   args=args,
                                   shortcuts={})
Beispiel #12
0
def test_execute_from_config_passes_env_dict_if_defined(
        mock_compile_environment, mock_plz_config, mock_gather, mock_exit):
    # Arrange
    args = ["args"]
    config = get_sample_config()
    mock_plz_config.return_value = (config, None)
    mock_compile_environment.return_value = {"foo": "bar"}

    # Act
    main.execute_from_config("testcmd", args)

    # Assert
    mock_gather.assert_called_with(ANY,
                                   cwd=ANY,
                                   args=ANY,
                                   env={"foo": "bar"},
                                   shortcuts=ANY)