@@ -834,19 +834,11 @@ def test_bump_manual_version_disallows_prerelease_offset(mocker):
834834
835835
836836def test_bump_command_prelease_version_type_via_cli (
837- tmp_commitizen_project , mocker : MockFixture
837+ tmp_commitizen_project_initial , mocker : MockFixture
838838):
839- # PRERELEASE
839+ tmp_commitizen_project = tmp_commitizen_project_initial ()
840840 tmp_version_file = tmp_commitizen_project .join ("__version__.py" )
841- tmp_version_file .write ("0.1.0" )
842841 tmp_commitizen_cfg_file = tmp_commitizen_project .join ("pyproject.toml" )
843- tmp_version_file_string = str (tmp_version_file ).replace ("\\ " , "/" )
844- tmp_commitizen_cfg_file .write (
845- f"{ tmp_commitizen_cfg_file .read ()} \n "
846- f'version_files = ["{ tmp_version_file_string } "]'
847- )
848-
849- create_file_and_commit ("feat: new user interface" )
850842
851843 testargs = [
852844 "cz" ,
@@ -863,11 +855,9 @@ def test_bump_command_prelease_version_type_via_cli(
863855 tag_exists = git .tag_exist ("0.2.0-a0" )
864856 assert tag_exists is True
865857
866- with open (tmp_version_file , "r" ) as f :
867- assert "0.2.0-a0" in f .read ()
868-
869- with open (tmp_commitizen_cfg_file , "r" ) as f :
870- assert "0.2.0-a0" in f .read ()
858+ for version_file in [tmp_version_file , tmp_commitizen_cfg_file ]:
859+ with open (version_file , "r" ) as f :
860+ assert "0.2.0-a0" in f .read ()
871861
872862 # PRERELEASE BUMP CREATES VERSION WITHOUT PRERELEASE
873863 testargs = ["cz" , "bump" , "--yes" ]
@@ -877,28 +867,19 @@ def test_bump_command_prelease_version_type_via_cli(
877867 tag_exists = git .tag_exist ("0.2.0" )
878868 assert tag_exists is True
879869
880- with open (tmp_version_file , "r" ) as f :
881- assert "0.2.0" in f .read ()
882-
883- with open (tmp_commitizen_cfg_file , "r" ) as f :
884- assert "0.2.0" in f .read ()
870+ for version_file in [tmp_version_file , tmp_commitizen_cfg_file ]:
871+ with open (version_file , "r" ) as f :
872+ assert "0.2.0" in f .read ()
885873
886874
887875def test_bump_command_prelease_version_type_via_config (
888- tmp_commitizen_project , mocker : MockFixture
876+ tmp_commitizen_project_initial , mocker : MockFixture
889877):
890- # PRERELEASE
878+ tmp_commitizen_project = tmp_commitizen_project_initial (
879+ config_extra = 'version_type = "semver"\n ' ,
880+ )
891881 tmp_version_file = tmp_commitizen_project .join ("__version__.py" )
892- tmp_version_file .write ("0.1.0" )
893882 tmp_commitizen_cfg_file = tmp_commitizen_project .join ("pyproject.toml" )
894- tmp_version_file_string = str (tmp_version_file ).replace ("\\ " , "/" )
895- tmp_commitizen_cfg_file .write (
896- f"{ tmp_commitizen_cfg_file .read ()} \n "
897- f'version_files = ["{ tmp_version_file_string } "]\n '
898- f'version_type = "semver"'
899- )
900-
901- create_file_and_commit ("feat: new user interface" )
902883
903884 testargs = ["cz" , "bump" , "--prerelease" , "alpha" , "--yes" ]
904885 mocker .patch .object (sys , "argv" , testargs )
@@ -907,11 +888,9 @@ def test_bump_command_prelease_version_type_via_config(
907888 tag_exists = git .tag_exist ("0.2.0-a0" )
908889 assert tag_exists is True
909890
910- with open (tmp_version_file , "r" ) as f :
911- assert "0.2.0-a0" in f .read ()
912-
913- with open (tmp_commitizen_cfg_file , "r" ) as f :
914- assert "0.2.0-a0" in f .read ()
891+ for version_file in [tmp_version_file , tmp_commitizen_cfg_file ]:
892+ with open (version_file , "r" ) as f :
893+ assert "0.2.0-a0" in f .read ()
915894
916895 testargs = ["cz" , "bump" , "--prerelease" , "alpha" , "--yes" ]
917896 mocker .patch .object (sys , "argv" , testargs )
@@ -920,11 +899,9 @@ def test_bump_command_prelease_version_type_via_config(
920899 tag_exists = git .tag_exist ("0.2.0-a1" )
921900 assert tag_exists is True
922901
923- with open (tmp_version_file , "r" ) as f :
924- assert "0.2.0-a1" in f .read ()
925-
926- with open (tmp_commitizen_cfg_file , "r" ) as f :
927- assert "0.2.0-a1" in f .read ()
902+ for version_file in [tmp_version_file , tmp_commitizen_cfg_file ]:
903+ with open (version_file , "r" ) as f :
904+ assert "0.2.0-a1" in f .read ()
928905
929906 # PRERELEASE BUMP CREATES VERSION WITHOUT PRERELEASE
930907 testargs = ["cz" , "bump" , "--yes" ]
@@ -934,28 +911,19 @@ def test_bump_command_prelease_version_type_via_config(
934911 tag_exists = git .tag_exist ("0.2.0" )
935912 assert tag_exists is True
936913
937- with open (tmp_version_file , "r" ) as f :
938- assert "0.2.0" in f .read ()
939-
940- with open (tmp_commitizen_cfg_file , "r" ) as f :
941- assert "0.2.0" in f .read ()
914+ for version_file in [tmp_version_file , tmp_commitizen_cfg_file ]:
915+ with open (version_file , "r" ) as f :
916+ assert "0.2.0" in f .read ()
942917
943918
944919def test_bump_command_prelease_version_type_check_old_tags (
945- tmp_commitizen_project , mocker : MockFixture
920+ tmp_commitizen_project_initial , mocker : MockFixture
946921):
947- # PRERELEASE
922+ tmp_commitizen_project = tmp_commitizen_project_initial (
923+ config_extra = ('tag_format = "v$version"\n version_type = "semver"\n ' ),
924+ )
948925 tmp_version_file = tmp_commitizen_project .join ("__version__.py" )
949- tmp_version_file .write ("0.1.0" )
950926 tmp_commitizen_cfg_file = tmp_commitizen_project .join ("pyproject.toml" )
951- tmp_version_file_string = str (tmp_version_file ).replace ("\\ " , "/" )
952- tmp_commitizen_cfg_file .write (
953- f"{ tmp_commitizen_cfg_file .read ()} \n "
954- f'version_files = ["{ tmp_version_file_string } "]\n '
955- f'tag_format = "v$version"\n '
956- f'version_type = "semver"\n '
957- )
958- create_file_and_commit ("feat: new user interface" )
959927
960928 testargs = ["cz" , "bump" , "--prerelease" , "alpha" , "--yes" ]
961929 mocker .patch .object (sys , "argv" , testargs )
@@ -964,11 +932,9 @@ def test_bump_command_prelease_version_type_check_old_tags(
964932 tag_exists = git .tag_exist ("v0.2.0-a0" )
965933 assert tag_exists is True
966934
967- with open (tmp_version_file , "r" ) as f :
968- assert "0.2.0-a0" in f .read ()
969-
970- with open (tmp_commitizen_cfg_file , "r" ) as f :
971- assert "0.2.0-a0" in f .read ()
935+ for version_file in [tmp_version_file , tmp_commitizen_cfg_file ]:
936+ with open (version_file , "r" ) as f :
937+ assert "0.2.0-a0" in f .read ()
972938
973939 testargs = ["cz" , "bump" , "--prerelease" , "alpha" ]
974940 mocker .patch .object (sys , "argv" , testargs )
@@ -977,11 +943,9 @@ def test_bump_command_prelease_version_type_check_old_tags(
977943 tag_exists = git .tag_exist ("v0.2.0-a1" )
978944 assert tag_exists is True
979945
980- with open (tmp_version_file , "r" ) as f :
981- assert "0.2.0-a1" in f .read ()
982-
983- with open (tmp_commitizen_cfg_file , "r" ) as f :
984- assert "0.2.0-a1" in f .read ()
946+ for version_file in [tmp_version_file , tmp_commitizen_cfg_file ]:
947+ with open (version_file , "r" ) as f :
948+ assert "0.2.0-a1" in f .read ()
985949
986950 # PRERELEASE BUMP CREATES VERSION WITHOUT PRERELEASE
987951 testargs = ["cz" , "bump" ]
@@ -991,8 +955,6 @@ def test_bump_command_prelease_version_type_check_old_tags(
991955 tag_exists = git .tag_exist ("v0.2.0" )
992956 assert tag_exists is True
993957
994- with open (tmp_version_file , "r" ) as f :
995- assert "0.2.0" in f .read ()
996-
997- with open (tmp_commitizen_cfg_file , "r" ) as f :
998- assert "0.2.0" in f .read ()
958+ for version_file in [tmp_version_file , tmp_commitizen_cfg_file ]:
959+ with open (version_file , "r" ) as f :
960+ assert "0.2.0" in f .read ()
0 commit comments