22
33import inspect
44import re
5- from pathlib import Path
65from textwrap import dedent
76from typing import TYPE_CHECKING
87from unittest .mock import call
2928)
3029
3130if TYPE_CHECKING :
32- import py
31+ from pathlib import Path
32+
3333 from pytest_mock import MockFixture
3434 from pytest_regressions .file_regression import FileRegressionFixture
3535
@@ -117,8 +117,8 @@ def test_bump_minor_increment_annotated_config_file(
117117def test_bump_minor_increment_signed_config_file (
118118 commit_msg : str , util : UtilFixture , tmp_commitizen_project_with_gpg
119119):
120- tmp_commitizen_cfg_file = tmp_commitizen_project_with_gpg . join ( "pyproject.toml" )
121- with Path ( tmp_commitizen_cfg_file ) .open ("a" , encoding = "utf-8" ) as f :
120+ tmp_commitizen_cfg_file = tmp_commitizen_project_with_gpg / "pyproject.toml"
121+ with tmp_commitizen_cfg_file .open ("a" , encoding = "utf-8" ) as f :
122122 f .write ("\n gpg_sign = 1" )
123123 util .create_file_and_commit (commit_msg )
124124 util .run_cli ("bump" , "--yes" )
@@ -360,11 +360,11 @@ def test_bump_when_no_new_commit(util: UtilFixture):
360360def test_bump_when_version_inconsistent_in_version_files (
361361 tmp_commitizen_project , util : UtilFixture
362362):
363- tmp_version_file = tmp_commitizen_project . join ( "__version__.py" )
364- tmp_version_file .write ("100.999.10000" )
365- tmp_commitizen_cfg_file = tmp_commitizen_project . join ( "pyproject.toml" )
363+ tmp_version_file = tmp_commitizen_project / "__version__.py"
364+ tmp_version_file .write_text ("100.999.10000" )
365+ tmp_commitizen_cfg_file = tmp_commitizen_project / "pyproject.toml"
366366 tmp_version_file_string = str (tmp_version_file ).replace ("\\ " , "/" )
367- with Path ( tmp_commitizen_cfg_file ) .open ("a" , encoding = "utf-8" ) as f :
367+ with tmp_commitizen_cfg_file .open ("a" , encoding = "utf-8" ) as f :
368368 f .write (f'\n version_files = ["{ tmp_version_file_string } "]' )
369369
370370 util .create_file_and_commit ("feat: new file" )
@@ -378,17 +378,17 @@ def test_bump_when_version_inconsistent_in_version_files(
378378def test_bump_major_version_zero_when_major_is_not_zero (
379379 tmp_commitizen_project , util : UtilFixture
380380):
381- tmp_version_file = tmp_commitizen_project . join ( "__version__.py" )
382- tmp_version_file .write ("1.0.0" )
381+ tmp_version_file = tmp_commitizen_project / "__version__.py"
382+ tmp_version_file .write_text ("1.0.0" )
383383 tmp_version_file_string = str (tmp_version_file ).replace ("\\ " , "/" )
384- tmp_commitizen_cfg_file = tmp_commitizen_project . join ( "pyproject.toml" )
385- tmp_commitizen_cfg_file .write (
384+ tmp_commitizen_cfg_file = tmp_commitizen_project / "pyproject.toml"
385+ tmp_commitizen_cfg_file .write_text (
386386 f"[tool.commitizen]\n "
387387 'version="1.0.0"\n '
388388 f'version_files = ["{ str (tmp_version_file_string )} "]'
389389 )
390- tmp_changelog_file = tmp_commitizen_project . join ( "CHANGELOG.md" )
391- tmp_changelog_file .write ("## v1.0.0" )
390+ tmp_changelog_file = tmp_commitizen_project / "CHANGELOG.md"
391+ tmp_changelog_file .write_text ("## v1.0.0" )
392392
393393 util .create_file_and_commit ("feat(user): new file" )
394394 util .create_tag ("v1.0.0" )
@@ -403,11 +403,11 @@ def test_bump_major_version_zero_when_major_is_not_zero(
403403
404404
405405def test_bump_files_only (tmp_commitizen_project , util : UtilFixture ):
406- tmp_version_file = tmp_commitizen_project . join ( "__version__.py" )
407- tmp_version_file .write ("0.1.0" )
408- tmp_commitizen_cfg_file = tmp_commitizen_project . join ( "pyproject.toml" )
406+ tmp_version_file = tmp_commitizen_project / "__version__.py"
407+ tmp_version_file .write_text ("0.1.0" )
408+ tmp_commitizen_cfg_file = tmp_commitizen_project / "pyproject.toml"
409409 tmp_version_file_string = str (tmp_version_file ).replace ("\\ " , "/" )
410- with Path ( tmp_commitizen_cfg_file ) .open ("a" , encoding = "utf-8" ) as f :
410+ with tmp_commitizen_cfg_file .open ("a" , encoding = "utf-8" ) as f :
411411 f .write (f'\n version_files = ["{ tmp_version_file_string } "]' )
412412
413413 util .create_file_and_commit ("feat: new user interface" )
@@ -420,17 +420,17 @@ def test_bump_files_only(tmp_commitizen_project, util: UtilFixture):
420420
421421 assert git .tag_exist ("0.3.0" ) is False
422422
423- assert "0.3.0" in Path ( tmp_version_file ) .read_text (encoding = "utf-8" )
423+ assert "0.3.0" in tmp_version_file .read_text (encoding = "utf-8" )
424424
425- assert "0.3.0" in Path ( tmp_commitizen_cfg_file ) .read_text (encoding = "utf-8" )
425+ assert "0.3.0" in tmp_commitizen_cfg_file .read_text (encoding = "utf-8" )
426426
427427
428428def test_bump_local_version (tmp_commitizen_project , util : UtilFixture ):
429- tmp_version_file = tmp_commitizen_project . join ( "__version__.py" )
430- tmp_version_file .write ("4.5.1+0.1.0" )
431- tmp_commitizen_cfg_file = tmp_commitizen_project . join ( "pyproject.toml" )
429+ tmp_version_file = tmp_commitizen_project / "__version__.py"
430+ tmp_version_file .write_text ("4.5.1+0.1.0" )
431+ tmp_commitizen_cfg_file = tmp_commitizen_project / "pyproject.toml"
432432 tmp_version_file_string = str (tmp_version_file ).replace ("\\ " , "/" )
433- tmp_commitizen_cfg_file .write (
433+ tmp_commitizen_cfg_file .write_text (
434434 f"[tool.commitizen]\n "
435435 'version="4.5.1+0.1.0"\n '
436436 f'version_files = ["{ tmp_version_file_string } "]'
@@ -440,7 +440,7 @@ def test_bump_local_version(tmp_commitizen_project, util: UtilFixture):
440440 util .run_cli ("bump" , "--yes" , "--local-version" )
441441 assert git .tag_exist ("4.5.1+0.2.0" ) is True
442442
443- assert "4.5.1+0.2.0" in Path ( tmp_version_file ) .read_text (encoding = "utf-8" )
443+ assert "4.5.1+0.2.0" in tmp_version_file .read_text (encoding = "utf-8" )
444444
445445
446446@pytest .mark .usefixtures ("tmp_commitizen_project" )
@@ -455,11 +455,10 @@ def test_bump_dry_run(util: UtilFixture, capsys: pytest.CaptureFixture):
455455 assert git .tag_exist ("0.2.0" ) is False
456456
457457
458- def test_bump_in_non_git_project (tmpdir , util : UtilFixture ):
459- with tmpdir .as_cwd ():
460- with pytest .raises (NotAGitProjectError ):
461- with pytest .raises (ExpectedExit ):
462- util .run_cli ("bump" , "--yes" )
458+ def test_bump_in_non_git_project (tmp_path , monkeypatch , util : UtilFixture ):
459+ monkeypatch .chdir (tmp_path )
460+ with pytest .raises (NotAGitProjectError ):
461+ util .run_cli ("bump" , "--yes" )
463462
464463
465464def test_none_increment_exit_should_be_a_class ():
@@ -676,13 +675,13 @@ def test_bump_changelog_command_commits_untracked_changelog_and_version_files(
676675 - Call commitizen main cli and assert that the `CHANGELOG.md` and the version file were committed.
677676 """
678677
679- with tmp_commitizen_project . join ( "pyproject.toml" ).open (
678+ with ( tmp_commitizen_project / "pyproject.toml" ).open (
680679 mode = "a" ,
681680 encoding = "utf-8" ,
682681 ) as commitizen_config :
683682 commitizen_config .write (f"version_files = [\n '{ version_regex } '\n ]" )
684683
685- with tmp_commitizen_project . join ( version_filepath ).open (
684+ with ( tmp_commitizen_project / version_filepath ).open (
686685 mode = "a+" , encoding = "utf-8"
687686 ) as version_file :
688687 version_file .write (version_file_content )
@@ -789,12 +788,10 @@ def test_bump_version_with_less_components_in_config(
789788 assert git .tag_exist (expected_version_after_bump ) is True
790789
791790 for version_file in [
792- tmp_commitizen_project . join ( "__version__.py" ) ,
793- tmp_commitizen_project . join ( "pyproject.toml" ) ,
791+ tmp_commitizen_project / "__version__.py" ,
792+ tmp_commitizen_project / "pyproject.toml" ,
794793 ]:
795- assert expected_version_after_bump in Path (version_file ).read_text (
796- encoding = "utf-8"
797- )
794+ assert expected_version_after_bump in version_file .read_text (encoding = "utf-8" )
798795
799796
800797@pytest .mark .parametrize ("commit_msg" , ["feat: new file" , "feat(user): new file" ])
@@ -804,8 +801,8 @@ def test_bump_with_pre_bump_hooks(
804801 pre_bump_hook = "scripts/pre_bump_hook.sh"
805802 post_bump_hook = "scripts/post_bump_hook.sh"
806803
807- tmp_commitizen_cfg_file = tmp_commitizen_project . join ( "pyproject.toml" )
808- with Path ( tmp_commitizen_cfg_file ) .open ("a" , encoding = "utf-8" ) as f :
804+ tmp_commitizen_cfg_file = tmp_commitizen_project / "pyproject.toml"
805+ with tmp_commitizen_cfg_file .open ("a" , encoding = "utf-8" ) as f :
809806 f .write (
810807 f'\n pre_bump_hooks = ["{ pre_bump_hook } "]\n '
811808 f'post_bump_hooks = ["{ post_bump_hook } "]\n '
@@ -855,8 +852,8 @@ def test_bump_with_hooks_and_increment(
855852 pre_bump_hook = "scripts/pre_bump_hook.sh"
856853 post_bump_hook = "scripts/post_bump_hook.sh"
857854
858- tmp_commitizen_cfg_file = tmp_commitizen_project . join ( "pyproject.toml" )
859- with Path ( tmp_commitizen_cfg_file ) .open ("a" , encoding = "utf-8" ) as f :
855+ tmp_commitizen_cfg_file = tmp_commitizen_project / "pyproject.toml"
856+ with tmp_commitizen_cfg_file .open ("a" , encoding = "utf-8" ) as f :
860857 f .write (
861858 f'\n pre_bump_hooks = ["{ pre_bump_hook } "]\n '
862859 f'post_bump_hooks = ["{ post_bump_hook } "]\n '
@@ -892,8 +889,8 @@ def test_bump_command_prerelease_scheme_via_cli(
892889 tmp_commitizen_project_initial , util : UtilFixture
893890):
894891 tmp_commitizen_project = tmp_commitizen_project_initial ()
895- tmp_version_file = tmp_commitizen_project . join ( "__version__.py" )
896- tmp_commitizen_cfg_file = tmp_commitizen_project . join ( "pyproject.toml" )
892+ tmp_version_file = tmp_commitizen_project / "__version__.py"
893+ tmp_commitizen_cfg_file = tmp_commitizen_project / "pyproject.toml"
897894
898895 util .run_cli (
899896 "bump" ,
@@ -906,14 +903,14 @@ def test_bump_command_prerelease_scheme_via_cli(
906903 assert git .tag_exist ("0.2.0-a0" ) is True
907904
908905 for version_file in [tmp_version_file , tmp_commitizen_cfg_file ]:
909- assert "0.2.0-a0" in Path ( version_file ) .read_text (encoding = "utf-8" )
906+ assert "0.2.0-a0" in version_file .read_text (encoding = "utf-8" )
910907
911908 # PRERELEASE BUMP CREATES VERSION WITHOUT PRERELEASE
912909 util .run_cli ("bump" , "--yes" )
913910 assert git .tag_exist ("0.2.0" ) is True
914911
915912 for version_file in [tmp_version_file , tmp_commitizen_cfg_file ]:
916- assert "0.2.0" in Path ( version_file ) .read_text (encoding = "utf-8" )
913+ assert "0.2.0" in version_file .read_text (encoding = "utf-8" )
917914
918915
919916def test_bump_command_prerelease_scheme_via_config (
@@ -922,27 +919,27 @@ def test_bump_command_prerelease_scheme_via_config(
922919 tmp_commitizen_project = tmp_commitizen_project_initial (
923920 config_extra = 'version_scheme = "semver"\n ' ,
924921 )
925- tmp_version_file = tmp_commitizen_project . join ( "__version__.py" )
926- tmp_commitizen_cfg_file = tmp_commitizen_project . join ( "pyproject.toml" )
922+ tmp_version_file = tmp_commitizen_project / "__version__.py"
923+ tmp_commitizen_cfg_file = tmp_commitizen_project / "pyproject.toml"
927924
928925 util .run_cli ("bump" , "--prerelease" , "alpha" , "--yes" )
929926 assert git .tag_exist ("0.2.0-a0" ) is True
930927
931928 for version_file in [tmp_version_file , tmp_commitizen_cfg_file ]:
932- assert "0.2.0-a0" in Path ( version_file ) .read_text (encoding = "utf-8" )
929+ assert "0.2.0-a0" in version_file .read_text (encoding = "utf-8" )
933930
934931 util .run_cli ("bump" , "--prerelease" , "alpha" , "--yes" )
935932 assert git .tag_exist ("0.2.0-a1" ) is True
936933
937934 for version_file in [tmp_version_file , tmp_commitizen_cfg_file ]:
938- assert "0.2.0-a1" in Path ( version_file ) .read_text (encoding = "utf-8" )
935+ assert "0.2.0-a1" in version_file .read_text (encoding = "utf-8" )
939936
940937 # PRERELEASE BUMP CREATES VERSION WITHOUT PRERELEASE
941938 util .run_cli ("bump" , "--yes" )
942939 assert git .tag_exist ("0.2.0" ) is True
943940
944941 for version_file in [tmp_version_file , tmp_commitizen_cfg_file ]:
945- assert "0.2.0" in Path ( version_file ) .read_text (encoding = "utf-8" )
942+ assert "0.2.0" in version_file .read_text (encoding = "utf-8" )
946943
947944
948945def test_bump_command_prerelease_scheme_check_old_tags (
@@ -951,27 +948,27 @@ def test_bump_command_prerelease_scheme_check_old_tags(
951948 tmp_commitizen_project = tmp_commitizen_project_initial (
952949 config_extra = ('tag_format = "v$version"\n version_scheme = "semver"\n ' ),
953950 )
954- tmp_version_file = tmp_commitizen_project . join ( "__version__.py" )
955- tmp_commitizen_cfg_file = tmp_commitizen_project . join ( "pyproject.toml" )
951+ tmp_version_file = tmp_commitizen_project / "__version__.py"
952+ tmp_commitizen_cfg_file = tmp_commitizen_project / "pyproject.toml"
956953
957954 util .run_cli ("bump" , "--prerelease" , "alpha" , "--yes" )
958955 assert git .tag_exist ("v0.2.0-a0" ) is True
959956
960957 for version_file in [tmp_version_file , tmp_commitizen_cfg_file ]:
961- assert "0.2.0-a0" in Path ( version_file ) .read_text (encoding = "utf-8" )
958+ assert "0.2.0-a0" in version_file .read_text (encoding = "utf-8" )
962959
963960 util .run_cli ("bump" , "--prerelease" , "alpha" )
964961 assert git .tag_exist ("v0.2.0-a1" ) is True
965962
966963 for version_file in [tmp_version_file , tmp_commitizen_cfg_file ]:
967- assert "0.2.0-a1" in Path ( version_file ) .read_text (encoding = "utf-8" )
964+ assert "0.2.0-a1" in version_file .read_text (encoding = "utf-8" )
968965
969966 # PRERELEASE BUMP CREATES VERSION WITHOUT PRERELEASE
970967 util .run_cli ("bump" )
971968 assert git .tag_exist ("v0.2.0" ) is True
972969
973970 for version_file in [tmp_version_file , tmp_commitizen_cfg_file ]:
974- assert "0.2.0" in Path ( version_file ) .read_text (encoding = "utf-8" )
971+ assert "0.2.0" in version_file .read_text (encoding = "utf-8" )
975972
976973
977974@pytest .mark .usefixtures ("tmp_commitizen_project" )
@@ -1062,7 +1059,7 @@ def test_bump_template_option_precedence(
10621059 cfg : str ,
10631060 expected : str ,
10641061):
1065- project_root = Path ( tmp_commitizen_project )
1062+ project_root = tmp_commitizen_project
10661063 cfg_template = project_root / "changelog.cfg"
10671064 cmd_template = project_root / "changelog.cmd"
10681065 default_template = project_root / any_changelog_format .template
@@ -1101,7 +1098,7 @@ def test_bump_template_extras_precedence(
11011098 any_changelog_format : ChangelogFormat ,
11021099 mock_plugin : BaseCommitizen ,
11031100):
1104- project_root = Path ( tmp_commitizen_project )
1101+ project_root = tmp_commitizen_project
11051102 changelog_tpl = project_root / any_changelog_format .template
11061103 changelog_tpl .write_text ("{{first}} - {{second}} - {{third}}" )
11071104
@@ -1142,7 +1139,7 @@ def test_bump_template_extra_quotes(
11421139 util : UtilFixture ,
11431140 any_changelog_format : ChangelogFormat ,
11441141):
1145- project_root = Path ( tmp_commitizen_project )
1142+ project_root = tmp_commitizen_project
11461143 changelog_tpl = project_root / any_changelog_format .template
11471144 changelog_tpl .write_text ("{{first}} - {{second}} - {{third}}" )
11481145
@@ -1170,7 +1167,7 @@ def test_bump_changelog_contains_increment_only(
11701167):
11711168 """Issue 1024"""
11721169 # Initialize commitizen up to v1.0.0
1173- project_root = Path ( tmp_commitizen_project )
1170+ project_root = tmp_commitizen_project
11741171 tmp_commitizen_cfg_file = project_root / "pyproject.toml"
11751172 tmp_commitizen_cfg_file .write_text (
11761173 '[tool.commitizen]\n version="1.0.0"\n update_changelog_on_bump = true\n '
@@ -1277,7 +1274,7 @@ def test_bump_allow_no_commit_with_increment(
12771274 tmp_commitizen_project , util : UtilFixture , capsys
12781275):
12791276 with tmp_commitizen_project .as_cwd ():
1280- # # Create the first commit and bump to 1.0.0
1277+ # Create the first commit and bump to 1.0.0
12811278 util .create_file_and_commit ("feat(user)!: new file" )
12821279 util .run_cli ("bump" , "--yes" )
12831280
@@ -1314,9 +1311,9 @@ def test_bump_allow_no_commit_with_manual_version(
13141311
13151312
13161313def test_bump_detect_legacy_tags_from_scm (
1317- tmp_commitizen_project : py . path . local , util : UtilFixture
1314+ tmp_commitizen_project : Path , util : UtilFixture
13181315):
1319- project_root = Path ( tmp_commitizen_project )
1316+ project_root = tmp_commitizen_project
13201317 tmp_commitizen_cfg_file = project_root / "pyproject.toml"
13211318 tmp_commitizen_cfg_file .write_text (
13221319 "\n " .join (
@@ -1340,11 +1337,11 @@ def test_bump_detect_legacy_tags_from_scm(
13401337
13411338
13421339def test_bump_warn_but_dont_fail_on_invalid_tags (
1343- tmp_commitizen_project : py . path . local ,
1340+ tmp_commitizen_project : Path ,
13441341 util : UtilFixture ,
13451342 capsys : pytest .CaptureFixture ,
13461343):
1347- project_root = Path ( tmp_commitizen_project )
1344+ project_root = tmp_commitizen_project
13481345 tmp_commitizen_cfg_file = project_root / "pyproject.toml"
13491346 tmp_commitizen_cfg_file .write_text (
13501347 "\n " .join (
0 commit comments