コード例 #1
0
def test_should_fail_if_yaml_file_is_not_present(capsys):
    run("tests/data/1build.yaml", ['build'])
    captured = capsys.readouterr()

    invalid_file_error_message = \
        "No 'tests/data/1build.yaml' file found in current directory.\n"

    assert invalid_file_error_message in captured.out
コード例 #2
0
def test_create_default_yaml_file():
    mock_file_writer = MagicMock()

    with patch("onebuild.main.write_default_config_file",
               mock_file_writer,
               create=True):
        run("", ['--init', 'some project'])

    mock_file_writer.assert_called_with('some project')
コード例 #3
0
def test_build_successful_command(capsys):
    run("tests/data/build_file.yaml", ['build'])
    captured = capsys.readouterr()
    expected_message = "" + DASH + "\n" \
                                   "Name: build\n" \
                                   "Command: echo 'Running build'\n" \
                       + DASH + "\n"
    expected_command_output = "Running build"
    assert expected_message in captured.out
    assert expected_command_output in captured.out
コード例 #4
0
def test_create_default_yaml_file(mock_isfile):
    mock_file_writer = MagicMock()

    mock_isfile.return_value = False

    with patch("onebuild.init_command.write", mock_file_writer, create=True):
        run("", ['--init', 'some project'])

    mock_file_writer.assert_called_with(
        '1build.yaml', 'w',
        "project: some project\ncommands:\n  - build: echo 'Running build'")
コード例 #5
0
def test_should_fails_if_no_command_found_with_given_name(capsys):
    run("tests/data/build_file.yaml", ['random'])
    captured = capsys.readouterr()

    invalid_file_error = "No command 'random' found in config file\n\n" \
                         "" + DASH + "\n" \
                                     "project: Sample Project\n" \
                                     "commands:\n" \
                                     "build | echo 'Running build'\n" \
                                     "lint | echo 'Running lint'\n" \
                                     "" + DASH

    assert invalid_file_error in captured.out
コード例 #6
0
def test_should_work_with_only_after_command(capsys):
    run("tests/data/build_file_with_after_only.yaml", ['build'])
    captured = capsys.readouterr()
    expected_cmd_message = "" + DASH + "\n" + \
                           "Name: build\n" + \
                           "Command: echo 'Running build'\n" + \
                           "After: echo 'Running some cleanup script'\n" + \
                           DASH + "\n"
    expected_command_output = "Running build"
    expected_after_command_output = "Running some cleanup script"
    assert expected_cmd_message in captured.out
    assert expected_command_output in captured.out
    assert expected_after_command_output in captured.out
コード例 #7
0
def test_build_successful_with_before_and_after_command(capsys):
    run("tests/data/build_file_with_before_and_after.yaml", ['build'])
    captured = capsys.readouterr()
    expected_cmd_message = "" + DASH + "\nName: build\n" + \
                           "Command: echo 'Running build'\n" + \
                           "Before: echo 'Running some setup script'\n" + \
                           "After: echo 'Running some cleanup script'\n" + \
                           DASH + "\n"
    expected_before_command_output = "Running some setup script"
    expected_command_output = "Running build"
    expected_after_command_output = "Running some cleanup script"
    assert expected_cmd_message in captured.out
    assert expected_before_command_output in captured.out
    assert expected_command_output in captured.out
    assert expected_after_command_output in captured.out
コード例 #8
0
def test_should_fail_if_yaml_file_is_not_in_correct_yaml_format(capsys):
    run("tests/data/invalid_yaml_file.yaml", ['build'])
    captured = capsys.readouterr()

    invalid_file_error_message = \
        "Error in parsing 'tests/data/invalid_yaml_file.yaml' config file." \
        " Make sure file is in correct format.\n" \
        "Sample format is:\n\n" \
        + DASH + "\n" \
                 "project: Sample Project\n" \
                 "commands:\n" \
                 "  - build: ./gradlew clean build\n" \
                 "  - lint: ./gradlew spotlessApply\n" \
        + DASH

    assert invalid_file_error_message in captured.out
コード例 #9
0
def test_error_message_if_file_already_exists(mock_isfile):
    mock_file_writer = MagicMock()

    mock_isfile.return_value = True

    captured_output = StringIO()
    sys.stdout = captured_output

    with patch("onebuild.init_command.write", mock_file_writer, create=True):
        run("", ['--init', 'some project'])

    sys.stdout = sys.__stdout__
    assert "1build.yaml configuration file already exists." \
           in captured_output.getvalue()

    mock_file_writer.assert_not_called()
コード例 #10
0
def test_show_help(capsys):
    run("tests/data/build_file.yaml", ['--help'])

    assert_usage_help(capsys)
コード例 #11
0
def test_show_version(capsys):
    run("tests/data/build_file.yaml", ['--version'])
    assert_version(capsys)
コード例 #12
0
def test_error_message_if_file_name_is_not_provided_with_init(capsys):
    run("", ['--init'])
    captured = capsys.readouterr()
    expected_message = "The 'project name' parameter is missing with --init" \
                       "\n\nusage: 1build --init project_name"
    assert expected_message in captured.out
コード例 #13
0
def test_show_version_mismatch(capsys):
    version_message = "1build 1.0.1"
    run("tests/data/build_file.yaml", ['-v'])
    captured = capsys.readouterr()
    assert version_message != captured.out
コード例 #14
0
def test_show_version_on_short_input(capsys):
    run("tests/data/build_file.yaml", ['-v'])

    assert_version(capsys)
コード例 #15
0
def test_show_list_of_commands(capsys):
    run("tests/data/build_file.yaml", ['--list'])

    assert_list_of_command_help(capsys)
コード例 #16
0
def test_show_list_of_commands_on_short_input(capsys):
    run("tests/data/build_file.yaml", ['-l'])

    assert_list_of_command_help(capsys)
コード例 #17
0
def test_show_help_on_not_input(capsys):
    run("tests/data/build_file.yaml", [])
    assert_usage_help(capsys)