1
1
import sys
2
- import time
3
-
4
2
from datetime import date
5
- from unittest import mock
6
3
7
4
import pytest
8
5
15
12
NotAGitProjectError ,
16
13
NotAllowed ,
17
14
)
18
- from tests .utils import create_file_and_commit
15
+ from tests .utils import create_file_and_commit , wait_for_tag
19
16
20
17
21
18
@pytest .mark .usefixtures ("tmp_commitizen_project" )
@@ -536,10 +533,11 @@ def test_changelog_with_filename_as_empty_string(mocker, changelog_path, config_
536
533
537
534
@pytest .mark .usefixtures ("tmp_commitizen_project" )
538
535
@pytest .mark .freeze_time ("2022-02-13" )
539
- @mock .patch ("commitizen.git.GitTag.date" , "2022-02-13" )
540
536
def test_changelog_from_rev_first_version_from_arg (
541
537
mocker , config_path , changelog_path , file_regression
542
538
):
539
+ mocker .patch ("commitizen.git.GitTag.date" , "2022-02-13" )
540
+
543
541
with open (config_path , "a" ) as f :
544
542
f .write ('tag_format = "$version"\n ' )
545
543
@@ -549,18 +547,18 @@ def test_changelog_from_rev_first_version_from_arg(
549
547
testargs = ["cz" , "bump" , "--yes" ]
550
548
mocker .patch .object (sys , "argv" , testargs )
551
549
cli .main ()
552
- time .sleep (0.5 )
550
+ wait_for_tag ()
551
+
553
552
create_file_and_commit ("feat: after 0.2.0" )
554
553
create_file_and_commit ("feat: another feature" )
555
554
556
555
testargs = ["cz" , "bump" , "--yes" ]
557
556
mocker .patch .object (sys , "argv" , testargs )
558
557
cli .main ()
559
- time . sleep ( 0.5 )
558
+
560
559
testargs = ["cz" , "changelog" , "0.2.0" ]
561
560
mocker .patch .object (sys , "argv" , testargs )
562
561
cli .main ()
563
-
564
562
with open (changelog_path , "r" ) as f :
565
563
out = f .read ()
566
564
@@ -569,10 +567,11 @@ def test_changelog_from_rev_first_version_from_arg(
569
567
570
568
@pytest .mark .usefixtures ("tmp_commitizen_project" )
571
569
@pytest .mark .freeze_time ("2022-02-13" )
572
- @mock .patch ("commitizen.git.GitTag.date" , "2022-02-13" )
573
570
def test_changelog_from_rev_latest_version_from_arg (
574
571
mocker , config_path , changelog_path , file_regression
575
572
):
573
+ mocker .patch ("commitizen.git.GitTag.date" , "2022-02-13" )
574
+
576
575
with open (config_path , "a" ) as f :
577
576
f .write ('tag_format = "$version"\n ' )
578
577
@@ -581,14 +580,17 @@ def test_changelog_from_rev_latest_version_from_arg(
581
580
testargs = ["cz" , "bump" , "--yes" ]
582
581
mocker .patch .object (sys , "argv" , testargs )
583
582
cli .main ()
584
- time .sleep (0.5 )
583
+ wait_for_tag ()
584
+
585
585
create_file_and_commit ("feat: after 0.2.0" )
586
586
create_file_and_commit ("feat: another feature" )
587
587
588
588
testargs = ["cz" , "bump" , "--yes" ]
589
589
mocker .patch .object (sys , "argv" , testargs )
590
590
cli .main ()
591
- time .sleep (0.5 )
591
+
592
+ wait_for_tag ()
593
+
592
594
testargs = ["cz" , "changelog" , "0.3.0" ]
593
595
mocker .patch .object (sys , "argv" , testargs )
594
596
cli .main ()
@@ -613,12 +615,15 @@ def test_changelog_from_rev_single_version_not_found(
613
615
mocker .patch .object (sys , "argv" , testargs )
614
616
cli .main ()
615
617
618
+ wait_for_tag ()
619
+
616
620
create_file_and_commit ("feat: after 0.2.0" )
617
621
create_file_and_commit ("feat: another feature" )
618
622
619
623
testargs = ["cz" , "bump" , "--yes" ]
620
624
mocker .patch .object (sys , "argv" , testargs )
621
625
cli .main ()
626
+ wait_for_tag ()
622
627
623
628
testargs = ["cz" , "changelog" , "0.8.0" ] # it shouldn't exist
624
629
mocker .patch .object (sys , "argv" , testargs )
@@ -657,10 +662,11 @@ def test_changelog_from_rev_range_version_not_found(mocker, config_path):
657
662
658
663
@pytest .mark .usefixtures ("tmp_commitizen_project" )
659
664
@pytest .mark .freeze_time ("2022-02-13" )
660
- @mock .patch ("commitizen.git.GitTag.date" , "2022-02-13" )
661
665
def test_changelog_from_rev_version_range_including_first_tag (
662
666
mocker , config_path , changelog_path , file_regression
663
667
):
668
+ mocker .patch ("commitizen.git.GitTag.date" , "2022-02-13" )
669
+
664
670
with open (config_path , "a" ) as f :
665
671
f .write ('tag_format = "$version"\n ' )
666
672
@@ -683,16 +689,16 @@ def test_changelog_from_rev_version_range_including_first_tag(
683
689
with open (changelog_path , "r" ) as f :
684
690
out = f .read ()
685
691
686
- print (out )
687
692
file_regression .check (out , extension = ".md" )
688
693
689
694
690
695
@pytest .mark .usefixtures ("tmp_commitizen_project" )
691
696
@pytest .mark .freeze_time ("2022-02-13" )
692
- @mock .patch ("commitizen.git.GitTag.date" , "2022-02-13" )
693
697
def test_changelog_from_rev_version_range_from_arg (
694
698
mocker , config_path , changelog_path , file_regression
695
699
):
700
+ mocker .patch ("commitizen.git.GitTag.date" , "2022-02-13" )
701
+
696
702
with open (config_path , "a" ) as f :
697
703
f .write ('tag_format = "$version"\n ' )
698
704
@@ -701,21 +707,21 @@ def test_changelog_from_rev_version_range_from_arg(
701
707
testargs = ["cz" , "bump" , "--yes" ]
702
708
mocker .patch .object (sys , "argv" , testargs )
703
709
cli .main ()
704
- time . sleep ( 0.5 )
710
+ wait_for_tag ( )
705
711
create_file_and_commit ("feat: after 0.2.0" )
706
712
create_file_and_commit ("feat: another feature" )
707
713
708
714
testargs = ["cz" , "bump" , "--yes" ]
709
715
mocker .patch .object (sys , "argv" , testargs )
710
716
cli .main ()
711
- time . sleep ( 0.5 )
717
+ wait_for_tag ( )
712
718
713
719
create_file_and_commit ("feat: getting ready for this" )
714
720
715
721
testargs = ["cz" , "bump" , "--yes" ]
716
722
mocker .patch .object (sys , "argv" , testargs )
717
723
cli .main ()
718
- time . sleep ( 0.5 )
724
+ wait_for_tag ( )
719
725
720
726
testargs = ["cz" , "changelog" , "0.3.0..0.4.0" ]
721
727
mocker .patch .object (sys , "argv" , testargs )
@@ -728,10 +734,11 @@ def test_changelog_from_rev_version_range_from_arg(
728
734
729
735
@pytest .mark .usefixtures ("tmp_commitizen_project" )
730
736
@pytest .mark .freeze_time ("2022-02-13" )
731
- @mock .patch ("commitizen.git.GitTag.date" , "2022-02-13" )
732
737
def test_changelog_from_rev_version_with_big_range_from_arg (
733
738
mocker , config_path , changelog_path , file_regression
734
739
):
740
+ mocker .patch ("commitizen.git.GitTag.date" , "2022-02-13" )
741
+
735
742
with open (config_path , "a" ) as f :
736
743
f .write ('tag_format = "$version"\n ' )
737
744
@@ -741,40 +748,40 @@ def test_changelog_from_rev_version_with_big_range_from_arg(
741
748
testargs = ["cz" , "bump" , "--yes" ]
742
749
mocker .patch .object (sys , "argv" , testargs )
743
750
cli .main ()
744
- time . sleep ( 0.5 )
751
+ wait_for_tag ( )
745
752
746
753
create_file_and_commit ("feat: after 0.2.0" )
747
754
create_file_and_commit ("feat: another feature" )
748
755
749
756
testargs = ["cz" , "bump" , "--yes" ] # 0.3.0
750
757
mocker .patch .object (sys , "argv" , testargs )
751
758
cli .main ()
752
- time . sleep ( 0.5 )
759
+ wait_for_tag ( )
753
760
create_file_and_commit ("feat: getting ready for this" )
754
761
755
762
testargs = ["cz" , "bump" , "--yes" ] # 0.4.0
756
763
mocker .patch .object (sys , "argv" , testargs )
757
764
cli .main ()
758
- time . sleep ( 0.5 )
765
+ wait_for_tag ( )
759
766
create_file_and_commit ("fix: small error" )
760
767
761
768
testargs = ["cz" , "bump" , "--yes" ] # 0.4.1
762
769
mocker .patch .object (sys , "argv" , testargs )
763
770
cli .main ()
764
- time . sleep ( 0.5 )
771
+ wait_for_tag ( )
765
772
create_file_and_commit ("feat: new shinny feature" )
766
773
767
774
testargs = ["cz" , "bump" , "--yes" ] # 0.5.0
768
775
mocker .patch .object (sys , "argv" , testargs )
769
776
cli .main ()
770
- time . sleep ( 0.5 )
777
+ wait_for_tag ( )
771
778
create_file_and_commit ("feat: amazing different shinny feature" )
772
779
# dirty hack to avoid same time between tags
773
780
774
781
testargs = ["cz" , "bump" , "--yes" ] # 0.6.0
775
782
mocker .patch .object (sys , "argv" , testargs )
776
783
cli .main ()
777
- time . sleep ( 0.5 )
784
+ wait_for_tag ( )
778
785
779
786
testargs = ["cz" , "changelog" , "0.3.0..0.5.0" ]
780
787
mocker .patch .object (sys , "argv" , testargs )
@@ -787,10 +794,10 @@ def test_changelog_from_rev_version_with_big_range_from_arg(
787
794
788
795
@pytest .mark .usefixtures ("tmp_commitizen_project" )
789
796
@pytest .mark .freeze_time ("2022-02-13" )
790
- @mock .patch ("commitizen.git.GitTag.date" , "2022-02-13" )
791
797
def test_changelog_from_rev_latest_version_dry_run (
792
798
mocker , capsys , config_path , changelog_path , file_regression
793
799
):
800
+ mocker .patch ("commitizen.git.GitTag.date" , "2022-02-13" )
794
801
795
802
with open (config_path , "a" ) as f :
796
803
f .write ('tag_format = "$version"\n ' )
@@ -800,15 +807,17 @@ def test_changelog_from_rev_latest_version_dry_run(
800
807
testargs = ["cz" , "bump" , "--yes" ]
801
808
mocker .patch .object (sys , "argv" , testargs )
802
809
cli .main ()
803
- time .sleep (0.5 )
810
+ wait_for_tag ()
811
+
804
812
create_file_and_commit ("feat: after 0.2.0" )
805
813
create_file_and_commit ("feat: another feature" )
806
814
807
815
testargs = ["cz" , "bump" , "--yes" ]
808
816
mocker .patch .object (sys , "argv" , testargs )
809
817
cli .main ()
810
818
capsys .readouterr ()
811
- time .sleep (0.5 )
819
+ wait_for_tag ()
820
+
812
821
testargs = ["cz" , "changelog" , "0.3.0" , "--dry-run" ]
813
822
mocker .patch .object (sys , "argv" , testargs )
814
823
with pytest .raises (DryRunExit ):
0 commit comments