refactor: use pathlib utilities to shorten code#1855
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1855 +/- ##
==========================================
- Coverage 97.99% 97.98% -0.01%
==========================================
Files 60 60
Lines 2692 2684 -8
==========================================
- Hits 2638 2630 -8
Misses 54 54 ☔ View full report in Codecov by Sentry. |
0008e21 to
d058fa2
Compare
There was a problem hiding this comment.
Pull request overview
Refactors file IO across core Commitizen commands/config and the test suite to use pathlib.Path convenience APIs (read_text, read_bytes, write_bytes, etc.), reducing boilerplate and aligning IO patterns.
Changes:
- Replace
open(...).read()/Path.open(...).read()patterns withPath.read_text()in tests andinfo()helpers. - Replace binary config reads/writes with
Path.read_bytes()/Path.write_bytes()in TOML config handling and config loading. - Adjust a commit-command test fixture to write/read the backup message using
Pathutilities and correct working-directory expectations.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_conf.py | Simplifies TOML config content assertions using Path.read_text(). |
| tests/test_changelog.py | Uses Path.read_text() for loading changelog fixture content. |
| tests/test_bump_update_version_in_files.py | Replaces manual file opening with Path.read_text() when aggregating regression output. |
| tests/conftest.py | Switches to append-mode writes via open(..., "a") for generated pyproject.toml test content. |
| tests/commands/test_init_command.py | Reads generated config files via Path.read_text() and parses JSON/YAML from strings. |
| tests/commands/test_commit_command.py | Updates backup-message fixture to use Path.write_text() and ensure correct cwd for the command. |
| tests/commands/test_check_command.py | Updates mocks to patch Path.read_text() instead of open(). |
| tests/commands/test_changelog_command.py | Replaces repeated file reads with Path.read_text() across changelog command tests. |
| tests/commands/test_bump_command.py | Uses append-mode Path.open("a") and Path.read_text() for assertions on bumped files. |
| commitizen/cz/jira/jira.py | Uses Path.read_text() for bundled info text. |
| commitizen/cz/customize/customize.py | Uses Path(info_path).read_text() for external info file support. |
| commitizen/cz/conventional_commits/conventional_commits.py | Uses Path.read_text() for bundled info text. |
| commitizen/config/toml_config.py | Simplifies TOML reads/writes with read_bytes() / write_bytes(). |
| commitizen/config/init.py | Loads config bytes via Path.read_bytes() when creating config objects. |
| commitizen/commands/commit.py | Uses Path.read_text() when reading the temporary editor file and backup message. |
| commitizen/commands/check.py | Uses Path.read_text() to load commit messages from --commit-msg-file. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
d058fa2 to
16d8ee8
Compare
|
@copilot what can you assist me with this PR? |
|
@bearomorphism I've opened a new pull request, #1856, to work on those changes. Once the pull request is ready, I'll request review from you. |
|
Thanks for quick review, Santi! |
Description
Checklist
Was generative AI tooling used to co-author this PR?
Cursor
Steps to Test This Pull Request
Run
uv run poe test.