From 79ce43eaa37da2c9eb7365f515403d18f73e9f7d Mon Sep 17 00:00:00 2001 From: Yu-Ting Hsiung Date: Sun, 1 Feb 2026 19:56:01 +0800 Subject: [PATCH] test: rename fixture config to default_config to avoid name conflict --- tests/commands/conftest.py | 14 -- tests/commands/test_changelog_command.py | 21 +-- tests/commands/test_check_command.py | 117 ++++++++------- tests/commands/test_commit_command.py | 140 ++++++++++-------- tests/commands/test_common_command.py | 4 +- tests/commands/test_init_command.py | 96 +++++++----- tests/commands/test_version_command.py | 72 +++++---- tests/conftest.py | 18 +-- tests/providers/test_base_provider.py | 10 +- tests/providers/test_cargo_provider.py | 24 +-- tests/providers/test_commitizen_provider.py | 8 +- tests/providers/test_composer_provider.py | 6 +- tests/providers/test_npm_provider.py | 6 +- tests/providers/test_pep621_provider.py | 6 +- tests/providers/test_poetry_provider.py | 6 +- tests/providers/test_scm_provider.py | 30 ++-- tests/providers/test_uv_provider.py | 6 +- tests/test_changelog_format_asciidoc.py | 12 +- tests/test_changelog_format_markdown.py | 12 +- .../test_changelog_format_restructuredtext.py | 12 +- tests/test_changelog_format_textile.py | 12 +- tests/test_changelog_formats.py | 26 ++-- tests/test_cz_conventional_commits.py | 38 ++--- tests/test_cz_jira.py | 20 +-- tests/test_factory.py | 15 +- tests/test_version_schemes.py | 38 ++--- 26 files changed, 405 insertions(+), 364 deletions(-) diff --git a/tests/commands/conftest.py b/tests/commands/conftest.py index c7d5904504..b9c0455775 100644 --- a/tests/commands/conftest.py +++ b/tests/commands/conftest.py @@ -4,18 +4,9 @@ import pytest from pytest_mock import MockerFixture, MockType -from commitizen import defaults -from commitizen.config import BaseConfig from commitizen.config.json_config import JsonConfig -@pytest.fixture -def config() -> BaseConfig: - _config = BaseConfig() - _config.settings.update({"name": defaults.DEFAULT_SETTINGS["name"]}) - return _config - - @pytest.fixture def config_customize() -> JsonConfig: json_string = r"""{ @@ -50,11 +41,6 @@ def changelog_path() -> str: return os.path.join(os.getcwd(), "CHANGELOG.md") -@pytest.fixture -def config_path() -> str: - return os.path.join(os.getcwd(), "pyproject.toml") - - @pytest.fixture def success_mock(mocker: MockerFixture) -> MockType: return mocker.patch("commitizen.out.success") diff --git a/tests/commands/test_changelog_command.py b/tests/commands/test_changelog_command.py index dc97852144..0ee13fd1db 100644 --- a/tests/commands/test_changelog_command.py +++ b/tests/commands/test_changelog_command.py @@ -256,7 +256,7 @@ def test_changelog_incremental_keep_a_changelog_sample( @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.parametrize("dry_run", [True, False]) def test_changelog_hook( - mocker: MockFixture, config: BaseConfig, dry_run: bool, util: UtilFixture + mocker: MockFixture, default_config: BaseConfig, dry_run: bool, util: UtilFixture ): changelog_hook_mock = mocker.Mock() changelog_hook_mock.return_value = "cool changelog hook" @@ -265,9 +265,10 @@ def test_changelog_hook( util.create_file_and_commit("refactor: is in changelog") util.create_file_and_commit("Merge into master") - config.settings["change_type_order"] = ["Refactor", "Feat"] # type: ignore[typeddict-unknown-key] + default_config.settings["change_type_order"] = ["Refactor", "Feat"] # type: ignore[typeddict-unknown-key] changelog = Changelog( - config, {"unreleased_version": None, "incremental": True, "dry_run": dry_run} + default_config, + {"unreleased_version": None, "incremental": True, "dry_run": dry_run}, ) mocker.patch.object(changelog.cz, "changelog_hook", changelog_hook_mock) if dry_run: @@ -312,7 +313,7 @@ def test_changelog_hook_customize( @pytest.mark.usefixtures("tmp_commitizen_project") def test_changelog_release_hook( - mocker: MockFixture, config: BaseConfig, util: UtilFixture + mocker: MockFixture, default_config: BaseConfig, util: UtilFixture ): def changelog_release_hook(release: dict, tag: git.GitTag) -> dict: return release @@ -325,7 +326,8 @@ def changelog_release_hook(release: dict, tag: git.GitTag) -> dict: # changelog = Changelog(config, {}) changelog = Changelog( - config, {"unreleased_version": None, "incremental": True, "dry_run": False} + default_config, + {"unreleased_version": None, "incremental": True, "dry_run": False}, ) mocker.patch.object(changelog.cz, "changelog_release_hook", changelog_release_hook) spy = mocker.spy(changelog.cz, "changelog_release_hook") @@ -1196,7 +1198,7 @@ def test_changelog_prerelease_rev_with_use_scheme_semver( @pytest.mark.usefixtures("tmp_commitizen_project") def test_changelog_uses_version_tags_for_header( - mocker: MockFixture, config: BaseConfig, util: UtilFixture + mocker: MockFixture, default_config: BaseConfig, util: UtilFixture ): """Tests that changelog headers always use version tags even if there are non-version tags @@ -1211,7 +1213,8 @@ def test_changelog_uses_version_tags_for_header( write_patch = mocker.patch("commitizen.commands.changelog.out.write") changelog = Changelog( - config, {"dry_run": True, "incremental": True, "unreleased_version": None} + default_config, + {"dry_run": True, "incremental": True, "unreleased_version": None}, ) with pytest.raises(DryRunExit): @@ -1227,7 +1230,7 @@ def test_changelog_uses_version_tags_for_header( @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.freeze_time("2022-02-13") def test_changelog_from_current_version_tag_with_nonversion_tag( - mocker: MockFixture, config: BaseConfig, util: UtilFixture + mocker: MockFixture, default_config: BaseConfig, util: UtilFixture ): """Tests that changelog generation for a single version works even if there is a non-version tag in the list of tags @@ -1251,7 +1254,7 @@ def test_changelog_from_current_version_tag_with_nonversion_tag( with pytest.raises(DryRunExit): Changelog( - config, + default_config, { "dry_run": True, "incremental": False, diff --git a/tests/commands/test_check_command.py b/tests/commands/test_check_command.py index f225e912ea..b23551797a 100644 --- a/tests/commands/test_check_command.py +++ b/tests/commands/test_check_command.py @@ -123,12 +123,12 @@ def test_check_conventional_commit_succeeds( ), ), ) -def test_check_no_conventional_commit(commit_msg, config, tmpdir): +def test_check_no_conventional_commit(commit_msg, default_config, tmpdir): tempfile = tmpdir.join("temp_commit_file") tempfile.write(commit_msg) with pytest.raises(InvalidCommitMessageError): - commands.Check(config=config, arguments={"commit_msg_file": tempfile})() + commands.Check(config=default_config, arguments={"commit_msg_file": tempfile})() @pytest.mark.parametrize( @@ -140,44 +140,50 @@ def test_check_no_conventional_commit(commit_msg, config, tmpdir): "bump: 0.0.1 -> 1.0.0", ), ) -def test_check_conventional_commit(commit_msg, config, success_mock: MockType, tmpdir): +def test_check_conventional_commit( + commit_msg, default_config, success_mock: MockType, tmpdir +): tempfile = tmpdir.join("temp_commit_file") tempfile.write(commit_msg) - commands.Check(config=config, arguments={"commit_msg_file": tempfile})() + commands.Check(config=default_config, arguments={"commit_msg_file": tempfile})() success_mock.assert_called_once() -def test_check_command_when_commit_file_not_found(config): +def test_check_command_when_commit_file_not_found(default_config): with pytest.raises(FileNotFoundError): - commands.Check(config=config, arguments={"commit_msg_file": "no_such_file"})() + commands.Check( + config=default_config, arguments={"commit_msg_file": "no_such_file"} + )() def test_check_a_range_of_git_commits( - config, success_mock: MockType, mocker: MockFixture + default_config, success_mock: MockType, mocker: MockFixture ): mocker.patch( "commitizen.git.get_commits", return_value=_build_fake_git_commits(COMMIT_LOG) ) - commands.Check(config=config, arguments={"rev_range": "HEAD~10..master"})() + commands.Check(config=default_config, arguments={"rev_range": "HEAD~10..master"})() success_mock.assert_called_once() -def test_check_a_range_of_git_commits_and_failed(config, mocker: MockFixture): +def test_check_a_range_of_git_commits_and_failed(default_config, mocker: MockFixture): mocker.patch( "commitizen.git.get_commits", return_value=_build_fake_git_commits(["This commit does not follow rule"]), ) with pytest.raises(InvalidCommitMessageError) as excinfo: - commands.Check(config=config, arguments={"rev_range": "HEAD~10..master"})() + commands.Check( + config=default_config, arguments={"rev_range": "HEAD~10..master"} + )() assert "This commit does not follow rule" in str(excinfo.value) -def test_check_command_with_invalid_argument(config): +def test_check_command_with_invalid_argument(default_config): with pytest.raises(InvalidCommandArgumentError) as excinfo: commands.Check( - config=config, + config=default_config, arguments={"commit_msg_file": "some_file", "rev_range": "HEAD~10..master"}, ) assert ( @@ -187,15 +193,17 @@ def test_check_command_with_invalid_argument(config): @pytest.mark.usefixtures("tmp_commitizen_project") -def test_check_command_with_empty_range(config: BaseConfig, util: UtilFixture): +def test_check_command_with_empty_range(default_config: BaseConfig, util: UtilFixture): # must initialize git with a commit util.create_file_and_commit("feat: initial") with pytest.raises(NoCommitsFoundError) as excinfo: - commands.Check(config=config, arguments={"rev_range": "master..master"})() + commands.Check( + config=default_config, arguments={"rev_range": "master..master"} + )() assert "No commit found with range: 'master..master'" in str(excinfo) -def test_check_a_range_of_failed_git_commits(config, mocker: MockFixture): +def test_check_a_range_of_failed_git_commits(default_config, mocker: MockFixture): ill_formatted_commits_msgs = [ "First commit does not follow rule", "Second commit does not follow rule", @@ -207,59 +215,66 @@ def test_check_a_range_of_failed_git_commits(config, mocker: MockFixture): ) with pytest.raises(InvalidCommitMessageError) as excinfo: - commands.Check(config=config, arguments={"rev_range": "HEAD~10..master"})() + commands.Check( + config=default_config, arguments={"rev_range": "HEAD~10..master"} + )() assert all([msg in str(excinfo.value) for msg in ill_formatted_commits_msgs]) -def test_check_command_with_valid_message(config, success_mock: MockType): +def test_check_command_with_valid_message(default_config, success_mock: MockType): commands.Check( - config=config, arguments={"message": "fix(scope): some commit message"} + config=default_config, + arguments={"message": "fix(scope): some commit message"}, )() success_mock.assert_called_once() @pytest.mark.parametrize("message", ["bad commit", ""]) -def test_check_command_with_invalid_message(config, message): +def test_check_command_with_invalid_message(default_config, message): with pytest.raises(InvalidCommitMessageError): - commands.Check(config=config, arguments={"message": message})() + commands.Check(config=default_config, arguments={"message": message})() -def test_check_command_with_allow_abort_arg(config, success_mock): - commands.Check(config=config, arguments={"message": "", "allow_abort": True})() +def test_check_command_with_allow_abort_arg(default_config, success_mock): + commands.Check( + config=default_config, arguments={"message": "", "allow_abort": True} + )() success_mock.assert_called_once() -def test_check_command_with_allow_abort_config(config, success_mock): - config.settings["allow_abort"] = True - commands.Check(config=config, arguments={"message": ""})() +def test_check_command_with_allow_abort_config(default_config, success_mock): + default_config.settings["allow_abort"] = True + commands.Check(config=default_config, arguments={"message": ""})() success_mock.assert_called_once() -def test_check_command_override_allow_abort_config(config): - config.settings["allow_abort"] = True +def test_check_command_override_allow_abort_config(default_config): + default_config.settings["allow_abort"] = True with pytest.raises(InvalidCommitMessageError): - commands.Check(config=config, arguments={"message": "", "allow_abort": False})() + commands.Check( + config=default_config, arguments={"message": "", "allow_abort": False} + )() -def test_check_command_with_allowed_prefixes_arg(config, success_mock): +def test_check_command_with_allowed_prefixes_arg(default_config, success_mock): commands.Check( - config=config, + config=default_config, arguments={"message": "custom! test", "allowed_prefixes": ["custom!"]}, )() success_mock.assert_called_once() -def test_check_command_with_allowed_prefixes_config(config, success_mock): - config.settings["allowed_prefixes"] = ["custom!"] - commands.Check(config=config, arguments={"message": "custom! test"})() +def test_check_command_with_allowed_prefixes_config(default_config, success_mock): + default_config.settings["allowed_prefixes"] = ["custom!"] + commands.Check(config=default_config, arguments={"message": "custom! test"})() success_mock.assert_called_once() -def test_check_command_override_allowed_prefixes_config(config): - config.settings["allow_abort"] = ["fixup!"] +def test_check_command_override_allowed_prefixes_config(default_config): + default_config.settings["allow_abort"] = ["fixup!"] with pytest.raises(InvalidCommitMessageError): commands.Check( - config=config, + config=default_config, arguments={"message": "fixup! test", "allowed_prefixes": ["custom!"]}, )() @@ -336,58 +351,58 @@ def test_check_conventional_commit_succeed_with_git_diff( assert "Commit validation: successful!" in out -def test_check_command_with_message_length_limit(config, success_mock): +def test_check_command_with_message_length_limit(default_config, success_mock): message = "fix(scope): some commit message" commands.Check( - config=config, + config=default_config, arguments={"message": message, "message_length_limit": len(message) + 1}, )() success_mock.assert_called_once() -def test_check_command_with_message_length_limit_exceeded(config): +def test_check_command_with_message_length_limit_exceeded(default_config): message = "fix(scope): some commit message" with pytest.raises(CommitMessageLengthExceededError): commands.Check( - config=config, + config=default_config, arguments={"message": message, "message_length_limit": len(message) - 1}, )() -def test_check_command_with_amend_prefix_default(config, success_mock): - commands.Check(config=config, arguments={"message": "amend! test"})() +def test_check_command_with_amend_prefix_default(default_config, success_mock): + commands.Check(config=default_config, arguments={"message": "amend! test"})() success_mock.assert_called_once() -def test_check_command_with_config_message_length_limit(config, success_mock): +def test_check_command_with_config_message_length_limit(default_config, success_mock): message = "fix(scope): some commit message" - config.settings["message_length_limit"] = len(message) + 1 + default_config.settings["message_length_limit"] = len(message) + 1 commands.Check( - config=config, + config=default_config, arguments={"message": message}, )() success_mock.assert_called_once() -def test_check_command_with_config_message_length_limit_exceeded(config): +def test_check_command_with_config_message_length_limit_exceeded(default_config): message = "fix(scope): some commit message" - config.settings["message_length_limit"] = len(message) - 1 + default_config.settings["message_length_limit"] = len(message) - 1 with pytest.raises(CommitMessageLengthExceededError): commands.Check( - config=config, + config=default_config, arguments={"message": message}, )() def test_check_command_cli_overrides_config_message_length_limit( - config, success_mock: MockType + default_config, success_mock: MockType ): message = "fix(scope): some commit message" - config.settings["message_length_limit"] = len(message) - 1 + default_config.settings["message_length_limit"] = len(message) - 1 for message_length_limit in [len(message) + 1, 0]: success_mock.reset_mock() commands.Check( - config=config, + config=default_config, arguments={ "message": message, "message_length_limit": message_length_limit, diff --git a/tests/commands/test_commit_command.py b/tests/commands/test_commit_command.py index 89a9224b85..252fb85903 100644 --- a/tests/commands/test_commit_command.py +++ b/tests/commands/test_commit_command.py @@ -55,21 +55,21 @@ def backup_file(tmp_git_project): @pytest.mark.usefixtures("staging_is_clean", "commit_mock", "prompt_mock_feat") -def test_commit(config, success_mock: MockType): - commands.Commit(config, {})() +def test_commit(default_config, success_mock: MockType): + commands.Commit(default_config, {})() success_mock.assert_called_once() @pytest.mark.usefixtures("staging_is_clean") def test_commit_backup_on_failure( - config, mocker: MockFixture, prompt_mock_feat: MockType + default_config, mocker: MockFixture, prompt_mock_feat: MockType ): mocker.patch( "commitizen.git.commit", return_value=cmd.Command("", "error", b"", b"", 9) ) error_mock = mocker.patch("commitizen.out.error") - commit_cmd = commands.Commit(config, {}) + commit_cmd = commands.Commit(default_config, {}) temp_file = commit_cmd.backup_file_path with pytest.raises(CommitError): commit_cmd() @@ -80,20 +80,20 @@ def test_commit_backup_on_failure( @pytest.mark.usefixtures("staging_is_clean", "commit_mock") -def test_commit_retry_fails_no_backup(config): +def test_commit_retry_fails_no_backup(default_config): with pytest.raises(NoCommitBackupError) as excinfo: - commands.Commit(config, {"retry": True})() + commands.Commit(default_config, {"retry": True})() assert NoCommitBackupError.message in str(excinfo.value) @pytest.mark.usefixtures("staging_is_clean", "backup_file") def test_commit_retry_works( - config, success_mock: MockType, mocker: MockFixture, commit_mock: MockType + default_config, success_mock: MockType, mocker: MockFixture, commit_mock: MockType ): prompt_mock = mocker.patch("questionary.prompt") - commit_cmd = commands.Commit(config, {"retry": True}) + commit_cmd = commands.Commit(default_config, {"retry": True}) temp_file = commit_cmd.backup_file_path commit_cmd() @@ -105,10 +105,13 @@ def test_commit_retry_works( @pytest.mark.usefixtures("staging_is_clean") def test_commit_retry_after_failure_no_backup( - config, success_mock: MockType, commit_mock: MockType, prompt_mock_feat: MockType + default_config, + success_mock: MockType, + commit_mock: MockType, + prompt_mock_feat: MockType, ): - config.settings["retry_after_failure"] = True - commands.Commit(config, {})() + default_config.settings["retry_after_failure"] = True + commands.Commit(default_config, {})() commit_mock.assert_called_with("feat: user created\n\ncloses #21", args="") prompt_mock_feat.assert_called_once() @@ -117,12 +120,12 @@ def test_commit_retry_after_failure_no_backup( @pytest.mark.usefixtures("staging_is_clean", "backup_file") def test_commit_retry_after_failure_works( - config, success_mock: MockType, mocker: MockFixture, commit_mock: MockType + default_config, success_mock: MockType, mocker: MockFixture, commit_mock: MockType ): prompt_mock = mocker.patch("questionary.prompt") - config.settings["retry_after_failure"] = True - commit_cmd = commands.Commit(config, {}) + default_config.settings["retry_after_failure"] = True + commit_cmd = commands.Commit(default_config, {}) temp_file = commit_cmd.backup_file_path commit_cmd() @@ -134,10 +137,13 @@ def test_commit_retry_after_failure_works( @pytest.mark.usefixtures("staging_is_clean", "backup_file") def test_commit_retry_after_failure_with_no_retry_works( - config, success_mock: MockType, commit_mock: MockType, prompt_mock_feat: MockType + default_config, + success_mock: MockType, + commit_mock: MockType, + prompt_mock_feat: MockType, ): - config.settings["retry_after_failure"] = True - commit_cmd = commands.Commit(config, {"no_retry": True}) + default_config.settings["retry_after_failure"] = True + commit_cmd = commands.Commit(default_config, {"no_retry": True}) temp_file = commit_cmd.backup_file_path commit_cmd() @@ -148,33 +154,35 @@ def test_commit_retry_after_failure_with_no_retry_works( @pytest.mark.usefixtures("staging_is_clean", "prompt_mock_feat") -def test_commit_command_with_dry_run_option(config): +def test_commit_command_with_dry_run_option(default_config): with pytest.raises(DryRunExit): - commands.Commit(config, {"dry_run": True})() + commands.Commit(default_config, {"dry_run": True})() @pytest.mark.usefixtures("staging_is_clean", "commit_mock", "prompt_mock_feat") def test_commit_command_with_write_message_to_file_option( - config, tmp_path, success_mock: MockType + default_config, tmp_path, success_mock: MockType ): tmp_file = tmp_path / "message" - commands.Commit(config, {"write_message_to_file": tmp_file})() + commands.Commit(default_config, {"write_message_to_file": tmp_file})() success_mock.assert_called_once() assert tmp_file.exists() assert "feat: user created" in tmp_file.read_text() @pytest.mark.usefixtures("staging_is_clean", "prompt_mock_feat") -def test_commit_command_with_invalid_write_message_to_file_option(config, tmp_path): +def test_commit_command_with_invalid_write_message_to_file_option( + default_config, tmp_path +): with pytest.raises(NotAllowed): - commands.Commit(config, {"write_message_to_file": tmp_path})() + commands.Commit(default_config, {"write_message_to_file": tmp_path})() @pytest.mark.usefixtures("staging_is_clean", "prompt_mock_feat") def test_commit_command_with_signoff_option( - config, success_mock: MockType, commit_mock: MockType + default_config, success_mock: MockType, commit_mock: MockType ): - commands.Commit(config, {"signoff": True})() + commands.Commit(default_config, {"signoff": True})() commit_mock.assert_called_once_with(ANY, args="-s") success_mock.assert_called_once() @@ -182,10 +190,10 @@ def test_commit_command_with_signoff_option( @pytest.mark.usefixtures("staging_is_clean", "prompt_mock_feat") def test_commit_command_with_always_signoff_enabled( - config, success_mock: MockType, commit_mock: MockType + default_config, success_mock: MockType, commit_mock: MockType ): - config.settings["always_signoff"] = True - commands.Commit(config, {})() + default_config.settings["always_signoff"] = True + commands.Commit(default_config, {})() commit_mock.assert_called_once_with(ANY, args="-s") success_mock.assert_called_once() @@ -193,28 +201,30 @@ def test_commit_command_with_always_signoff_enabled( @pytest.mark.usefixtures("staging_is_clean", "prompt_mock_feat") def test_commit_command_with_gpgsign_and_always_signoff_enabled( - config, success_mock: MockType, commit_mock: MockType + default_config, success_mock: MockType, commit_mock: MockType ): - config.settings["always_signoff"] = True - commands.Commit(config, {"extra_cli_args": "-S"})() + default_config.settings["always_signoff"] = True + commands.Commit(default_config, {"extra_cli_args": "-S"})() commit_mock.assert_called_once_with(ANY, args="-S -s") success_mock.assert_called_once() @pytest.mark.usefixtures("tmp_git_project") -def test_commit_when_nothing_to_commit(config, mocker: MockFixture): +def test_commit_when_nothing_to_commit(default_config, mocker: MockFixture): mocker.patch("commitizen.git.is_staging_clean", return_value=True) with pytest.raises(NothingToCommitError) as excinfo: - commands.Commit(config, {})() + commands.Commit(default_config, {})() assert "No files added to staging!" in str(excinfo.value) @pytest.mark.usefixtures("staging_is_clean", "prompt_mock_feat") -def test_commit_with_allow_empty(config, success_mock: MockType, commit_mock: MockType): - commands.Commit(config, {"extra_cli_args": "--allow-empty"})() +def test_commit_with_allow_empty( + default_config, success_mock: MockType, commit_mock: MockType +): + commands.Commit(default_config, {"extra_cli_args": "--allow-empty"})() commit_mock.assert_called_with( "feat: user created\n\ncloses #21", args="--allow-empty" ) @@ -223,10 +233,10 @@ def test_commit_with_allow_empty(config, success_mock: MockType, commit_mock: Mo @pytest.mark.usefixtures("staging_is_clean", "prompt_mock_feat") def test_commit_with_signoff_and_allow_empty( - config, success_mock: MockType, commit_mock: MockType + default_config, success_mock: MockType, commit_mock: MockType ): - config.settings["always_signoff"] = True - commands.Commit(config, {"extra_cli_args": "--allow-empty"})() + default_config.settings["always_signoff"] = True + commands.Commit(default_config, {"extra_cli_args": "--allow-empty"})() commit_mock.assert_called_with( "feat: user created\n\ncloses #21", args="--allow-empty -s" @@ -235,59 +245,61 @@ def test_commit_with_signoff_and_allow_empty( @pytest.mark.usefixtures("staging_is_clean") -def test_commit_when_customized_expected_raised(config, mocker: MockFixture): +def test_commit_when_customized_expected_raised(default_config, mocker: MockFixture): _err = ValueError() _err.__context__ = CzException("This is the root custom err") mocker.patch("questionary.prompt", side_effect=_err) with pytest.raises(CustomError) as excinfo: - commands.Commit(config, {})() + commands.Commit(default_config, {})() # Assert only the content in the formatted text assert "This is the root custom err" in str(excinfo.value) @pytest.mark.usefixtures("staging_is_clean") -def test_commit_when_non_customized_expected_raised(config, mocker: MockFixture): +def test_commit_when_non_customized_expected_raised( + default_config, mocker: MockFixture +): mocker.patch("questionary.prompt", side_effect=ValueError()) with pytest.raises(ValueError): - commands.Commit(config, {})() + commands.Commit(default_config, {})() @pytest.mark.usefixtures("staging_is_clean") -def test_commit_when_no_user_answer(config, mocker: MockFixture): +def test_commit_when_no_user_answer(default_config, mocker: MockFixture): mocker.patch("questionary.prompt", return_value=None) with pytest.raises(NoAnswersError): - commands.Commit(config, {})() + commands.Commit(default_config, {})() -def test_commit_in_non_git_project(tmpdir, config): +def test_commit_in_non_git_project(tmpdir, default_config): with tmpdir.as_cwd(): with pytest.raises(NotAGitProjectError): - commands.Commit(config, {}) + commands.Commit(default_config, {}) @pytest.mark.usefixtures("staging_is_clean", "commit_mock", "prompt_mock_feat") def test_commit_command_with_all_option( - config, success_mock: MockType, mocker: MockFixture + default_config, success_mock: MockType, mocker: MockFixture ): add_mock = mocker.patch("commitizen.git.add") - commands.Commit(config, {"all": True})() + commands.Commit(default_config, {"all": True})() add_mock.assert_called() success_mock.assert_called_once() @pytest.mark.usefixtures("staging_is_clean", "prompt_mock_feat") def test_commit_command_with_extra_args( - config, success_mock: MockType, commit_mock: MockType + default_config, success_mock: MockType, commit_mock: MockType ): - commands.Commit(config, {"extra_cli_args": "-- -extra-args1 -extra-arg2"})() + commands.Commit(default_config, {"extra_cli_args": "-- -extra-args1 -extra-arg2"})() commit_mock.assert_called_once_with(ANY, args="-- -extra-args1 -extra-arg2") success_mock.assert_called_once() @pytest.mark.usefixtures("staging_is_clean") @pytest.mark.parametrize("editor", ["vim", None]) -def test_manual_edit(editor, config, mocker: MockFixture, tmp_path): +def test_manual_edit(editor, default_config, mocker: MockFixture, tmp_path): mocker.patch("commitizen.git.get_core_editor", return_value=editor) subprocess_mock = mocker.patch("subprocess.call") @@ -300,7 +312,7 @@ def test_manual_edit(editor, config, mocker: MockFixture, tmp_path): mock_temp_file = mocker.patch("tempfile.NamedTemporaryFile") mock_temp_file.return_value.__enter__.return_value.name = str(temp_file) - commit_cmd = commands.Commit(config, {"edit": True}) + commit_cmd = commands.Commit(default_config, {"edit": True}) if editor is None: with pytest.raises(RuntimeError): @@ -315,7 +327,7 @@ def test_manual_edit(editor, config, mocker: MockFixture, tmp_path): @pytest.mark.parametrize( "out", ["no changes added to commit", "nothing added to commit"] ) -def test_commit_when_nothing_added_to_commit(config, mocker: MockFixture, out): +def test_commit_when_nothing_added_to_commit(default_config, mocker: MockFixture, out): commit_mock = mocker.patch( "commitizen.git.commit", return_value=cmd.Command( @@ -328,7 +340,7 @@ def test_commit_when_nothing_added_to_commit(config, mocker: MockFixture, out): ) error_mock = mocker.patch("commitizen.out.error") - commands.Commit(config, {})() + commands.Commit(default_config, {})() commit_mock.assert_called_once() error_mock.assert_called_once_with(out) @@ -336,32 +348,32 @@ def test_commit_when_nothing_added_to_commit(config, mocker: MockFixture, out): @pytest.mark.usefixtures("staging_is_clean", "commit_mock") def test_commit_command_with_config_message_length_limit( - config, success_mock: MockType, prompt_mock_feat: MockType + default_config, success_mock: MockType, prompt_mock_feat: MockType ): prefix = prompt_mock_feat.return_value["prefix"] subject = prompt_mock_feat.return_value["subject"] message_length = len(f"{prefix}: {subject}") - commands.Commit(config, {"message_length_limit": message_length})() + commands.Commit(default_config, {"message_length_limit": message_length})() success_mock.assert_called_once() with pytest.raises(CommitMessageLengthExceededError): - commands.Commit(config, {"message_length_limit": message_length - 1})() + commands.Commit(default_config, {"message_length_limit": message_length - 1})() - config.settings["message_length_limit"] = message_length + default_config.settings["message_length_limit"] = message_length success_mock.reset_mock() - commands.Commit(config, {})() + commands.Commit(default_config, {})() success_mock.assert_called_once() - config.settings["message_length_limit"] = message_length - 1 + default_config.settings["message_length_limit"] = message_length - 1 with pytest.raises(CommitMessageLengthExceededError): - commands.Commit(config, {})() + commands.Commit(default_config, {})() - # Test config message length limit is overridden by CLI argument + # Test default_config message length limit is overridden by CLI argument success_mock.reset_mock() - commands.Commit(config, {"message_length_limit": message_length})() + commands.Commit(default_config, {"message_length_limit": message_length})() success_mock.assert_called_once() success_mock.reset_mock() - commands.Commit(config, {"message_length_limit": 0})() + commands.Commit(default_config, {"message_length_limit": 0})() success_mock.assert_called_once() diff --git a/tests/commands/test_common_command.py b/tests/commands/test_common_command.py index c70bc96e94..7e61126cc9 100644 --- a/tests/commands/test_common_command.py +++ b/tests/commands/test_common_command.py @@ -48,7 +48,7 @@ def test_command_shows_description_when_use_help_option( Schema, ], ) -def test_simple_command_call_once(config, mocker: MockFixture, command): +def test_simple_command_call_once(default_config, mocker: MockFixture, command): write_mock = mocker.patch("commitizen.out.write") - command(config)() + command(default_config)() write_mock.assert_called_once() diff --git a/tests/commands/test_init_command.py b/tests/commands/test_init_command.py index 0cf6377ead..aedb2e29fe 100644 --- a/tests/commands/test_init_command.py +++ b/tests/commands/test_init_command.py @@ -63,7 +63,7 @@ def unsafe_ask(self): def test_init_without_setup_pre_commit_hook( - tmpdir, mocker: MockFixture, config: BaseConfig + tmpdir, mocker: MockFixture, default_config: BaseConfig ): mocker.patch( "questionary.select", @@ -79,7 +79,7 @@ def test_init_without_setup_pre_commit_hook( # Return None to skip hook installation mocker.patch("questionary.checkbox", return_value=FakeQuestion(None)) with tmpdir.as_cwd(): - commands.Init(config)() + commands.Init(default_config)() with open("pyproject.toml", encoding="utf-8") as toml_file: config_data = toml_file.read() @@ -88,17 +88,19 @@ def test_init_without_setup_pre_commit_hook( assert not os.path.isfile(pre_commit_config_filename) -def test_init_when_config_already_exists(config: BaseConfig, capsys): +def test_init_when_config_already_exists(default_config: BaseConfig, capsys): # Set config path path = Path(os.sep.join(["tests", "pyproject.toml"])) - config.path = path + default_config.path = path - commands.Init(config)() + commands.Init(default_config)() captured = capsys.readouterr() assert captured.out == f"Config file {path} already exists\n" -def test_init_without_choosing_tag(config: BaseConfig, mocker: MockFixture, tmpdir): +def test_init_without_choosing_tag( + default_config: BaseConfig, mocker: MockFixture, tmpdir +): mocker.patch( "commitizen.commands.init.get_tag_names", return_value=["0.0.2", "0.0.1"] ) @@ -117,7 +119,7 @@ def test_init_without_choosing_tag(config: BaseConfig, mocker: MockFixture, tmpd with tmpdir.as_cwd(): with pytest.raises(NoAnswersError): - commands.Init(config)() + commands.Init(default_config)() @pytest.fixture @@ -180,26 +182,26 @@ def check_pre_commit_config(expected: list[dict[str, Any]]): @pytest.mark.usefixtures("pre_commit_installed") class TestPreCommitCases: def test_no_existing_pre_commit_config( - self, default_choice: str, tmpdir, config: BaseConfig + self, default_choice: str, tmpdir, default_config: BaseConfig ): with tmpdir.as_cwd(): - commands.Init(config)() + commands.Init(default_config)() check_cz_config(default_choice) check_pre_commit_config([cz_hook_config]) def test_empty_pre_commit_config( - self, default_choice: str, tmpdir, config: BaseConfig + self, default_choice: str, tmpdir, default_config: BaseConfig ): with tmpdir.as_cwd(): p = tmpdir.join(pre_commit_config_filename) p.write("") - commands.Init(config)() + commands.Init(default_config)() check_cz_config(default_choice) check_pre_commit_config([cz_hook_config]) def test_pre_commit_config_without_cz_hook( - self, default_choice: str, tmpdir, config: BaseConfig + self, default_choice: str, tmpdir, default_config: BaseConfig ): existing_hook_config = { "repo": "https://github.com/pre-commit/pre-commit-hooks", @@ -211,18 +213,18 @@ def test_pre_commit_config_without_cz_hook( p = tmpdir.join(pre_commit_config_filename) p.write(yaml.safe_dump({"repos": [existing_hook_config]})) - commands.Init(config)() + commands.Init(default_config)() check_cz_config(default_choice) check_pre_commit_config([existing_hook_config, cz_hook_config]) def test_cz_hook_exists_in_pre_commit_config( - self, default_choice: str, tmpdir, config: BaseConfig + self, default_choice: str, tmpdir, default_config: BaseConfig ): with tmpdir.as_cwd(): p = tmpdir.join(pre_commit_config_filename) p.write(yaml.safe_dump({"repos": [cz_hook_config]})) - commands.Init(config)() + commands.Init(default_config)() check_cz_config(default_choice) # check that config is not duplicated check_pre_commit_config([cz_hook_config]) @@ -231,7 +233,7 @@ def test_cz_hook_exists_in_pre_commit_config( class TestNoPreCommitInstalled: @pytest.mark.usefixtures("default_choice") def test_pre_commit_not_installed( - self, mocker: MockFixture, config: BaseConfig, tmpdir + self, mocker: MockFixture, default_config: BaseConfig, tmpdir ): # Assume `pre-commit` is not installed mocker.patch( @@ -240,34 +242,38 @@ def test_pre_commit_not_installed( ) with tmpdir.as_cwd(): with pytest.raises(InitFailedError): - commands.Init(config)() + commands.Init(default_config)() class TestAskTagFormat: - def test_confirm_v_tag_format(self, mocker: MockFixture, config: BaseConfig): - init = commands.Init(config) + def test_confirm_v_tag_format( + self, mocker: MockFixture, default_config: BaseConfig + ): + init = commands.Init(default_config) mocker.patch("questionary.confirm", return_value=FakeQuestion(True)) result = init._ask_tag_format("v1.0.0") assert result == r"v$version" - def test_reject_v_tag_format(self, mocker: MockFixture, config: BaseConfig): - init = commands.Init(config) + def test_reject_v_tag_format(self, mocker: MockFixture, default_config: BaseConfig): + init = commands.Init(default_config) mocker.patch("questionary.confirm", return_value=FakeQuestion(False)) mocker.patch("questionary.text", return_value=FakeQuestion("custom-$version")) result = init._ask_tag_format("v1.0.0") assert result == "custom-$version" - def test_non_v_tag_format(self, mocker: MockFixture, config: BaseConfig): - init = commands.Init(config) + def test_non_v_tag_format(self, mocker: MockFixture, default_config: BaseConfig): + init = commands.Init(default_config) mocker.patch("questionary.text", return_value=FakeQuestion("custom-$version")) result = init._ask_tag_format("1.0.0") assert result == "custom-$version" - def test_empty_input_returns_default(self, mocker: MockFixture, config: BaseConfig): - init = commands.Init(config) + def test_empty_input_returns_default( + self, mocker: MockFixture, default_config: BaseConfig + ): + init = commands.Init(default_config) mocker.patch("questionary.confirm", return_value=FakeQuestion(False)) mocker.patch("questionary.text", return_value=FakeQuestion("")) @@ -276,7 +282,7 @@ def test_empty_input_returns_default(self, mocker: MockFixture, config: BaseConf def test_init_with_confirmed_tag_format( - config: BaseConfig, mocker: MockFixture, tmpdir + default_config: BaseConfig, mocker: MockFixture, tmpdir ): mocker.patch( "commitizen.commands.init.get_tag_names", return_value=["v0.0.2", "v0.0.1"] @@ -296,12 +302,14 @@ def test_init_with_confirmed_tag_format( mocker.patch("questionary.checkbox", return_value=FakeQuestion(None)) with tmpdir.as_cwd(): - commands.Init(config)() + commands.Init(default_config)() with open("pyproject.toml", encoding="utf-8") as toml_file: assert 'tag_format = "v$version"' in toml_file.read() -def test_init_with_no_existing_tags(config: BaseConfig, mocker: MockFixture, tmpdir): +def test_init_with_no_existing_tags( + default_config: BaseConfig, mocker: MockFixture, tmpdir +): mocker.patch("commitizen.commands.init.get_tag_names", return_value=[]) mocker.patch("commitizen.commands.init.get_latest_tag_name", return_value="v1.0.0") mocker.patch( @@ -318,13 +326,13 @@ def test_init_with_no_existing_tags(config: BaseConfig, mocker: MockFixture, tmp mocker.patch("questionary.checkbox", return_value=FakeQuestion(None)) with tmpdir.as_cwd(): - commands.Init(config)() + commands.Init(default_config)() with open("pyproject.toml", encoding="utf-8") as toml_file: assert 'version = "0.0.1"' in toml_file.read() def test_init_with_no_existing_latest_tag( - config: BaseConfig, mocker: MockFixture, tmpdir + default_config: BaseConfig, mocker: MockFixture, tmpdir ): mocker.patch("commitizen.commands.init.get_latest_tag_name", return_value=None) mocker.patch( @@ -341,12 +349,14 @@ def test_init_with_no_existing_latest_tag( mocker.patch("questionary.checkbox", return_value=FakeQuestion(None)) with tmpdir.as_cwd(): - commands.Init(config)() + commands.Init(default_config)() with open("pyproject.toml", encoding="utf-8") as toml_file: assert 'version = "0.0.1"' in toml_file.read() -def test_init_with_existing_tags(config: BaseConfig, mocker: MockFixture, tmpdir): +def test_init_with_existing_tags( + default_config: BaseConfig, mocker: MockFixture, tmpdir +): expected_tags = ["v1.0.0", "v0.9.0", "v0.8.0"] mocker.patch("commitizen.commands.init.get_tag_names", return_value=expected_tags) mocker.patch("commitizen.commands.init.get_latest_tag_name", return_value="v1.0.0") @@ -365,12 +375,14 @@ def test_init_with_existing_tags(config: BaseConfig, mocker: MockFixture, tmpdir mocker.patch("questionary.checkbox", return_value=FakeQuestion(None)) with tmpdir.as_cwd(): - commands.Init(config)() + commands.Init(default_config)() with open("pyproject.toml", encoding="utf-8") as toml_file: assert 'version = "1.0.0"' in toml_file.read() -def test_init_with_valid_tag_selection(config: BaseConfig, mocker: MockFixture, tmpdir): +def test_init_with_valid_tag_selection( + default_config: BaseConfig, mocker: MockFixture, tmpdir +): expected_tags = ["v1.0.0", "v0.9.0", "v0.8.0"] mocker.patch("commitizen.commands.init.get_tag_names", return_value=expected_tags) mocker.patch("commitizen.commands.init.get_latest_tag_name", return_value="v1.0.0") @@ -394,14 +406,16 @@ def test_init_with_valid_tag_selection(config: BaseConfig, mocker: MockFixture, mocker.patch("questionary.checkbox", return_value=FakeQuestion(None)) with tmpdir.as_cwd(): - commands.Init(config)() + commands.Init(default_config)() with open("pyproject.toml", encoding="utf-8") as toml_file: content = toml_file.read() assert 'version = "0.9.0"' in content assert 'version_scheme = "semver"' in content -def test_init_configuration_settings(tmpdir, mocker: MockFixture, config: BaseConfig): +def test_init_configuration_settings( + tmpdir, mocker: MockFixture, default_config: BaseConfig +): """Test that all configuration settings are properly initialized.""" mocker.patch( "questionary.select", @@ -417,7 +431,7 @@ def test_init_configuration_settings(tmpdir, mocker: MockFixture, config: BaseCo mocker.patch("questionary.checkbox", return_value=FakeQuestion(None)) with tmpdir.as_cwd(): - commands.Init(config)() + commands.Init(default_config)() with open("pyproject.toml", encoding="utf-8") as toml_file: config_data = toml_file.read() @@ -432,7 +446,7 @@ def test_init_configuration_settings(tmpdir, mocker: MockFixture, config: BaseCo def test_init_configuration_with_version_provider( - tmpdir, mocker: MockFixture, config: BaseConfig + tmpdir, mocker: MockFixture, default_config: BaseConfig ): """Test configuration initialization with a different version provider.""" mocker.patch( @@ -449,7 +463,7 @@ def test_init_configuration_with_version_provider( mocker.patch("questionary.checkbox", return_value=FakeQuestion(None)) with tmpdir.as_cwd(): - commands.Init(config)() + commands.Init(default_config)() with open("pyproject.toml", encoding="utf-8") as toml_file: config_data = toml_file.read() @@ -467,10 +481,10 @@ def test_init_configuration_with_version_provider( def test_construct_name_choice_with_description( - config: BaseConfig, mocker: MockFixture + default_config: BaseConfig, mocker: MockFixture ): """Test the construction of cz name choices with descriptions.""" - init = commands.Init(config) + init = commands.Init(default_config) # mock the registry to have only one cz for testing mocker.patch.dict( "commitizen.cz.registry", diff --git a/tests/commands/test_version_command.py b/tests/commands/test_version_command.py index af22ba7ad2..6f7a22bd76 100644 --- a/tests/commands/test_version_command.py +++ b/tests/commands/test_version_command.py @@ -9,20 +9,20 @@ from commitizen.config.base_config import BaseConfig -def test_version_for_showing_project_version_error(config, capsys): - # No version specified in config +def test_version_for_showing_project_version_error(default_config: BaseConfig, capsys): + # No version specified in default_config commands.Version( - config, + default_config, {"project": True}, )() captured = capsys.readouterr() assert "No project information in this project." in captured.err -def test_version_for_showing_project_version(config, capsys): - config.settings["version"] = "v0.0.1" +def test_version_for_showing_project_version(default_config: BaseConfig, capsys): + default_config.settings["version"] = "v0.0.1" commands.Version( - config, + default_config, {"project": True}, )() captured = capsys.readouterr() @@ -30,18 +30,22 @@ def test_version_for_showing_project_version(config, capsys): @pytest.mark.parametrize("project", (True, False)) -def test_version_for_showing_commitizen_version(config, capsys, project: bool): +def test_version_for_showing_commitizen_version( + default_config: BaseConfig, capsys, project: bool +): commands.Version( - config, + default_config, {"project": project, "commitizen": True}, )() captured = capsys.readouterr() assert f"{__version__}" in captured.out -def test_version_for_showing_both_versions_no_project(config, capsys): +def test_version_for_showing_both_versions_no_project( + default_config: BaseConfig, capsys +): commands.Version( - config, + default_config, {"verbose": True}, )() captured = capsys.readouterr() @@ -49,10 +53,10 @@ def test_version_for_showing_both_versions_no_project(config, capsys): assert "No project information in this project." in captured.err -def test_version_for_showing_both_versions(config, capsys): - config.settings["version"] = "v0.0.1" +def test_version_for_showing_both_versions(default_config: BaseConfig, capsys): + default_config.settings["version"] = "v0.0.1" commands.Version( - config, + default_config, {"verbose": True}, )() captured = capsys.readouterr() @@ -62,9 +66,9 @@ def test_version_for_showing_both_versions(config, capsys): assert expected_out in captured.out -def test_version_for_showing_commitizen_system_info(config, capsys): +def test_version_for_showing_commitizen_system_info(default_config: BaseConfig, capsys): commands.Version( - config, + default_config, {"report": True}, )() captured = capsys.readouterr() @@ -77,7 +81,7 @@ def test_version_for_showing_commitizen_system_info(config, capsys): @pytest.mark.usefixtures("tmp_git_project") def test_version_use_version_provider( mocker: MockerFixture, - config: BaseConfig, + default_config: BaseConfig, capsys: pytest.CaptureFixture, project: bool, ): @@ -89,7 +93,7 @@ def test_version_use_version_provider( ) commands.Version( - config, + default_config, { "project": project, "verbose": not project, @@ -112,10 +116,12 @@ def test_version_use_version_provider( ("0.1.0", "0\n"), ], ) -def test_version_just_major(config, capsys, version: str, expected_version: str): - config.settings["version"] = version +def test_version_just_major( + default_config: BaseConfig, capsys, version: str, expected_version: str +): + default_config.settings["version"] = version commands.Version( - config, + default_config, { "project": True, "major": True, @@ -134,10 +140,12 @@ def test_version_just_major(config, capsys, version: str, expected_version: str) ("0.1.0", "1\n"), ], ) -def test_version_just_minor(config, capsys, version: str, expected_version: str): - config.settings["version"] = version +def test_version_just_minor( + default_config: BaseConfig, capsys, version: str, expected_version: str +): + default_config.settings["version"] = version commands.Version( - config, + default_config, { "project": True, "minor": True, @@ -148,9 +156,11 @@ def test_version_just_minor(config, capsys, version: str, expected_version: str) @pytest.mark.parametrize("argument", ("major", "minor")) -def test_version_just_major_error_no_project(config, capsys, argument: str): +def test_version_just_major_error_no_project( + default_config: BaseConfig, capsys, argument: str +): commands.Version( - config, + default_config, { argument: True, # type: ignore[misc] }, @@ -173,13 +183,13 @@ def test_version_just_major_error_no_project(config, capsys, argument: str): ], ) def test_version_with_tag_format( - config, capsys, version: str, tag_format: str, expected_output: str + default_config, capsys, version: str, tag_format: str, expected_output: str ): """Test --tag option applies tag_format to version""" - config.settings["version"] = version - config.settings["tag_format"] = tag_format + default_config.settings["version"] = version + default_config.settings["tag_format"] = tag_format commands.Version( - config, + default_config, { "project": True, "tag": True, @@ -189,10 +199,10 @@ def test_version_with_tag_format( assert captured.out == expected_output -def test_version_tag_without_project_error(config, capsys): +def test_version_tag_without_project_error(default_config: BaseConfig, capsys): """Test --tag requires --project or --verbose""" commands.Version( - config, + default_config, { "tag": True, }, diff --git a/tests/conftest.py b/tests/conftest.py index b1690ccab8..a95087e7d5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -159,7 +159,7 @@ def tmp_commitizen_project_with_gpg(tmp_commitizen_project): @pytest.fixture -def config(): +def default_config(): _config = BaseConfig() _config.settings.update({"name": defaults.DEFAULT_SETTINGS["name"]}) return _config @@ -278,8 +278,8 @@ def info(self) -> str: @pytest.fixture -def mock_plugin(mocker: MockerFixture, config: BaseConfig) -> BaseCommitizen: - mock = MockPlugin(config) +def mock_plugin(mocker: MockerFixture, default_config: BaseConfig) -> BaseCommitizen: + mock = MockPlugin(default_config) mocker.patch("commitizen.factory.committer_factory", return_value=mock) return mock @@ -289,23 +289,23 @@ def mock_plugin(mocker: MockerFixture, config: BaseConfig) -> BaseCommitizen: @pytest.fixture(params=SUPPORTED_FORMATS) def changelog_format( - config: BaseConfig, request: pytest.FixtureRequest + default_config: BaseConfig, request: pytest.FixtureRequest ) -> ChangelogFormat: """For tests relying on formats specifics""" format: str = request.param - config.settings["changelog_format"] = format + default_config.settings["changelog_format"] = format if "tmp_commitizen_project" in request.fixturenames: tmp_commitizen_project = request.getfixturevalue("tmp_commitizen_project") pyproject = tmp_commitizen_project / "pyproject.toml" pyproject.write(f'{pyproject.read()}\nchangelog_format = "{format}"\n') - return get_changelog_format(config) + return get_changelog_format(default_config) @pytest.fixture -def any_changelog_format(config: BaseConfig) -> ChangelogFormat: +def any_changelog_format(default_config: BaseConfig) -> ChangelogFormat: """For test not relying on formats specifics, use the default""" - config.settings["changelog_format"] = defaults.CHANGELOG_FORMAT - return get_changelog_format(config) + default_config.settings["changelog_format"] = defaults.CHANGELOG_FORMAT + return get_changelog_format(default_config) @pytest.fixture(params=[pytest.param(PYTHON_VERSION, id=f"py_{PYTHON_VERSION}")]) diff --git a/tests/providers/test_base_provider.py b/tests/providers/test_base_provider.py index 782a8ba89e..38df03a079 100644 --- a/tests/providers/test_base_provider.py +++ b/tests/providers/test_base_provider.py @@ -12,13 +12,13 @@ from commitizen.config.base_config import BaseConfig -def test_default_version_provider_is_commitizen_config(config: BaseConfig): - provider = get_provider(config) +def test_default_version_provider_is_commitizen_config(default_config: BaseConfig): + provider = get_provider(default_config) assert isinstance(provider, CommitizenProvider) -def test_raise_for_unknown_provider(config: BaseConfig): - config.settings["version_provider"] = "unknown" +def test_raise_for_unknown_provider(default_config: BaseConfig): + default_config.settings["version_provider"] = "unknown" with pytest.raises(VersionProviderUnknown): - get_provider(config) + get_provider(default_config) diff --git a/tests/providers/test_cargo_provider.py b/tests/providers/test_cargo_provider.py index ea15fdbf39..e26bc4c2ef 100644 --- a/tests/providers/test_cargo_provider.py +++ b/tests/providers/test_cargo_provider.py @@ -236,7 +236,7 @@ ), ) def test_cargo_provider( - config: BaseConfig, + default_config: BaseConfig, chdir: Path, content: str, expected: str, @@ -244,9 +244,9 @@ def test_cargo_provider( filename = CargoProvider.filename file = chdir / filename file.write_text(dedent(content)) - config.settings["version_provider"] = "cargo" + default_config.settings["version_provider"] = "cargo" - provider = get_provider(config) + provider = get_provider(default_config) assert isinstance(provider, CargoProvider) assert provider.get_version() == "0.1.0" @@ -272,7 +272,7 @@ def test_cargo_provider( ), ) def test_cargo_provider_with_lock( - config: BaseConfig, + default_config: BaseConfig, chdir: Path, toml_content: str, lock_content: str, @@ -295,9 +295,9 @@ def test_cargo_provider_with_lock( lock_filename = CargoProvider.lock_filename lock_file = chdir / lock_filename lock_file.write_text(dedent(lock_content)) - config.settings["version_provider"] = "cargo" + default_config.settings["version_provider"] = "cargo" - provider = get_provider(config) + provider = get_provider(default_config) assert isinstance(provider, CargoProvider) assert provider.get_version() == "0.1.0" @@ -307,7 +307,7 @@ def test_cargo_provider_with_lock( def test_cargo_provider_workspace_member_without_version_key( - config: BaseConfig, + default_config: BaseConfig, chdir: Path, ): """Test workspace member that has no version key at all (should not crash).""" @@ -365,9 +365,9 @@ def test_cargo_provider_workspace_member_without_version_key( lock_file = chdir / lock_filename lock_file.write_text(dedent(lock_content)) - config.settings["version_provider"] = "cargo" + default_config.settings["version_provider"] = "cargo" - provider = get_provider(config) + provider = get_provider(default_config) assert isinstance(provider, CargoProvider) assert provider.get_version() == "0.1.0" @@ -379,7 +379,7 @@ def test_cargo_provider_workspace_member_without_version_key( def test_cargo_provider_workspace_member_without_workspace_key( - config: BaseConfig, + default_config: BaseConfig, chdir: Path, ): """Test workspace member that has version key but no workspace subkey.""" @@ -440,9 +440,9 @@ def test_cargo_provider_workspace_member_without_workspace_key( lock_file = chdir / lock_filename lock_file.write_text(dedent(lock_content)) - config.settings["version_provider"] = "cargo" + default_config.settings["version_provider"] = "cargo" - provider = get_provider(config) + provider = get_provider(default_config) assert isinstance(provider, CargoProvider) assert provider.get_version() == "0.1.0" diff --git a/tests/providers/test_commitizen_provider.py b/tests/providers/test_commitizen_provider.py index c28dc90f79..ea24913bf9 100644 --- a/tests/providers/test_commitizen_provider.py +++ b/tests/providers/test_commitizen_provider.py @@ -10,11 +10,11 @@ from commitizen.config.base_config import BaseConfig -def test_commitizen_provider(config: BaseConfig, mocker: MockerFixture): - config.settings["version"] = "42" - mock = mocker.patch.object(config, "set_key") +def test_commitizen_provider(default_config: BaseConfig, mocker: MockerFixture): + default_config.settings["version"] = "42" + mock = mocker.patch.object(default_config, "set_key") - provider = CommitizenProvider(config) + provider = CommitizenProvider(default_config) assert provider.get_version() == "42" provider.set_version("43.1") diff --git a/tests/providers/test_composer_provider.py b/tests/providers/test_composer_provider.py index 22357b7a7f..9ab92c79a4 100644 --- a/tests/providers/test_composer_provider.py +++ b/tests/providers/test_composer_provider.py @@ -33,7 +33,7 @@ ((COMPOSER_JSON, COMPOSER_EXPECTED),), ) def test_composer_provider( - config: BaseConfig, + default_config: BaseConfig, chdir: Path, content: str, expected: str, @@ -41,9 +41,9 @@ def test_composer_provider( filename = ComposerProvider.filename file = chdir / filename file.write_text(dedent(content)) - config.settings["version_provider"] = "composer" + default_config.settings["version_provider"] = "composer" - provider = get_provider(config) + provider = get_provider(default_config) assert isinstance(provider, ComposerProvider) assert provider.get_version() == "0.1.0" diff --git a/tests/providers/test_npm_provider.py b/tests/providers/test_npm_provider.py index 785a2cb7fd..c15815ec02 100644 --- a/tests/providers/test_npm_provider.py +++ b/tests/providers/test_npm_provider.py @@ -73,7 +73,7 @@ ((NPM_LOCKFILE_JSON, NPM_LOCKFILE_EXPECTED), (None, None)), ) def test_npm_provider( - config: BaseConfig, + default_config: BaseConfig, chdir: Path, pkg_lock_content: str, pkg_lock_expected: str, @@ -88,9 +88,9 @@ def test_npm_provider( if pkg_shrinkwrap_content: pkg_shrinkwrap = chdir / NpmProvider.shrinkwrap_filename pkg_shrinkwrap.write_text(dedent(pkg_shrinkwrap_content)) - config.settings["version_provider"] = "npm" + default_config.settings["version_provider"] = "npm" - provider = get_provider(config) + provider = get_provider(default_config) assert isinstance(provider, NpmProvider) assert provider.get_version() == "0.1.0" diff --git a/tests/providers/test_pep621_provider.py b/tests/providers/test_pep621_provider.py index f44cef38c8..af65cb081f 100644 --- a/tests/providers/test_pep621_provider.py +++ b/tests/providers/test_pep621_provider.py @@ -29,7 +29,7 @@ ((PEP621_TOML, PEP621_EXPECTED),), ) def test_cargo_provider( - config: BaseConfig, + default_config: BaseConfig, chdir: Path, content: str, expected: str, @@ -37,9 +37,9 @@ def test_cargo_provider( filename = Pep621Provider.filename file = chdir / filename file.write_text(dedent(content)) - config.settings["version_provider"] = "pep621" + default_config.settings["version_provider"] = "pep621" - provider = get_provider(config) + provider = get_provider(default_config) assert isinstance(provider, Pep621Provider) assert provider.get_version() == "0.1.0" diff --git a/tests/providers/test_poetry_provider.py b/tests/providers/test_poetry_provider.py index ad998d41c7..fc36a53850 100644 --- a/tests/providers/test_poetry_provider.py +++ b/tests/providers/test_poetry_provider.py @@ -29,7 +29,7 @@ ((POETRY_TOML, POETRY_EXPECTED),), ) def test_cargo_provider( - config: BaseConfig, + default_config: BaseConfig, chdir: Path, content: str, expected: str, @@ -37,9 +37,9 @@ def test_cargo_provider( filename = PoetryProvider.filename file = chdir / filename file.write_text(dedent(content)) - config.settings["version_provider"] = "poetry" + default_config.settings["version_provider"] = "poetry" - provider = get_provider(config) + provider = get_provider(default_config) assert isinstance(provider, PoetryProvider) assert provider.get_version() == "0.1.0" diff --git a/tests/providers/test_scm_provider.py b/tests/providers/test_scm_provider.py index 1de4bf8fb9..55eaa11580 100644 --- a/tests/providers/test_scm_provider.py +++ b/tests/providers/test_scm_provider.py @@ -40,7 +40,7 @@ ) @pytest.mark.usefixtures("tmp_git_project") def test_scm_provider( - config: BaseConfig, + default_config: BaseConfig, tag_format: str, tag: str, expected_version: str, @@ -51,10 +51,10 @@ def test_scm_provider( util.create_file_and_commit("test: fake commit") util.create_tag("should-not-match") - config.settings["version_provider"] = "scm" - config.settings["tag_format"] = tag_format + default_config.settings["version_provider"] = "scm" + default_config.settings["tag_format"] = tag_format - provider = get_provider(config) + provider = get_provider(default_config) assert isinstance(provider, ScmProvider) actual_version = provider.get_version() assert actual_version == expected_version @@ -64,21 +64,21 @@ def test_scm_provider( @pytest.mark.usefixtures("tmp_git_project") -def test_scm_provider_default_without_commits_and_tags(config: BaseConfig): - config.settings["version_provider"] = "scm" +def test_scm_provider_default_without_commits_and_tags(default_config: BaseConfig): + default_config.settings["version_provider"] = "scm" - provider = get_provider(config) + provider = get_provider(default_config) assert isinstance(provider, ScmProvider) assert provider.get_version() == "0.0.0" @pytest.mark.usefixtures("tmp_git_project") def test_scm_provider_default_with_commits_and_tags( - config: BaseConfig, util: UtilFixture + default_config: BaseConfig, util: UtilFixture ): - config.settings["version_provider"] = "scm" + default_config.settings["version_provider"] = "scm" - provider = get_provider(config) + provider = get_provider(default_config) assert isinstance(provider, ScmProvider) assert provider.get_version() == "0.0.0" @@ -120,14 +120,14 @@ def test_scm_provider_default_with_commits_and_tags( @pytest.mark.usefixtures("tmp_git_project") -def test_scm_provider_detect_legacy_tags(config: BaseConfig, util: UtilFixture): - config.settings["version_provider"] = "scm" - config.settings["tag_format"] = "v${version}" - config.settings["legacy_tag_formats"] = [ +def test_scm_provider_detect_legacy_tags(default_config: BaseConfig, util: UtilFixture): + default_config.settings["version_provider"] = "scm" + default_config.settings["tag_format"] = "v${version}" + default_config.settings["legacy_tag_formats"] = [ "legacy-${version}", "old-${version}", ] - provider = get_provider(config) + provider = get_provider(default_config) util.create_file_and_commit("test: fake commit") util.create_tag("old-0.4.1") diff --git a/tests/providers/test_uv_provider.py b/tests/providers/test_uv_provider.py index 3dc55a91bd..0bceac0177 100644 --- a/tests/providers/test_uv_provider.py +++ b/tests/providers/test_uv_provider.py @@ -86,7 +86,7 @@ ], ) def test_uv_provider( - config: BaseConfig, + default_config: BaseConfig, tmpdir, file_regression: FileRegressionFixture, pyproject_content: str, @@ -98,9 +98,9 @@ def test_uv_provider( uv_lock_file = tmpdir / UvProvider.lock_filename uv_lock_file.write_text(UV_LOCK_SIMPLIFIED, encoding="utf-8") - config.settings["version_provider"] = "uv" + default_config.settings["version_provider"] = "uv" - provider = get_provider(config) + provider = get_provider(default_config) assert isinstance(provider, UvProvider) assert provider.get_version() == "4.2.1" diff --git a/tests/test_changelog_format_asciidoc.py b/tests/test_changelog_format_asciidoc.py index c64979ee16..c53f2503ff 100644 --- a/tests/test_changelog_format_asciidoc.py +++ b/tests/test_changelog_format_asciidoc.py @@ -103,15 +103,15 @@ @pytest.fixture -def format(config: BaseConfig) -> AsciiDoc: - return AsciiDoc(config) +def format(default_config: BaseConfig) -> AsciiDoc: + return AsciiDoc(default_config) @pytest.fixture -def format_with_tags(config: BaseConfig, request) -> AsciiDoc: - config.settings["tag_format"] = request.param - config.settings["legacy_tag_formats"] = ["legacy-${version}"] - return AsciiDoc(config) +def format_with_tags(default_config: BaseConfig, request) -> AsciiDoc: + default_config.settings["tag_format"] = request.param + default_config.settings["legacy_tag_formats"] = ["legacy-${version}"] + return AsciiDoc(default_config) VERSIONS_EXAMPLES = [ diff --git a/tests/test_changelog_format_markdown.py b/tests/test_changelog_format_markdown.py index e09d68cfed..43f59751db 100644 --- a/tests/test_changelog_format_markdown.py +++ b/tests/test_changelog_format_markdown.py @@ -103,15 +103,15 @@ @pytest.fixture -def format(config: BaseConfig) -> Markdown: - return Markdown(config) +def format(default_config: BaseConfig) -> Markdown: + return Markdown(default_config) @pytest.fixture -def format_with_tags(config: BaseConfig, request) -> Markdown: - config.settings["tag_format"] = request.param - config.settings["legacy_tag_formats"] = ["legacy-${version}"] - return Markdown(config) +def format_with_tags(default_config: BaseConfig, request) -> Markdown: + default_config.settings["tag_format"] = request.param + default_config.settings["legacy_tag_formats"] = ["legacy-${version}"] + return Markdown(default_config) VERSIONS_EXAMPLES = [ diff --git a/tests/test_changelog_format_restructuredtext.py b/tests/test_changelog_format_restructuredtext.py index e6eceff4fa..9ac27c8f97 100644 --- a/tests/test_changelog_format_restructuredtext.py +++ b/tests/test_changelog_format_restructuredtext.py @@ -305,15 +305,15 @@ def case( @pytest.fixture -def format(config: BaseConfig) -> RestructuredText: - return RestructuredText(config) +def format(default_config: BaseConfig) -> RestructuredText: + return RestructuredText(default_config) @pytest.fixture -def format_with_tags(config: BaseConfig, request) -> RestructuredText: - config.settings["tag_format"] = request.param - config.settings["legacy_tag_formats"] = ["legacy-${version}"] - return RestructuredText(config) +def format_with_tags(default_config: BaseConfig, request) -> RestructuredText: + default_config.settings["tag_format"] = request.param + default_config.settings["legacy_tag_formats"] = ["legacy-${version}"] + return RestructuredText(default_config) @pytest.mark.parametrize("content, expected", CASES) diff --git a/tests/test_changelog_format_textile.py b/tests/test_changelog_format_textile.py index 752cf229e5..6737901640 100644 --- a/tests/test_changelog_format_textile.py +++ b/tests/test_changelog_format_textile.py @@ -96,15 +96,15 @@ @pytest.fixture -def format(config: BaseConfig) -> Textile: - return Textile(config) +def format(default_config: BaseConfig) -> Textile: + return Textile(default_config) @pytest.fixture -def format_with_tags(config: BaseConfig, request) -> Textile: - config.settings["tag_format"] = request.param - config.settings["legacy_tag_formats"] = ["legacy-${version}"] - return Textile(config) +def format_with_tags(default_config: BaseConfig, request) -> Textile: + default_config.settings["tag_format"] = request.param + default_config.settings["legacy_tag_formats"] = ["legacy-${version}"] + return Textile(default_config) VERSIONS_EXAMPLES = [ diff --git a/tests/test_changelog_formats.py b/tests/test_changelog_formats.py index ff7126d345..b34cb39598 100644 --- a/tests/test_changelog_formats.py +++ b/tests/test_changelog_formats.py @@ -36,28 +36,32 @@ def test_guess_format_unknown(filename: str): for name, format in KNOWN_CHANGELOG_FORMATS.items() ], ) -def test_get_format(config: BaseConfig, name: str, expected: type[ChangelogFormat]): - config.settings["changelog_format"] = name - assert isinstance(get_changelog_format(config), expected) +def test_get_format( + default_config: BaseConfig, name: str, expected: type[ChangelogFormat] +): + default_config.settings["changelog_format"] = name + assert isinstance(get_changelog_format(default_config), expected) @pytest.mark.parametrize("filename", (None, "")) -def test_get_format_empty_filename(config: BaseConfig, filename: str | None): - config.settings["changelog_format"] = defaults.CHANGELOG_FORMAT +def test_get_format_empty_filename(default_config: BaseConfig, filename: str | None): + default_config.settings["changelog_format"] = defaults.CHANGELOG_FORMAT assert isinstance( - get_changelog_format(config, filename), + get_changelog_format(default_config, filename), KNOWN_CHANGELOG_FORMATS[defaults.CHANGELOG_FORMAT], ) @pytest.mark.parametrize("filename", (None, "")) -def test_get_format_empty_filename_no_setting(config: BaseConfig, filename: str | None): - config.settings["changelog_format"] = None +def test_get_format_empty_filename_no_setting( + default_config: BaseConfig, filename: str | None +): + default_config.settings["changelog_format"] = None with pytest.raises(ChangelogFormatUnknown): - get_changelog_format(config, filename) + get_changelog_format(default_config, filename) @pytest.mark.parametrize("filename", ("extensionless", "file.unknown")) -def test_get_format_unknown(config: BaseConfig, filename: str | None): +def test_get_format_unknown(default_config: BaseConfig, filename: str | None): with pytest.raises(ChangelogFormatUnknown): - get_changelog_format(config, filename) + get_changelog_format(default_config, filename) diff --git a/tests/test_cz_conventional_commits.py b/tests/test_cz_conventional_commits.py index 1742b0f3b7..0bf80b72fe 100644 --- a/tests/test_cz_conventional_commits.py +++ b/tests/test_cz_conventional_commits.py @@ -40,15 +40,15 @@ def test_subject_transformations(subject_transformation): assert transformed_subject == _parse_subject(invalid_subject) -def test_questions(config): - conventional_commits = ConventionalCommitsCz(config) +def test_questions(default_config): + conventional_commits = ConventionalCommitsCz(default_config) questions = conventional_commits.questions() assert isinstance(questions, list) assert isinstance(questions[0], dict) -def test_choices_all_have_keyboard_shortcuts(config): - conventional_commits = ConventionalCommitsCz(config) +def test_choices_all_have_keyboard_shortcuts(default_config): + conventional_commits = ConventionalCommitsCz(default_config) questions = conventional_commits.questions() list_questions = (q for q in questions if q["type"] == "list") @@ -56,8 +56,8 @@ def test_choices_all_have_keyboard_shortcuts(config): assert all("key" in choice for choice in select["choices"]) -def test_small_answer(config): - conventional_commits = ConventionalCommitsCz(config) +def test_small_answer(default_config): + conventional_commits = ConventionalCommitsCz(default_config) answers = { "prefix": "fix", "scope": "users", @@ -70,8 +70,8 @@ def test_small_answer(config): assert message == "fix(users): email pattern corrected" -def test_long_answer(config): - conventional_commits = ConventionalCommitsCz(config) +def test_long_answer(default_config): + conventional_commits = ConventionalCommitsCz(default_config) answers = { "prefix": "fix", "scope": "users", @@ -87,8 +87,8 @@ def test_long_answer(config): ) -def test_breaking_change_in_footer(config): - conventional_commits = ConventionalCommitsCz(config) +def test_breaking_change_in_footer(default_config): + conventional_commits = ConventionalCommitsCz(default_config) answers = { "prefix": "fix", "scope": "users", @@ -135,13 +135,13 @@ def test_breaking_change_in_footer(config): ], ) def test_breaking_change_message_formats( - config, scope, breaking_change_exclamation_in_title, expected_message + default_config, scope, breaking_change_exclamation_in_title, expected_message ): # Set the breaking_change_exclamation_in_title setting - config.settings["breaking_change_exclamation_in_title"] = ( + default_config.settings["breaking_change_exclamation_in_title"] = ( breaking_change_exclamation_in_title ) - conventional_commits = ConventionalCommitsCz(config) + conventional_commits = ConventionalCommitsCz(default_config) answers = { "prefix": "feat", "scope": scope, @@ -154,22 +154,22 @@ def test_breaking_change_message_formats( assert message == expected_message -def test_example(config): +def test_example(default_config): """just testing a string is returned. not the content""" - conventional_commits = ConventionalCommitsCz(config) + conventional_commits = ConventionalCommitsCz(default_config) example = conventional_commits.example() assert isinstance(example, str) -def test_schema(config): +def test_schema(default_config): """just testing a string is returned. not the content""" - conventional_commits = ConventionalCommitsCz(config) + conventional_commits = ConventionalCommitsCz(default_config) schema = conventional_commits.schema() assert isinstance(schema, str) -def test_info(config): +def test_info(default_config): """just testing a string is returned. not the content""" - conventional_commits = ConventionalCommitsCz(config) + conventional_commits = ConventionalCommitsCz(default_config) info = conventional_commits.info() assert isinstance(info, str) diff --git a/tests/test_cz_jira.py b/tests/test_cz_jira.py index 03055c14b1..2ae28361ab 100644 --- a/tests/test_cz_jira.py +++ b/tests/test_cz_jira.py @@ -1,15 +1,15 @@ from commitizen.cz.jira import JiraSmartCz -def test_questions(config): - cz = JiraSmartCz(config) +def test_questions(default_config): + cz = JiraSmartCz(default_config) questions = cz.questions() assert isinstance(questions, list) assert isinstance(questions[0], dict) -def test_answer(config): - cz = JiraSmartCz(config) +def test_answer(default_config): + cz = JiraSmartCz(default_config) answers = { "message": "new test", "issues": "JRA-34", @@ -21,18 +21,18 @@ def test_answer(config): assert message == "new test JRA-34" -def test_example(config): - cz = JiraSmartCz(config) +def test_example(default_config): + cz = JiraSmartCz(default_config) assert "JRA-34 #comment corrected indent issue\n" in cz.example() -def test_schema(config): - cz = JiraSmartCz(config) +def test_schema(default_config): + cz = JiraSmartCz(default_config) assert "" in cz.schema() -def test_info(config): - cz = JiraSmartCz(config) +def test_info(default_config): + cz = JiraSmartCz(default_config) assert ( "Smart Commits allow repository committers to perform " "actions such as transitioning JIRA Software" diff --git a/tests/test_factory.py b/tests/test_factory.py index 303ae4e728..e672281614 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -5,7 +5,6 @@ import pytest from commitizen import BaseCommitizen, defaults, factory -from commitizen.config import BaseConfig from commitizen.cz import discover_plugins from commitizen.cz.conventional_commits import ConventionalCommitsCz from commitizen.cz.customize import CustomizeCommitsCz @@ -21,18 +20,16 @@ class OtherPlugin: pass -def test_factory(): - config = BaseConfig() - config.settings.update({"name": defaults.DEFAULT_SETTINGS["name"]}) - r = factory.committer_factory(config) +def test_factory(default_config): + default_config.settings.update({"name": defaults.DEFAULT_SETTINGS["name"]}) + r = factory.committer_factory(default_config) assert isinstance(r, BaseCommitizen) -def test_factory_fails(): - config = BaseConfig() - config.settings.update({"name": "Nothing"}) +def test_factory_fails(default_config): + default_config.settings.update({"name": "Nothing"}) with pytest.raises(NoCommitizenFoundException) as excinfo: - factory.committer_factory(config) + factory.committer_factory(default_config) assert "The committer has not been found in the system." in str(excinfo) diff --git a/tests/test_version_schemes.py b/tests/test_version_schemes.py index 0f38f90d80..cbc076ae37 100644 --- a/tests/test_version_schemes.py +++ b/tests/test_version_schemes.py @@ -14,45 +14,45 @@ from commitizen.config.base_config import BaseConfig -def test_default_version_scheme_is_pep440(config: BaseConfig): - scheme = get_version_scheme(config.settings) +def test_default_version_scheme_is_pep440(default_config: BaseConfig): + scheme = get_version_scheme(default_config.settings) assert scheme is Pep440 -def test_version_scheme_from_config(config: BaseConfig): - config.settings["version_scheme"] = "semver" - scheme = get_version_scheme(config.settings) +def test_version_scheme_from_config(default_config: BaseConfig): + default_config.settings["version_scheme"] = "semver" + scheme = get_version_scheme(default_config.settings) assert scheme is SemVer -def test_version_scheme_from_name(config: BaseConfig): - config.settings["version_scheme"] = "pep440" - scheme = get_version_scheme(config.settings, "semver") +def test_version_scheme_from_name(default_config: BaseConfig): + default_config.settings["version_scheme"] = "pep440" + scheme = get_version_scheme(default_config.settings, "semver") assert scheme is SemVer -def test_raise_for_unknown_version_scheme(config: BaseConfig): +def test_raise_for_unknown_version_scheme(default_config: BaseConfig): with pytest.raises(VersionSchemeUnknown): - get_version_scheme(config.settings, "unknown") + get_version_scheme(default_config.settings, "unknown") -def test_version_scheme_from_deprecated_config(config: BaseConfig): - config.settings["version_type"] = "semver" +def test_version_scheme_from_deprecated_config(default_config: BaseConfig): + default_config.settings["version_type"] = "semver" with pytest.warns(DeprecationWarning, match="Please use `version_scheme` instead"): - scheme = get_version_scheme(config.settings) + scheme = get_version_scheme(default_config.settings) assert scheme is SemVer -def test_version_scheme_from_config_priority(config: BaseConfig): - config.settings["version_scheme"] = "pep440" - config.settings["version_type"] = "semver" +def test_version_scheme_from_config_priority(default_config: BaseConfig): + default_config.settings["version_scheme"] = "pep440" + default_config.settings["version_type"] = "semver" with pytest.warns(DeprecationWarning, match="Please use `version_scheme` instead"): - scheme = get_version_scheme(config.settings) + scheme = get_version_scheme(default_config.settings) assert scheme is Pep440 def test_warn_if_version_protocol_not_implemented( - config: BaseConfig, mocker: MockerFixture + default_config: BaseConfig, mocker: MockerFixture ): class NotVersionProtocol: pass @@ -62,7 +62,7 @@ class NotVersionProtocol: mocker.patch.object(metadata, "entry_points", return_value=(ep,)) with pytest.warns() as warnings: - get_version_scheme(config.settings, "any") + get_version_scheme(default_config.settings, "any") assert "Version scheme any does not implement the VersionProtocol" in str( warnings[0].message )