Exemplo n.º 1
0
def test_check_a_range_of_git_commits_and_failed(config, mocker):
    error_mock = mocker.patch("commitizen.out.error")
    mocker.patch(
        "commitizen.git.get_commits",
        return_value=_build_fake_git_commits(
            ["This commit does not follow rule"]),
    )
    check_cmd = commands.Check(config=config,
                               arguments={"rev_range": "HEAD~10..master"})

    with pytest.raises(InvalidCommitMessageError):
        check_cmd()
        error_mock.assert_called_once()
Exemplo n.º 2
0
def test_check_conventional_commit(mocker):
    success_mock = mocker.patch("commitizen.out.success")
    with get_temp_dir() as dir:

        tempfile = os.path.join(dir, "temp_commit_file")
        with open(tempfile, 'w') as f:
            f.write("feat(lang): added polish language")

        check_cmd = commands.Check(config=config,
                                   arguments={"commit_msg_file": tempfile})

        check_cmd()
        success_mock.assert_called_once()
Exemplo n.º 3
0
def test_check_no_conventional_commit(mocker):
    with pytest.raises(SystemExit):
        error_mock = mocker.patch("commitizen.out.error")

        with get_temp_dir() as dir:

            tempfile = os.path.join(dir, "temp_commit_file")
            with open(tempfile, 'w') as f:
                f.write("no conventional commit")

            check_cmd = commands.Check(config=config,
                                       arguments={"commit_msg_file": tempfile})
            check_cmd()
            error_mock.assert_called_once()
Exemplo n.º 4
0
def test_check_a_range_of_failed_git_commits(config, mocker):
    ill_formated_commits_msgs = [
        "First commit does not follow rule",
        "Second commit does not follow rule",
        ("Third commit does not follow rule\n" "Ill-formatted commit with body"),
    ]
    mocker.patch(
        "commitizen.git.get_commits",
        return_value=_build_fake_git_commits(ill_formated_commits_msgs),
    )
    check_cmd = commands.Check(
        config=config, arguments={"rev_range": "HEAD~10..master"}
    )

    with pytest.raises(InvalidCommitMessageError) as excinfo:
        check_cmd()
    assert all([msg in str(excinfo.value) for msg in ill_formated_commits_msgs])
Exemplo n.º 5
0
def test_check_command_with_empty_range(config, mocker):
    check_cmd = commands.Check(config=config, arguments={"rev_range": "master..master"})
    with pytest.raises(NoCommitsFoundError) as excinfo:
        check_cmd()

    assert "No commit found with range: 'master..master'" in str(excinfo)
Exemplo n.º 6
0
def test_check_command_when_commit_file_not_found(config):
    with pytest.raises(FileNotFoundError):
        commands.Check(config=config, arguments={"commit_msg_file": "no_such_file"})()
Exemplo n.º 7
0
def test_check_command_with_invalid_argment(args, config, capsys):
    with pytest.raises(SystemExit):
        commands.Check(config=config, arguments=args)
    _, err = capsys.readouterr()
    assert "One and only one argument is required for check command!" in err
Exemplo n.º 8
0
def test_check_command_with_invalid_argment(args, config):
    with pytest.raises(InvalidCommandArgumentError) as excinfo:
        commands.Check(config=config, arguments=args)
    assert "One and only one argument is required for check command!" in str(
        excinfo.value)