Skip to content

Commit 3084375

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

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

commitizen/git.py

+5-1
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

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
from datetime import date
3+
from unittest import mock
34

45
import pytest
56

@@ -533,6 +534,7 @@ def test_changelog_with_filename_as_empty_string(mocker, changelog_path, config_
533534

534535
@pytest.mark.usefixtures("tmp_commitizen_project")
535536
@pytest.mark.freeze_time("2022-02-13")
537+
@mock.patch("commitizen.git.GitTag.date", "2022-02-13")
536538
def test_changelog_from_rev_first_version_from_arg(
537539
mocker, config_path, changelog_path, file_regression
538540
):
@@ -564,6 +566,7 @@ def test_changelog_from_rev_first_version_from_arg(
564566

565567
@pytest.mark.usefixtures("tmp_commitizen_project")
566568
@pytest.mark.freeze_time("2022-02-13")
569+
@mock.patch("commitizen.git.GitTag.date", "2022-02-13")
567570
def test_changelog_from_rev_latest_version_from_arg(
568571
mocker, config_path, changelog_path, file_regression
569572
):
@@ -651,6 +654,7 @@ def test_changelog_from_rev_range_version_not_found(mocker, config_path):
651654

652655
@pytest.mark.usefixtures("tmp_commitizen_project")
653656
@pytest.mark.freeze_time("2022-02-13")
657+
@mock.patch("commitizen.git.GitTag.date", "2022-02-13")
654658
def test_changelog_from_rev_version_range_including_first_tag(
655659
mocker, config_path, changelog_path, file_regression
656660
):
@@ -682,6 +686,7 @@ def test_changelog_from_rev_version_range_including_first_tag(
682686

683687
@pytest.mark.usefixtures("tmp_commitizen_project")
684688
@pytest.mark.freeze_time("2022-02-13")
689+
@mock.patch("commitizen.git.GitTag.date", "2022-02-13")
685690
def test_changelog_from_rev_version_range_from_arg(
686691
mocker, config_path, changelog_path, file_regression
687692
):
@@ -718,6 +723,7 @@ def test_changelog_from_rev_version_range_from_arg(
718723

719724
@pytest.mark.usefixtures("tmp_commitizen_project")
720725
@pytest.mark.freeze_time("2022-02-13")
726+
@mock.patch("commitizen.git.GitTag.date", "2022-02-13")
721727
def test_changelog_from_rev_version_with_big_range_from_arg(
722728
mocker, config_path, changelog_path, file_regression
723729
):
@@ -772,6 +778,7 @@ def test_changelog_from_rev_version_with_big_range_from_arg(
772778

773779
@pytest.mark.usefixtures("tmp_commitizen_project")
774780
@pytest.mark.freeze_time("2022-02-13")
781+
@mock.patch("commitizen.git.GitTag.date", "2022-02-13")
775782
def test_changelog_from_rev_latest_version_dry_run(
776783
mocker, capsys, config_path, changelog_path, file_regression
777784
):

0 commit comments

Comments
 (0)