Exemplo n.º 1
0
def test_CommitMessageHeadStartsWithDetector_invalid_pattern():
    """Check to see if the detectors validate the pattern."""
    detector = detectors.CommitMessageHeadStartsWithDetector('name',
                                                             'BAD_CHANGE_TYPE',
                                                             pattern=[])
    with pytest.raises(exception.DetectorValidationException):
        assert detector.validate_detector_params()
Exemplo n.º 2
0
def test_CommitMessageHeadStartsWithDetector_trigger_strip(simple_repo: str) -> None:
    """Check the strip functionality."""
    repo = git.Repo(simple_repo, odbt=git.GitDB)
    pattern = 'abcd'
    message = '  \n\n ' + pattern + ' extra text'
    file_path = os.path.join(repo.working_dir, 'dummy_file')
    open(file_path, 'w+').close()
    commit = repo.index.commit(message)

    detector = detectors.CommitMessageHeadStartsWithDetector(
        'name', 'MAJOR', pattern=pattern)
    assert detector.evaluate(commit)

    detector_no_strip = detectors.CommitMessageHeadStartsWithDetector(
        'name', 'MAJOR', pattern=pattern, strip=False)
    assert not detector_no_strip.evaluate(commit)
Exemplo n.º 3
0
def test_CommitMessageHeadStartsWithDetector_trigger_case(simple_repo: str) -> None:
    """Validate the case sensitivity functionality."""
    repo = git.Repo(simple_repo, odbt=git.GitDB)
    pattern = 'Abcd'
    message = pattern + ' extra text'
    file_path = os.path.join(repo.working_dir, 'dummy_file')
    open(file_path, 'w+').close()
    commit = repo.index.commit(message)

    detector = detectors.CommitMessageHeadStartsWithDetector(
        'name', 'MAJOR', pattern=pattern)
    assert detector.evaluate(commit)

    detector_bad_pattern = detectors.CommitMessageHeadStartsWithDetector(
        'name', 'MAJOR', pattern=pattern.lower())
    assert not detector_bad_pattern.evaluate(commit)

    detector_insesitive = detectors.CommitMessageHeadStartsWithDetector(
        'name', 'MAJOR', pattern=pattern.lower(), case_sensitive=False)
    assert detector_insesitive.evaluate(commit)
Exemplo n.º 4
0
def test_CommitMessageHeadStartsWithDetector_not_trigger(simple_repo: str) -> None:
    """Check to see if the detector avoids miss matches."""
    repo = git.Repo(simple_repo, odbt=git.GitDB)
    pattern = 'abcd'
    message = 'extra text' + pattern + ' extra text'
    file_path = os.path.join(repo.working_dir, 'dummy_file')
    open(file_path, 'w+').close()
    commit = repo.index.commit(message)

    detector = detectors.CommitMessageHeadStartsWithDetector(
        'name', 'MAJOR', pattern=pattern)
    assert not detector.evaluate(commit)
Exemplo n.º 5
0
def test_CommitMessageHeadStartsWithDetector_trigger(simple_repo):
    """Check the happy flow of the trigger."""
    repo = git.Repo(simple_repo, odbt=git.GitDB)
    pattern = 'abcd'
    message = pattern + ' extra text'
    file_path = os.path.join(repo.working_dir, 'dummy_file')
    open(file_path, 'w+').close()
    commit = repo.index.commit(message)

    detector = detectors.CommitMessageHeadStartsWithDetector('name',
                                                             'MAJOR',
                                                             pattern=pattern)
    assert detector.evaluate(commit)
Exemplo n.º 6
0
def test_CommitMessageHeadStartsWithDetector_invalid_type() -> None:
    """Check to see if the detectors validate the change_type."""
    detector = detectors.CommitMessageHeadStartsWithDetector(
        'name', 'BAD_CHANGE_TYPE', pattern='test-pattern')
    with pytest.raises(exception.DetectorValidationException):
        assert detector.validate_detector_params()
Exemplo n.º 7
0
def test_CommitMessageHeadStartsWithDetector_validation_type() -> None:
    """Check the validation for the detector."""
    detector = detectors.CommitMessageHeadStartsWithDetector(
        'name', 'MAJOR', pattern='test-pattern')
    assert detector.validate_detector_params() is None