From aae022653375dc7ba474d35a7f1542e6c32c513a Mon Sep 17 00:00:00 2001 From: Yu-Ting Hsiung Date: Sun, 1 Feb 2026 20:46:53 +0800 Subject: [PATCH 1/3] test: enable ruff rule PT006 and PT007 It turns out that I just had to run uv run ruff check --fix --unsafe-fixes --- pyproject.toml | 2 - tests/commands/test_bump_command.py | 40 +++++++++---------- tests/commands/test_changelog_command.py | 22 +++++----- tests/commands/test_check_command.py | 8 ++-- tests/commands/test_version_command.py | 12 +++--- tests/providers/test_cargo_provider.py | 12 +++--- tests/providers/test_composer_provider.py | 4 +- tests/providers/test_npm_provider.py | 8 ++-- tests/providers/test_pep621_provider.py | 4 +- tests/providers/test_poetry_provider.py | 4 +- tests/providers/test_scm_provider.py | 6 +-- tests/test_bump_create_commit_message.py | 12 +++--- tests/test_bump_find_increment.py | 12 +++--- tests/test_bump_normalize_tag.py | 2 +- tests/test_bump_update_version_in_files.py | 2 +- tests/test_changelog.py | 8 ++-- tests/test_changelog_format_asciidoc.py | 16 ++++---- tests/test_changelog_format_markdown.py | 16 ++++---- .../test_changelog_format_restructuredtext.py | 12 +++--- tests/test_changelog_format_textile.py | 16 ++++---- tests/test_changelog_formats.py | 10 ++--- tests/test_cli.py | 2 +- tests/test_conf.py | 6 +-- tests/test_cz_conventional_commits.py | 2 +- tests/test_git.py | 4 +- tests/test_project_info.py | 8 ++-- tests/test_version_scheme_pep440.py | 6 +-- tests/test_version_scheme_semver.py | 6 +-- tests/test_version_scheme_semver2.py | 4 +- 29 files changed, 132 insertions(+), 134 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ad639ba9bd..afe25bcb7b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -239,8 +239,6 @@ ignore = [ "E501", "D1", "D415", - "PT006", # TODO(bearomorphism): enable this rule - "PT007", # TODO(bearomorphism): enable this rule "PT011", # TODO(bearomorphism): enable this rule "PT022", # TODO(bearomorphism): enable this rule ] diff --git a/tests/commands/test_bump_command.py b/tests/commands/test_bump_command.py index d458e34d8e..44821120d2 100644 --- a/tests/commands/test_bump_command.py +++ b/tests/commands/test_bump_command.py @@ -40,14 +40,14 @@ @pytest.mark.parametrize( "commit_msg", - ( + [ "fix: username exception", "fix(user): username exception", "refactor: remove ini configuration support", "refactor(config): remove ini configuration support", "perf: update to use multiprocess", "perf(worker): update to use multiprocess", - ), + ], ) @pytest.mark.usefixtures("tmp_commitizen_project") def test_bump_patch_increment(commit_msg: str, util: UtilFixture): @@ -56,7 +56,7 @@ def test_bump_patch_increment(commit_msg: str, util: UtilFixture): assert git.tag_exist("0.1.1") is True -@pytest.mark.parametrize("commit_msg", ("feat: new file", "feat(user): new file")) +@pytest.mark.parametrize("commit_msg", ["feat: new file", "feat(user): new file"]) @pytest.mark.usefixtures("tmp_commitizen_project") def test_bump_minor_increment(commit_msg: str, util: UtilFixture): util.create_file_and_commit(commit_msg) @@ -68,7 +68,7 @@ def test_bump_minor_increment(commit_msg: str, util: UtilFixture): ) -@pytest.mark.parametrize("commit_msg", ("feat: new file", "feat(user): new file")) +@pytest.mark.parametrize("commit_msg", ["feat: new file", "feat(user): new file"]) @pytest.mark.usefixtures("tmp_commitizen_project") def test_bump_minor_increment_annotated(commit_msg: str, util: UtilFixture): util.create_file_and_commit(commit_msg) @@ -82,7 +82,7 @@ def test_bump_minor_increment_annotated(commit_msg: str, util: UtilFixture): assert git.is_signed_tag("0.2.0") is False -@pytest.mark.parametrize("commit_msg", ("feat: new file", "feat(user): new file")) +@pytest.mark.parametrize("commit_msg", ["feat: new file", "feat(user): new file"]) @pytest.mark.usefixtures("tmp_commitizen_project_with_gpg") def test_bump_minor_increment_signed(commit_msg: str, util: UtilFixture): util.create_file_and_commit(commit_msg) @@ -96,7 +96,7 @@ def test_bump_minor_increment_signed(commit_msg: str, util: UtilFixture): assert git.is_signed_tag("0.2.0") is True -@pytest.mark.parametrize("commit_msg", ("feat: new file", "feat(user): new file")) +@pytest.mark.parametrize("commit_msg", ["feat: new file", "feat(user): new file"]) def test_bump_minor_increment_annotated_config_file( commit_msg: str, util: UtilFixture, pyproject: Path ): @@ -112,7 +112,7 @@ def test_bump_minor_increment_annotated_config_file( assert git.is_signed_tag("0.2.0") is False -@pytest.mark.parametrize("commit_msg", ("feat: new file", "feat(user): new file")) +@pytest.mark.parametrize("commit_msg", ["feat: new file", "feat(user): new file"]) def test_bump_minor_increment_signed_config_file( commit_msg: str, util: UtilFixture, tmp_commitizen_project_with_gpg ): @@ -132,7 +132,7 @@ def test_bump_minor_increment_signed_config_file( @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.parametrize( "commit_msg", - ( + [ "feat: new user interface\n\nBREAKING CHANGE: age is no longer supported", "feat!: new user interface\n\nBREAKING CHANGE: age is no longer supported", "feat!: new user interface", @@ -141,7 +141,7 @@ def test_bump_minor_increment_signed_config_file( "feat(user)!: new user interface", "BREAKING CHANGE: age is no longer supported", "BREAKING-CHANGE: age is no longer supported", - ), + ], ) def test_bump_major_increment(commit_msg: str, util: UtilFixture): util.create_file_and_commit(commit_msg) @@ -152,7 +152,7 @@ def test_bump_major_increment(commit_msg: str, util: UtilFixture): @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.parametrize( "commit_msg", - ( + [ "feat: new user interface\n\nBREAKING CHANGE: age is no longer supported", "feat!: new user interface\n\nBREAKING CHANGE: age is no longer supported", "feat!: new user interface", @@ -161,7 +161,7 @@ def test_bump_major_increment(commit_msg: str, util: UtilFixture): "feat(user)!: new user interface", "BREAKING CHANGE: age is no longer supported", "BREAKING-CHANGE: age is no longer supported", - ), + ], ) def test_bump_major_increment_major_version_zero(commit_msg: str, util: UtilFixture): util.create_file_and_commit(commit_msg) @@ -171,7 +171,7 @@ def test_bump_major_increment_major_version_zero(commit_msg: str, util: UtilFixt @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.parametrize( - "commit_msg,increment,expected_tag", + ("commit_msg", "increment", "expected_tag"), [ ("feat: new file", "PATCH", "0.1.1"), ("fix: username exception", "major", "1.0.0"), @@ -607,7 +607,7 @@ def test_bump_with_git_to_stdout_arg(util: UtilFixture, capsys: pytest.CaptureFi @pytest.mark.parametrize( - "version_filepath, version_regex, version_file_content", + ("version_filepath", "version_regex", "version_file_content"), [ pytest.param( "pyproject.toml", @@ -779,7 +779,7 @@ def test_bump_manual_version_disallows_major_version_zero(util: UtilFixture): @pytest.mark.parametrize( - "initial_version, expected_version_after_bump", + ("initial_version", "expected_version_after_bump"), [ ("1", "1.1.0"), ("1.2", "1.3.0"), @@ -805,7 +805,7 @@ def test_bump_version_with_less_components_in_config( assert expected_version_after_bump in f.read() -@pytest.mark.parametrize("commit_msg", ("feat: new file", "feat(user): new file")) +@pytest.mark.parametrize("commit_msg", ["feat: new file", "feat(user): new file"]) def test_bump_with_pre_bump_hooks( commit_msg, mocker: MockFixture, tmp_commitizen_project, util: UtilFixture ): @@ -993,7 +993,7 @@ def test_bump_command_prerelease_scheme_check_old_tags( @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.usefixtures("use_cz_semver") @pytest.mark.parametrize( - "message, expected_tag", + ("message", "expected_tag"), [ ("minor: add users", "0.2.0"), ("patch: bug affecting users", "0.1.1"), @@ -1009,7 +1009,7 @@ def test_bump_with_plugin(util: UtilFixture, message: str, expected_tag: str): @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.usefixtures("use_cz_semver") @pytest.mark.parametrize( - "message, expected_tag", + ("message", "expected_tag"), [ ("minor: add users", "0.2.0"), ("patch: bug affecting users", "0.1.1"), @@ -1061,14 +1061,14 @@ def test_bump_command_version_scheme_priority_over_version_type(util: UtilFixtur @pytest.mark.parametrize( - "arg, cfg, expected", - ( + ("arg", "cfg", "expected"), + [ pytest.param("", "", "default", id="default"), pytest.param("", "changelog.cfg", "from config", id="from-config"), pytest.param( "--template=changelog.cmd", "changelog.cfg", "from cmd", id="from-command" ), - ), + ], ) def test_bump_template_option_precedence( tmp_commitizen_project: Path, diff --git a/tests/commands/test_changelog_command.py b/tests/commands/test_changelog_command.py index dc97852144..e747c6b00e 100644 --- a/tests/commands/test_changelog_command.py +++ b/tests/commands/test_changelog_command.py @@ -692,7 +692,7 @@ def test_changelog_incremental_with_release_candidate_version( @pytest.mark.parametrize( - "from_pre,to_pre", itertools.product(["alpha", "beta", "rc"], repeat=2) + ("from_pre", "to_pre"), itertools.product(["alpha", "beta", "rc"], repeat=2) ) @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.freeze_time("2021-06-11") @@ -856,13 +856,13 @@ def test_changelog_from_rev_latest_version_from_arg( @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.parametrize( - "rev_range,tag", - ( + ("rev_range", "tag"), + [ pytest.param("0.8.0", "0.2.0", id="single-not-found"), pytest.param("0.1.0..0.3.0", "0.3.0", id="lower-bound-not-found"), pytest.param("0.1.0..0.3.0", "0.1.0", id="upper-bound-not-found"), pytest.param("0.3.0..0.4.0", "0.2.0", id="none-found"), - ), + ], ) def test_changelog_from_rev_range_not_found( config_path: str, rev_range: str, tag: str, util: UtilFixture @@ -1270,14 +1270,14 @@ def test_changelog_from_current_version_tag_with_nonversion_tag( @pytest.mark.parametrize( - "arg,cfg,expected", - ( + ("arg", "cfg", "expected"), + [ pytest.param("", "", "default", id="default"), pytest.param("", "changelog.cfg", "from config", id="from-config"), pytest.param( "--template=changelog.cmd", "changelog.cfg", "from cmd", id="from-command" ), - ), + ], ) def test_changelog_template_option_precedence( tmp_commitizen_project: Path, @@ -1588,12 +1588,12 @@ def test_changelog_template_extra_quotes( @pytest.mark.parametrize( - "extra, expected", - ( + ("extra", "expected"), + [ pytest.param("key=value=", "value=", id="2-equals"), pytest.param("key==value", "=value", id="2-consecutive-equals"), pytest.param("key==value==", "=value==", id="multiple-equals"), - ), + ], ) def test_changelog_template_extra_weird_but_valid( changelog_tpl: Path, @@ -1609,7 +1609,7 @@ def test_changelog_template_extra_weird_but_valid( assert changelog_file.read_text() == expected -@pytest.mark.parametrize("extra", ("no-equal", "", "=no-key")) +@pytest.mark.parametrize("extra", ["no-equal", "", "=no-key"]) def test_changelog_template_extra_bad_format( changelog_tpl: Path, extra: str, diff --git a/tests/commands/test_check_command.py b/tests/commands/test_check_command.py index f225e912ea..20f0bf87eb 100644 --- a/tests/commands/test_check_command.py +++ b/tests/commands/test_check_command.py @@ -113,7 +113,7 @@ def test_check_conventional_commit_succeeds( @pytest.mark.parametrize( "commit_msg", - ( + [ "feat!(lang): removed polish language", "no conventional commit", ( @@ -121,7 +121,7 @@ def test_check_conventional_commit_succeeds( "testing with more complex commit mes\n\n" "age with error" ), - ), + ], ) def test_check_no_conventional_commit(commit_msg, config, tmpdir): tempfile = tmpdir.join("temp_commit_file") @@ -133,12 +133,12 @@ def test_check_no_conventional_commit(commit_msg, config, tmpdir): @pytest.mark.parametrize( "commit_msg", - ( + [ "feat(lang)!: removed polish language", "feat(lang): added polish language", "feat: add polish language", "bump: 0.0.1 -> 1.0.0", - ), + ], ) def test_check_conventional_commit(commit_msg, config, success_mock: MockType, tmpdir): tempfile = tmpdir.join("temp_commit_file") diff --git a/tests/commands/test_version_command.py b/tests/commands/test_version_command.py index af22ba7ad2..dce710ac84 100644 --- a/tests/commands/test_version_command.py +++ b/tests/commands/test_version_command.py @@ -29,7 +29,7 @@ def test_version_for_showing_project_version(config, capsys): assert "v0.0.1" in captured.out -@pytest.mark.parametrize("project", (True, False)) +@pytest.mark.parametrize("project", [True, False]) def test_version_for_showing_commitizen_version(config, capsys, project: bool): commands.Version( config, @@ -73,7 +73,7 @@ def test_version_for_showing_commitizen_system_info(config, capsys): assert f"Operating System: {platform.system()}" in captured.out -@pytest.mark.parametrize("project", (True, False)) +@pytest.mark.parametrize("project", [True, False]) @pytest.mark.usefixtures("tmp_git_project") def test_version_use_version_provider( mocker: MockerFixture, @@ -104,7 +104,7 @@ def test_version_use_version_provider( @pytest.mark.parametrize( - "version, expected_version", + ("version", "expected_version"), [ ("1.0.0", "1\n"), ("2.1.3", "2\n"), @@ -126,7 +126,7 @@ def test_version_just_major(config, capsys, version: str, expected_version: str) @pytest.mark.parametrize( - "version, expected_version", + ("version", "expected_version"), [ ("1.0.0", "0\n"), ("2.1.3", "1\n"), @@ -147,7 +147,7 @@ def test_version_just_minor(config, capsys, version: str, expected_version: str) assert expected_version == captured.out -@pytest.mark.parametrize("argument", ("major", "minor")) +@pytest.mark.parametrize("argument", ["major", "minor"]) def test_version_just_major_error_no_project(config, capsys, argument: str): commands.Version( config, @@ -164,7 +164,7 @@ def test_version_just_major_error_no_project(config, capsys, argument: str): @pytest.mark.parametrize( - "version, tag_format, expected_output", + ("version", "tag_format", "expected_output"), [ ("1.2.3", "v$version", "v1.2.3\n"), ("1.2.3", "$version", "1.2.3\n"), diff --git a/tests/providers/test_cargo_provider.py b/tests/providers/test_cargo_provider.py index ea15fdbf39..63f143b291 100644 --- a/tests/providers/test_cargo_provider.py +++ b/tests/providers/test_cargo_provider.py @@ -229,11 +229,11 @@ @pytest.mark.parametrize( - "content, expected", - ( + ("content", "expected"), + [ (CARGO_TOML, CARGO_TOML_EXPECTED), (CARGO_WORKSPACE_TOML, CARGO_WORKSPACE_TOML_EXPECTED), - ), + ], ) def test_cargo_provider( config: BaseConfig, @@ -255,8 +255,8 @@ def test_cargo_provider( @pytest.mark.parametrize( - "toml_content, lock_content, toml_expected, lock_expected", - ( + ("toml_content", "lock_content", "toml_expected", "lock_expected"), + [ ( CARGO_TOML, CARGO_LOCK, @@ -269,7 +269,7 @@ def test_cargo_provider( CARGO_WORKSPACE_TOML_EXPECTED, CARGO_WORKSPACE_LOCK_EXPECTED, ), - ), + ], ) def test_cargo_provider_with_lock( config: BaseConfig, diff --git a/tests/providers/test_composer_provider.py b/tests/providers/test_composer_provider.py index 22357b7a7f..b3068a6fd6 100644 --- a/tests/providers/test_composer_provider.py +++ b/tests/providers/test_composer_provider.py @@ -29,8 +29,8 @@ @pytest.mark.parametrize( - "content, expected", - ((COMPOSER_JSON, COMPOSER_EXPECTED),), + ("content", "expected"), + [(COMPOSER_JSON, COMPOSER_EXPECTED)], ) def test_composer_provider( config: BaseConfig, diff --git a/tests/providers/test_npm_provider.py b/tests/providers/test_npm_provider.py index 785a2cb7fd..4de171a927 100644 --- a/tests/providers/test_npm_provider.py +++ b/tests/providers/test_npm_provider.py @@ -65,12 +65,12 @@ @pytest.mark.parametrize( - "pkg_shrinkwrap_content, pkg_shrinkwrap_expected", - ((NPM_LOCKFILE_JSON, NPM_LOCKFILE_EXPECTED), (None, None)), + ("pkg_shrinkwrap_content", "pkg_shrinkwrap_expected"), + [(NPM_LOCKFILE_JSON, NPM_LOCKFILE_EXPECTED), (None, None)], ) @pytest.mark.parametrize( - "pkg_lock_content, pkg_lock_expected", - ((NPM_LOCKFILE_JSON, NPM_LOCKFILE_EXPECTED), (None, None)), + ("pkg_lock_content", "pkg_lock_expected"), + [(NPM_LOCKFILE_JSON, NPM_LOCKFILE_EXPECTED), (None, None)], ) def test_npm_provider( config: BaseConfig, diff --git a/tests/providers/test_pep621_provider.py b/tests/providers/test_pep621_provider.py index f44cef38c8..e0ae0ba949 100644 --- a/tests/providers/test_pep621_provider.py +++ b/tests/providers/test_pep621_provider.py @@ -25,8 +25,8 @@ @pytest.mark.parametrize( - "content, expected", - ((PEP621_TOML, PEP621_EXPECTED),), + ("content", "expected"), + [(PEP621_TOML, PEP621_EXPECTED)], ) def test_cargo_provider( config: BaseConfig, diff --git a/tests/providers/test_poetry_provider.py b/tests/providers/test_poetry_provider.py index ad998d41c7..2a7841b8a1 100644 --- a/tests/providers/test_poetry_provider.py +++ b/tests/providers/test_poetry_provider.py @@ -25,8 +25,8 @@ @pytest.mark.parametrize( - "content, expected", - ((POETRY_TOML, POETRY_EXPECTED),), + ("content", "expected"), + [(POETRY_TOML, POETRY_EXPECTED)], ) def test_cargo_provider( config: BaseConfig, diff --git a/tests/providers/test_scm_provider.py b/tests/providers/test_scm_provider.py index 1de4bf8fb9..d3f0299f47 100644 --- a/tests/providers/test_scm_provider.py +++ b/tests/providers/test_scm_provider.py @@ -13,8 +13,8 @@ @pytest.mark.parametrize( - "tag_format,tag,expected_version", - ( + ("tag_format", "tag", "expected_version"), + [ # If tag_format is $version (the default), version_scheme.parser is used. # Its DEFAULT_VERSION_PARSER allows a v prefix, but matches PEP440 otherwise. ("$version", "no-match-because-version-scheme-is-strict", "0.0.0"), @@ -36,7 +36,7 @@ ("v$major.$minor.$patch$prerelease$devrelease", "v0.1.0", "0.1.0"), ("v$major.$minor.$patch$prerelease$devrelease", "v0.1.0rc1", "0.1.0rc1"), ("v$major.$minor.$patch$prerelease$devrelease", "v1.0.0.dev0", "1.0.0.dev0"), - ), + ], ) @pytest.mark.usefixtures("tmp_git_project") def test_scm_provider( diff --git a/tests/test_bump_create_commit_message.py b/tests/test_bump_create_commit_message.py index bdafd2364a..54b375335d 100644 --- a/tests/test_bump_create_commit_message.py +++ b/tests/test_bump_create_commit_message.py @@ -17,17 +17,17 @@ ] -@pytest.mark.parametrize("test_input,expected", conversion) +@pytest.mark.parametrize(("test_input", "expected"), conversion) def test_create_tag(test_input, expected): current_version, new_version, message_template = test_input new_tag = bump.create_commit_message(current_version, new_version, message_template) assert new_tag == expected -@pytest.mark.parametrize("hook_runner", ("pre-commit", "prek")) +@pytest.mark.parametrize("hook_runner", ["pre-commit", "prek"]) @pytest.mark.parametrize( "retry", - ( + [ pytest.param( True, marks=pytest.mark.skipif( @@ -36,7 +36,7 @@ def test_create_tag(test_input, expected): ), ), False, - ), + ], ) @pytest.mark.usefixtures("tmp_commitizen_project") def test_bump_pre_commit_changelog(util: UtilFixture, retry, hook_runner): @@ -84,8 +84,8 @@ def test_bump_pre_commit_changelog(util: UtilFixture, retry, hook_runner): ) -@pytest.mark.parametrize("hook_runner", ("pre-commit", "prek")) -@pytest.mark.parametrize("retry", (True, False)) +@pytest.mark.parametrize("hook_runner", ["pre-commit", "prek"]) +@pytest.mark.parametrize("retry", [True, False]) @pytest.mark.usefixtures("tmp_commitizen_project") def test_bump_pre_commit_changelog_fails_always(util: UtilFixture, retry, hook_runner): util.freezer.move_to("2022-04-01") diff --git a/tests/test_bump_find_increment.py b/tests/test_bump_find_increment.py index 77e11c78c7..8209278ed5 100644 --- a/tests/test_bump_find_increment.py +++ b/tests/test_bump_find_increment.py @@ -85,8 +85,8 @@ @pytest.mark.parametrize( - "messages, expected_type", - ( + ("messages", "expected_type"), + [ (PATCH_INCREMENTS_CC, "PATCH"), (MINOR_INCREMENTS_CC, "MINOR"), (MAJOR_INCREMENTS_BREAKING_CHANGE_CC, "MAJOR"), @@ -96,7 +96,7 @@ (MAJOR_INCREMENTS_EXCLAMATION_CC, "MAJOR"), (MAJOR_INCREMENTS_EXCLAMATION_CC_SAMPLE_2, "MAJOR"), (NONE_INCREMENT_CC, None), - ), + ], ) def test_find_increment(messages, expected_type): commits = [GitCommit(rev="test", title=message) for message in messages] @@ -109,12 +109,12 @@ def test_find_increment(messages, expected_type): @pytest.mark.parametrize( - "messages, expected_type", - ( + ("messages", "expected_type"), + [ (PATCH_INCREMENTS_SVE, "PATCH"), (MINOR_INCREMENTS_SVE, "MINOR"), (MAJOR_INCREMENTS_SVE, "MAJOR"), - ), + ], ) def test_find_increment_sve(messages, expected_type): commits = [GitCommit(rev="test", title=message) for message in messages] diff --git a/tests/test_bump_normalize_tag.py b/tests/test_bump_normalize_tag.py index 895acbd71a..558550c5ad 100644 --- a/tests/test_bump_normalize_tag.py +++ b/tests/test_bump_normalize_tag.py @@ -15,7 +15,7 @@ ] -@pytest.mark.parametrize("test_input,expected", conversion) +@pytest.mark.parametrize(("test_input", "expected"), conversion) def test_create_tag(test_input, expected): version, format = test_input rules = TagRules() diff --git a/tests/test_bump_update_version_in_files.py b/tests/test_bump_update_version_in_files.py index 8fd4c465b8..ea274c9317 100644 --- a/tests/test_bump_update_version_in_files.py +++ b/tests/test_bump_update_version_in_files.py @@ -295,7 +295,7 @@ def test_update_version_in_files_with_check_consistency_true_failure( @pytest.mark.parametrize( - "encoding,filename", + ("encoding", "filename"), [ ("latin-1", "test_latin1.txt"), ("utf-16", "test_utf16.txt"), diff --git a/tests/test_changelog.py b/tests/test_changelog.py index 0831bcc1ff..748e466a01 100644 --- a/tests/test_changelog.py +++ b/tests/test_changelog.py @@ -1154,7 +1154,7 @@ def test_invalid_tag_included_in_changelog(): ) -@pytest.mark.parametrize("merge_prereleases", (True, False)) +@pytest.mark.parametrize("merge_prereleases", [True, False]) def test_generate_tree_from_commits(gitcommits, tags, merge_prereleases): parser = ConventionalCommitsCz.commit_parser changelog_pattern = ConventionalCommitsCz.bump_pattern @@ -1194,8 +1194,8 @@ def test_generate_tree_from_commits_with_no_commits(tags): @pytest.mark.parametrize( - "change_type_order, expected_reordering", - ( + ("change_type_order", "expected_reordering"), + [ ([], {}), ( ["BREAKING CHANGE", "refactor"], @@ -1210,7 +1210,7 @@ def test_generate_tree_from_commits_with_no_commits(tags): }, }, ), - ), + ], ) def test_generate_ordered_changelog_tree(change_type_order, expected_reordering): tree = changelog.generate_ordered_changelog_tree(COMMITS_TREE, change_type_order) diff --git a/tests/test_changelog_format_asciidoc.py b/tests/test_changelog_format_asciidoc.py index c64979ee16..a56a05ba08 100644 --- a/tests/test_changelog_format_asciidoc.py +++ b/tests/test_changelog_format_asciidoc.py @@ -132,7 +132,7 @@ def format_with_tags(config: BaseConfig, request) -> AsciiDoc: ] -@pytest.mark.parametrize("line_from_changelog,output_version", VERSIONS_EXAMPLES) +@pytest.mark.parametrize(("line_from_changelog", "output_version"), VERSIONS_EXAMPLES) def test_changelog_detect_version( line_from_changelog: str, output_version: tuple[str, str] | None, format: AsciiDoc ): @@ -147,7 +147,7 @@ def test_changelog_detect_version( ] -@pytest.mark.parametrize("line_from_changelog,output_title", TITLES_EXAMPLES) +@pytest.mark.parametrize(("line_from_changelog", "output_title"), TITLES_EXAMPLES) def test_parse_title_type_of_line( line_from_changelog: str, output_title: str, format: AsciiDoc ): @@ -156,13 +156,13 @@ def test_parse_title_type_of_line( @pytest.mark.parametrize( - "content, expected", - ( + ("content", "expected"), + [ pytest.param(CHANGELOG_A, EXPECTED_A, id="A"), pytest.param(CHANGELOG_B, EXPECTED_B, id="B"), pytest.param(CHANGELOG_C, EXPECTED_C, id="C"), pytest.param(CHANGELOG_D, EXPECTED_D, id="D"), - ), + ], ) def test_get_metadata( tmp_path: Path, format: AsciiDoc, content: str, expected: Metadata @@ -178,8 +178,8 @@ def test_get_latest_full_release_no_file(format: AsciiDoc): @pytest.mark.parametrize( - "format_with_tags, tag_string, expected, ", - ( + ("format_with_tags", "tag_string", "expected"), + [ pytest.param("${version}-example", "1.0.0-example", "1.0.0"), pytest.param("${version}example", "1.0.0example", "1.0.0"), pytest.param("example${version}", "example1.0.0", "1.0.0"), @@ -197,7 +197,7 @@ def test_get_latest_full_release_no_file(format: AsciiDoc): "1.0.0-a1.dev1", ), pytest.param("new-${version}", "legacy-1.0.0", "1.0.0"), - ), + ], indirect=["format_with_tags"], ) def test_get_metadata_custom_tag_format( diff --git a/tests/test_changelog_format_markdown.py b/tests/test_changelog_format_markdown.py index e09d68cfed..1b75ed1f7f 100644 --- a/tests/test_changelog_format_markdown.py +++ b/tests/test_changelog_format_markdown.py @@ -132,7 +132,7 @@ def format_with_tags(config: BaseConfig, request) -> Markdown: ] -@pytest.mark.parametrize("line_from_changelog,output_version", VERSIONS_EXAMPLES) +@pytest.mark.parametrize(("line_from_changelog", "output_version"), VERSIONS_EXAMPLES) def test_changelog_detect_version( line_from_changelog: str, output_version: tuple[str, str] | None, format: Markdown ): @@ -147,7 +147,7 @@ def test_changelog_detect_version( ] -@pytest.mark.parametrize("line_from_changelog,output_title", TITLES_EXAMPLES) +@pytest.mark.parametrize(("line_from_changelog", "output_title"), TITLES_EXAMPLES) def test_parse_title_type_of_line( line_from_changelog: str, output_title: str, format: Markdown ): @@ -156,13 +156,13 @@ def test_parse_title_type_of_line( @pytest.mark.parametrize( - "content, expected", - ( + ("content", "expected"), + [ pytest.param(CHANGELOG_A, EXPECTED_A, id="A"), pytest.param(CHANGELOG_B, EXPECTED_B, id="B"), pytest.param(CHANGELOG_C, EXPECTED_C, id="C"), pytest.param(CHANGELOG_D, EXPECTED_D, id="D"), - ), + ], ) def test_get_metadata( tmp_path: Path, format: Markdown, content: str, expected: Metadata @@ -174,8 +174,8 @@ def test_get_metadata( @pytest.mark.parametrize( - "format_with_tags, tag_string, expected, ", - ( + ("format_with_tags", "tag_string", "expected"), + [ pytest.param("${version}-example", "1.0.0-example", "1.0.0"), pytest.param("${version}example", "1.0.0example", "1.0.0"), pytest.param("example${version}", "example1.0.0", "1.0.0"), @@ -198,7 +198,7 @@ def test_get_metadata( "1.0.0-a1.dev1", ), pytest.param("new-${version}", "legacy-1.0.0", "1.0.0"), - ), + ], indirect=["format_with_tags"], ) def test_get_metadata_custom_tag_format( diff --git a/tests/test_changelog_format_restructuredtext.py b/tests/test_changelog_format_restructuredtext.py index e6eceff4fa..00f7740737 100644 --- a/tests/test_changelog_format_restructuredtext.py +++ b/tests/test_changelog_format_restructuredtext.py @@ -316,7 +316,7 @@ def format_with_tags(config: BaseConfig, request) -> RestructuredText: return RestructuredText(config) -@pytest.mark.parametrize("content, expected", CASES) +@pytest.mark.parametrize(("content", "expected"), CASES) def test_get_metadata( tmp_path: Path, format: RestructuredText, content: str, expected: Metadata ): @@ -327,7 +327,7 @@ def test_get_metadata( @pytest.mark.parametrize( - "text, expected", + ("text", "expected"), [(text, True) for text in UNDERLINED_TITLES] + [(text, False) for text in NOT_UNDERLINED_TITLES], ) @@ -337,7 +337,7 @@ def test_is_underlined_title(text: str, expected: bool): @pytest.mark.parametrize( - "text, expected", + ("text", "expected"), [(text, True) for text in OVERLINED_TITLES] + [(text, False) for text in NOT_OVERLINED_TITLES], ) @@ -348,8 +348,8 @@ def test_is_overlined_title(text: str, expected: bool): @pytest.mark.parametrize( - "format_with_tags, tag_string, expected, ", - ( + ("format_with_tags", "tag_string", "expected"), + [ pytest.param("${version}-example", "1.0.0-example", "1.0.0"), pytest.param("${version}", "1.0.0", "1.0.0"), pytest.param("${version}example", "1.0.0example", "1.0.0"), @@ -368,7 +368,7 @@ def test_is_overlined_title(text: str, expected: bool): "1.0.0-a1.dev1", ), pytest.param("new-${version}", "legacy-1.0.0", "1.0.0"), - ), + ], indirect=["format_with_tags"], ) def test_get_metadata_custom_tag_format( diff --git a/tests/test_changelog_format_textile.py b/tests/test_changelog_format_textile.py index 752cf229e5..481f903a7a 100644 --- a/tests/test_changelog_format_textile.py +++ b/tests/test_changelog_format_textile.py @@ -125,7 +125,7 @@ def format_with_tags(config: BaseConfig, request) -> Textile: ] -@pytest.mark.parametrize("line_from_changelog,output_version", VERSIONS_EXAMPLES) +@pytest.mark.parametrize(("line_from_changelog", "output_version"), VERSIONS_EXAMPLES) def test_changelog_detect_version( line_from_changelog: str, output_version: tuple[str, str] | None, format: Textile ): @@ -140,7 +140,7 @@ def test_changelog_detect_version( ] -@pytest.mark.parametrize("line_from_changelog,output_title", TITLES_EXAMPLES) +@pytest.mark.parametrize(("line_from_changelog", "output_title"), TITLES_EXAMPLES) def test_parse_title_type_of_line( line_from_changelog: str, output_title: str, format: Textile ): @@ -149,13 +149,13 @@ def test_parse_title_type_of_line( @pytest.mark.parametrize( - "content, expected", - ( + ("content", "expected"), + [ pytest.param(CHANGELOG_A, EXPECTED_A, id="A"), pytest.param(CHANGELOG_B, EXPECTED_B, id="B"), pytest.param(CHANGELOG_C, EXPECTED_C, id="C"), pytest.param(CHANGELOG_D, EXPECTED_D, id="D"), - ), + ], ) def test_get_metadata( tmp_path: Path, format: Textile, content: str, expected: Metadata @@ -167,8 +167,8 @@ def test_get_metadata( @pytest.mark.parametrize( - "format_with_tags, tag_string, expected, ", - ( + ("format_with_tags", "tag_string", "expected"), + [ pytest.param("${version}-example", "1.0.0-example", "1.0.0"), pytest.param("${version}example", "1.0.0example", "1.0.0"), pytest.param("example${version}", "example1.0.0", "1.0.0"), @@ -186,7 +186,7 @@ def test_get_metadata( "1.0.0-a1.dev1", ), pytest.param("new-${version}", "legacy-1.0.0", "1.0.0"), - ), + ], indirect=["format_with_tags"], ) def test_get_metadata_custom_tag_format( diff --git a/tests/test_changelog_formats.py b/tests/test_changelog_formats.py index ff7126d345..6ffbc8dc33 100644 --- a/tests/test_changelog_formats.py +++ b/tests/test_changelog_formats.py @@ -24,13 +24,13 @@ def test_guess_format(format: type[ChangelogFormat]): assert _guess_changelog_format(f"CHANGELOG.{ext}") is format -@pytest.mark.parametrize("filename", ("CHANGELOG", "NEWS", "file.unknown", None)) +@pytest.mark.parametrize("filename", ["CHANGELOG", "NEWS", "file.unknown", None]) def test_guess_format_unknown(filename: str): assert _guess_changelog_format(filename) is None @pytest.mark.parametrize( - "name, expected", + ("name", "expected"), [ pytest.param(name, format, id=name) for name, format in KNOWN_CHANGELOG_FORMATS.items() @@ -41,7 +41,7 @@ def test_get_format(config: BaseConfig, name: str, expected: type[ChangelogForma assert isinstance(get_changelog_format(config), expected) -@pytest.mark.parametrize("filename", (None, "")) +@pytest.mark.parametrize("filename", [None, ""]) def test_get_format_empty_filename(config: BaseConfig, filename: str | None): config.settings["changelog_format"] = defaults.CHANGELOG_FORMAT assert isinstance( @@ -50,14 +50,14 @@ def test_get_format_empty_filename(config: BaseConfig, filename: str | None): ) -@pytest.mark.parametrize("filename", (None, "")) +@pytest.mark.parametrize("filename", [None, ""]) def test_get_format_empty_filename_no_setting(config: BaseConfig, filename: str | None): config.settings["changelog_format"] = None with pytest.raises(ChangelogFormatUnknown): get_changelog_format(config, filename) -@pytest.mark.parametrize("filename", ("extensionless", "file.unknown")) +@pytest.mark.parametrize("filename", ["extensionless", "file.unknown"]) def test_get_format_unknown(config: BaseConfig, filename: str | None): with pytest.raises(ChangelogFormatUnknown): get_changelog_format(config, filename) diff --git a/tests/test_cli.py b/tests/test_cli.py index f504a8cb6c..c1f6d5beda 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -138,7 +138,7 @@ def test_commitizen_excepthook_no_raises(capsys): @pytest.mark.parametrize( - "input_str, expected_result", + ("input_str", "expected_result"), [ pytest.param("1", [1], id="single_code"), pytest.param("1,2,3", [1, 2, 3], id="multiple_number_codes"), diff --git a/tests/test_conf.py b/tests/test_conf.py index f1ff76ff88..4c2d5c58ad 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -245,7 +245,7 @@ def test_load_empty_pyproject_toml_from_config_argument(self, tmpdir): class TestWarnMultipleConfigFiles: @pytest.mark.parametrize( - "files,expected_path", + ("files", "expected_path"), [ # Same directory, different file types ([(".cz.toml", TOML_STR), (".cz.json", JSON_STR)], ".cz.toml"), @@ -281,7 +281,7 @@ def test_warn_multiple_config_files_same_dir( assert cfg.path == Path(expected_path) @pytest.mark.parametrize( - "config_file,content", + ("config_file", "content"), [ (".cz.json", JSON_STR), (".cz.toml", TOML_STR), @@ -332,7 +332,7 @@ def test_no_warn_with_explicit_config_path(self, tmpdir, capsys): assert cfg.settings == json_cfg_expected.settings @pytest.mark.parametrize( - "config_file, content, with_git", + ("config_file", "content", "with_git"), [ (file, content, with_git) for file, content in [ diff --git a/tests/test_cz_conventional_commits.py b/tests/test_cz_conventional_commits.py index 1742b0f3b7..fc78b3fd49 100644 --- a/tests/test_cz_conventional_commits.py +++ b/tests/test_cz_conventional_commits.py @@ -106,7 +106,7 @@ def test_breaking_change_in_footer(config): @pytest.mark.parametrize( - "scope,breaking_change_exclamation_in_title,expected_message", + ("scope", "breaking_change_exclamation_in_title", "expected_message"), [ # Test with scope and breaking_change_exclamation_in_title enabled ( diff --git a/tests/test_git.py b/tests/test_git.py index 9333997813..8efb7ca5c0 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -352,7 +352,7 @@ def test_create_tag_with_message(util: UtilFixture): @pytest.mark.parametrize( - "file_path,expected_cmd", + ("file_path", "expected_cmd"), [ ( "/tmp/temp file", @@ -446,7 +446,7 @@ def test_git_commit_from_rev_and_commit(linebreak): @pytest.mark.parametrize( - "os_name,committer_date,expected_cmd", + ("os_name", "committer_date", "expected_cmd"), [ ( "nt", diff --git a/tests/test_project_info.py b/tests/test_project_info.py index 9fe26d3612..89359fe73e 100644 --- a/tests/test_project_info.py +++ b/tests/test_project_info.py @@ -19,7 +19,7 @@ def _create_project_files(files: dict[str, str | None]) -> None: @pytest.mark.parametrize( - "which_return, expected", + ("which_return", "expected"), [ ("/usr/local/bin/pre-commit", True), ("/usr/local/bin/prek", True), @@ -33,7 +33,7 @@ def test_is_pre_commit_installed(mocker, which_return, expected): @pytest.mark.parametrize( - "files, expected", + ("files", "expected"), [ ( {"pyproject.toml": '[tool.poetry]\nname = "test"\nversion = "0.1.0"'}, @@ -66,7 +66,7 @@ def test_get_default_version_provider(chdir, files, expected): @pytest.mark.parametrize( - "files, expected", + ("files", "expected"), [ ({"pyproject.toml": ""}, "pyproject.toml"), ({}, ".cz.toml"), @@ -78,7 +78,7 @@ def test_get_default_config_filename(chdir, files, expected): @pytest.mark.parametrize( - "files, expected", + ("files", "expected"), [ ({"pyproject.toml": ""}, "pep440"), ({"setup.py": ""}, "pep440"), diff --git a/tests/test_version_scheme_pep440.py b/tests/test_version_scheme_pep440.py index 3c15eeb4a9..479c2f775d 100644 --- a/tests/test_version_scheme_pep440.py +++ b/tests/test_version_scheme_pep440.py @@ -5,7 +5,7 @@ @pytest.mark.parametrize( - "version_args, expected_version", + ("version_args", "expected_version"), [ ( VersionSchemeTestArgs( @@ -1037,7 +1037,7 @@ def test_bump_pep440_version(version_args, expected_version): @pytest.mark.parametrize( - "version_args, expected_version", + ("version_args", "expected_version"), [ ( VersionSchemeTestArgs( @@ -1264,7 +1264,7 @@ def test_bump_pep440_version_force(version_args, expected_version): @pytest.mark.parametrize( - "version_args, expected_version", + ("version_args", "expected_version"), [ ( VersionSchemeTestArgs( diff --git a/tests/test_version_scheme_semver.py b/tests/test_version_scheme_semver.py index 1a75cd3eae..b5a275e980 100644 --- a/tests/test_version_scheme_semver.py +++ b/tests/test_version_scheme_semver.py @@ -7,7 +7,7 @@ @pytest.mark.parametrize( - "version_args, expected_version", + ("version_args", "expected_version"), [ ( VersionSchemeTestArgs( @@ -601,7 +601,7 @@ def test_bump_semver_version( @pytest.mark.parametrize( - "version_args, expected_version", + ("version_args", "expected_version"), [ ( VersionSchemeTestArgs( @@ -819,7 +819,7 @@ def test_bump_semver_version_force( @pytest.mark.parametrize( - "version_args, expected_version", + ("version_args", "expected_version"), [ ( VersionSchemeTestArgs( diff --git a/tests/test_version_scheme_semver2.py b/tests/test_version_scheme_semver2.py index 6ce00e06ed..ddd975bf7a 100644 --- a/tests/test_version_scheme_semver2.py +++ b/tests/test_version_scheme_semver2.py @@ -7,7 +7,7 @@ @pytest.mark.parametrize( - "version_args, expected_version", + ("version_args", "expected_version"), [ ( VersionSchemeTestArgs( @@ -571,7 +571,7 @@ def test_bump_semver_version( @pytest.mark.parametrize( - "version_args, expected_version", + ("version_args", "expected_version"), [ ( VersionSchemeTestArgs( From 527860c3f1d096c017bf3d4e63748e5c15d7540d Mon Sep 17 00:00:00 2001 From: Yu-Ting Hsiung Date: Sun, 1 Feb 2026 20:58:36 +0800 Subject: [PATCH 2/3] test: enable PT011 --- pyproject.toml | 1 - tests/commands/test_commit_command.py | 4 ++-- tests/test_exceptions.py | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index afe25bcb7b..52544e9ca4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -239,7 +239,6 @@ ignore = [ "E501", "D1", "D415", - "PT011", # TODO(bearomorphism): enable this rule "PT022", # TODO(bearomorphism): enable this rule ] extend-safe-fixes = [ diff --git a/tests/commands/test_commit_command.py b/tests/commands/test_commit_command.py index 89a9224b85..5adf21df66 100644 --- a/tests/commands/test_commit_command.py +++ b/tests/commands/test_commit_command.py @@ -248,8 +248,8 @@ def test_commit_when_customized_expected_raised(config, mocker: MockFixture): @pytest.mark.usefixtures("staging_is_clean") def test_commit_when_non_customized_expected_raised(config, mocker: MockFixture): - mocker.patch("questionary.prompt", side_effect=ValueError()) - with pytest.raises(ValueError): + mocker.patch("questionary.prompt", side_effect=ValueError("error message")) + with pytest.raises(ValueError, match="error message"): commands.Commit(config, {})() diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 1a66c79d02..f9ff733c95 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -30,7 +30,7 @@ def test_from_str_with_invalid_values(): """Test from_str with invalid values.""" with pytest.raises(KeyError): ExitCode.from_str("invalid_name") - with pytest.raises(ValueError): + with pytest.raises(ValueError, match="is not a valid ExitCode"): ExitCode.from_str("999") # Out of range decimal with pytest.raises(KeyError): ExitCode.from_str("") From 98438a08f7814f34fbd8bc9714929114e590bf3e Mon Sep 17 00:00:00 2001 From: Yu-Ting Hsiung Date: Sun, 1 Feb 2026 21:04:49 +0800 Subject: [PATCH 3/3] test: enable PT022 --- pyproject.toml | 7 +------ tests/conftest.py | 40 ++++++++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 52544e9ca4..8545892d33 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -235,12 +235,7 @@ select = [ "TC005", "TC006", ] -ignore = [ - "E501", - "D1", - "D415", - "PT022", # TODO(bearomorphism): enable this rule -] +ignore = ["E501", "D1", "D415"] extend-safe-fixes = [ "TC", # Move imports inside/outside TYPE_CHECKING blocks "UP", # Update syntaxes for current Python version recommendations diff --git a/tests/conftest.py b/tests/conftest.py index b1690ccab8..549b0b8fe4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -85,7 +85,7 @@ def tmp_commitizen_project(tmp_git_project): tmp_commitizen_cfg_file = tmp_git_project.join("pyproject.toml") tmp_commitizen_cfg_file.write('[tool.commitizen]\nversion="0.1.0"\n') - yield tmp_git_project + return tmp_git_project @pytest.fixture @@ -122,7 +122,7 @@ def _initial( return tmp_git_project - yield _initial + return _initial def _get_gpg_keyid(signer_mail): @@ -139,23 +139,31 @@ def tmp_commitizen_project_with_gpg(tmp_commitizen_project): # create a temporary GPGHOME to store a temporary keyring. # Home path must be less than 104 characters gpg_home = tempfile.TemporaryDirectory(suffix="_cz") + old_gnupghome = os.environ.get("GNUPGHOME") if os.name != "nt": os.environ["GNUPGHOME"] = gpg_home.name # tempdir = temp keyring - # create a key (a keyring will be generated within GPUPGHOME) - c = cmd.run( - f"gpg --batch --yes --debug-quick-random --passphrase '' --quick-gen-key '{SIGNER} {SIGNER_MAIL}'" - ) - if c.return_code != 0: - raise Exception(f"gpg keygen failed with err: '{c.err}'") - key_id = _get_gpg_keyid(SIGNER_MAIL) - assert key_id - - # configure git to use gpg signing - cmd.run("git config commit.gpgsign true") - cmd.run(f"git config user.signingkey {key_id}") - - yield tmp_commitizen_project + try: + # create a key (a keyring will be generated within GPUPGHOME) + c = cmd.run( + f"gpg --batch --yes --debug-quick-random --passphrase '' --quick-gen-key '{SIGNER} {SIGNER_MAIL}'" + ) + if c.return_code != 0: + raise Exception(f"gpg keygen failed with err: '{c.err}'") + key_id = _get_gpg_keyid(SIGNER_MAIL) + assert key_id + + # configure git to use gpg signing + cmd.run("git config commit.gpgsign true") + cmd.run(f"git config user.signingkey {key_id}") + + yield tmp_commitizen_project + finally: + if old_gnupghome is not None: + os.environ["GNUPGHOME"] = old_gnupghome + elif "GNUPGHOME" in os.environ and os.name != "nt": + os.environ.pop("GNUPGHOME") + gpg_home.cleanup() @pytest.fixture