Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4a0730a

Browse files
committed
refactor(git): use date as a function in GitTag to easily patch
1 parent 5ec1e79 commit 4a0730a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

commitizen/git.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ class GitTag(GitObject):
3939
def __init__(self, name, rev, date):
4040
self.rev = rev.strip()
4141
self.name = name.strip()
42-
self.date = date.strip()
42+
self._date = date.strip()
4343

4444
def __repr__(self):
4545
return f"GitTag('{self.name}', '{self.rev}', '{self.date}')"
4646

47+
@property
48+
def date(self):
49+
return self._date
50+
4751
@classmethod
4852
def from_line(cls, line: str, inner_delimiter: str) -> "GitTag":
4953

tests/commands/test_changelog_command.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from datetime import date
3-
3+
from unittest import mock
44
import pytest
55

66
from commitizen import cli, git
@@ -533,6 +533,7 @@ def test_changelog_with_filename_as_empty_string(mocker, changelog_path, config_
533533

534534
@pytest.mark.usefixtures("tmp_commitizen_project")
535535
@pytest.mark.freeze_time("2022-02-13")
536+
@mock.patch("commitizen.git.GitTag.date", "2022-02-13")
536537
def test_changelog_from_rev_first_version_from_arg(
537538
mocker, config_path, changelog_path, file_regression
538539
):
@@ -564,6 +565,7 @@ def test_changelog_from_rev_first_version_from_arg(
564565

565566
@pytest.mark.usefixtures("tmp_commitizen_project")
566567
@pytest.mark.freeze_time("2022-02-13")
568+
@mock.patch("commitizen.git.GitTag.date", "2022-02-13")
567569
def test_changelog_from_rev_latest_version_from_arg(
568570
mocker, config_path, changelog_path, file_regression
569571
):
@@ -651,6 +653,7 @@ def test_changelog_from_rev_range_version_not_found(mocker, config_path):
651653

652654
@pytest.mark.usefixtures("tmp_commitizen_project")
653655
@pytest.mark.freeze_time("2022-02-13")
656+
@mock.patch("commitizen.git.GitTag.date", "2022-02-13")
654657
def test_changelog_from_rev_version_range_including_first_tag(
655658
mocker, config_path, changelog_path, file_regression
656659
):
@@ -682,6 +685,7 @@ def test_changelog_from_rev_version_range_including_first_tag(
682685

683686
@pytest.mark.usefixtures("tmp_commitizen_project")
684687
@pytest.mark.freeze_time("2022-02-13")
688+
@mock.patch("commitizen.git.GitTag.date", "2022-02-13")
685689
def test_changelog_from_rev_version_range_from_arg(
686690
mocker, config_path, changelog_path, file_regression
687691
):
@@ -718,6 +722,7 @@ def test_changelog_from_rev_version_range_from_arg(
718722

719723
@pytest.mark.usefixtures("tmp_commitizen_project")
720724
@pytest.mark.freeze_time("2022-02-13")
725+
@mock.patch("commitizen.git.GitTag.date", "2022-02-13")
721726
def test_changelog_from_rev_version_with_big_range_from_arg(
722727
mocker, config_path, changelog_path, file_regression
723728
):
@@ -772,6 +777,7 @@ def test_changelog_from_rev_version_with_big_range_from_arg(
772777

773778
@pytest.mark.usefixtures("tmp_commitizen_project")
774779
@pytest.mark.freeze_time("2022-02-13")
780+
@mock.patch("commitizen.git.GitTag.date", "2022-02-13")
775781
def test_changelog_from_rev_latest_version_dry_run(
776782
mocker, capsys, config_path, changelog_path, file_regression
777783
):

0 commit comments

Comments
 (0)