Skip to content

Commit

Permalink
style: Resolve duty check-types
Browse files Browse the repository at this point in the history
Issue: pawamoy#59
Resolves: pawamoy#59
  • Loading branch information
sandzhaj committed Oct 8, 2023
1 parent 515c023 commit 4739f4d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/git_changelog/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class CommitConvention(ABC):
TYPE_REGEX: ClassVar[Pattern]
BREAK_REGEX: ClassVar[Pattern]
DEFAULT_RENDER: ClassVar[list[str]]
MINOR_TYPES: ClassVar[list[str]]

@abstractmethod
def parse_commit(self, commit: Commit) -> dict[str, str | bool]:
Expand Down
39 changes: 24 additions & 15 deletions tests/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

from __future__ import annotations

from abc import ABCMeta
from typing import Generator

import pytest

from git_changelog.commit import (
AngularConvention,
BasicConvention,
Commit,
CommitConvention,
ConventionalCommitConvention,
)

Expand Down Expand Up @@ -43,20 +47,23 @@ def test_parsing_trailers(body: str, expected_trailers: dict[str, str]) -> None:


@pytest.fixture()
def _reserve_types() -> None:
def _reserve_types() -> Generator[None, None, None]:
"""Fixture to preserve the conventional types."""
original_types = {
AngularConvention: [dict(AngularConvention.TYPES), list(AngularConvention.MINOR_TYPES)],
BasicConvention: [dict(BasicConvention.TYPES), list(BasicConvention.MINOR_TYPES)],
ConventionalCommitConvention: [dict(ConventionalCommitConvention.TYPES), list(ConventionalCommitConvention.MINOR_TYPES)],
original_types: dict[type[CommitConvention], tuple[dict[str, str], list[str]]] = {
AngularConvention: (dict(AngularConvention.TYPES), list(AngularConvention.MINOR_TYPES)),
BasicConvention: (dict(BasicConvention.TYPES), list(BasicConvention.MINOR_TYPES)),
ConventionalCommitConvention: (dict(ConventionalCommitConvention.TYPES),
list(ConventionalCommitConvention.MINOR_TYPES)),
}

yield
AngularConvention.TYPES = original_types[AngularConvention][0]
BasicConvention.TYPES = original_types[BasicConvention][0]
ConventionalCommitConvention.TYPES = original_types[ConventionalCommitConvention][0]
AngularConvention.MINOR_TYPES = original_types[AngularConvention][1]
BasicConvention.MINOR_TYPES = original_types[BasicConvention][1]
ConventionalCommitConvention.MINOR_TYPES = original_types[ConventionalCommitConvention][1]

AngularConvention.TYPES = dict(original_types[AngularConvention][0])
BasicConvention.TYPES = dict(original_types[BasicConvention][0])
ConventionalCommitConvention.TYPES = dict(original_types[ConventionalCommitConvention][0])
AngularConvention.MINOR_TYPES = list(original_types[AngularConvention][1])
BasicConvention.MINOR_TYPES = list(original_types[BasicConvention][1])
ConventionalCommitConvention.MINOR_TYPES = list(original_types[ConventionalCommitConvention][1])


@pytest.mark.usefixtures("_reserve_types")
Expand Down Expand Up @@ -85,7 +92,9 @@ def test_is_minor_works_with_custom_minor_types() -> None:
)
convention.replace_types(_new_types)
convention.update_minor_list(_minor_types)
commit_dict = convention().parse_commit(commit)
assert not commit_dict["is_major"]
assert commit_dict["is_minor"]
assert not commit_dict["is_patch"]
if not isinstance(convention, ABCMeta):
conv = convention()
commit_dict = conv.parse_commit(commit)
assert not commit_dict["is_major"]
assert commit_dict["is_minor"]
assert not commit_dict["is_patch"]

0 comments on commit 4739f4d

Please sign in to comment.