Skip to content

use pathlib in tests: make _common.RSRC a pathlib.Path#6850

Open
snejus wants to merge 1 commit into
masterfrom
make-rsrc-pathlib-path
Open

use pathlib in tests: make _common.RSRC a pathlib.Path#6850
snejus wants to merge 1 commit into
masterfrom
make-rsrc-pathlib-path

Conversation

@snejus

@snejus snejus commented Jul 16, 2026

Copy link
Copy Markdown
Member

Part of #6807

What changed

  • This change standardizes test resource paths by making _common.RSRC a pathlib.Path instead of a bytes path.
  • Test code now builds paths with / and uses Path helpers like read_text(), read_bytes(), open(), stat(), and resolve().
  • Path handling setup in beets/test/_common.py is simplified, and old byte-string path conversions are removed from many tests.

Why

  • Before, test code mixed os.path, byte paths, string decoding, and utility conversions.
  • Now, resource path handling has one clear shape: Path objects.
  • This reduces path-conversion noise and makes test helpers easier to read and reuse.

Copilot AI review requested due to automatic review settings July 16, 2026 16:35
@snejus
snejus requested a review from a team as a code owner July 16, 2026 16:35
@github-actions

Copy link
Copy Markdown

Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry.

@snejus
snejus force-pushed the keep-path-based-properties-in-helpers branch from 1e5cb96 to d0844f4 Compare July 16, 2026 16:36
@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.62%. Comparing base (8778d0e) to head (bfd3b7e).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6850      +/-   ##
==========================================
- Coverage   75.63%   75.62%   -0.01%     
==========================================
  Files         163      163              
  Lines       21317    21317              
  Branches     3361     3361              
==========================================
- Hits        16124    16122       -2     
- Misses       4403     4404       +1     
- Partials      790      791       +1     

see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

grug see PR try make test resource path _common.RSRC be pathlib.Path, so tests stop juggling bytes/str/os.path and use /, .open(), .read_bytes(), .stat(), etc.

Changes:

  • make beets/test/_common.py::RSRC be Path and adjust PLUGINPATH to string
  • update many tests to build resource paths via RSRC / "file.ext" and use Path helpers
  • remove some old bytes-path glue in tests

Reviewed changes

Copilot reviewed 37 out of 37 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
beets/test/_common.py redefine RSRC as Path and adjust plugin path string
beets/test/helper.py use RSRC Path in fixtures (but one place still assigns Path into byte-only Item["path"])
test/util/test_m3ufile.py use RSRC / ... for playlist fixtures
test/util/test_art_resize.py use Path for image fixture constant
test/ui/commands/test_utils.py simplify copy of resource media file using Path
test/ui/commands/test_update.py use Path for resource media inputs
test/ui/commands/test_completion.py load completion script via Path.open()
test/test_library.py use Path resource for unreadable file and unicode-path test (but .path assignment needs bytes)
test/test_importer.py use Path resource joins in importer tests (but importer.paths overwrites must stay bytes)
test/plugins/test_web.py use Path for resource media and URL path construction
test/plugins/test_spotify.py read mock JSON via Path.read_bytes()
test/plugins/test_replace.py remove .decode() and use RSRC Path directly
test/plugins/test_plugin_mediafield.py use RSRC Path when copying fixture file
test/plugins/test_metasync.py use RSRC Path for itunes xml fixtures
test/plugins/test_embedart.py switch art fixture paths to Path and simplify display string
test/plugins/test_convert.py switch convert stub/art paths to Path (but .artpath assignment must stay bytes)
test/plugins/test_art.py switch some fixture paths to Path (linked issue says this file was scope-exempt)
test/plugins/test_acousticbrainz.py load JSON via Path.read_text() + json.loads()

Comment thread beets/test/helper.py
Comment thread test/test_library.py
Comment thread test/plugins/test_convert.py
Comment thread test/plugins/test_convert.py
Comment thread test/test_importer.py
Comment thread test/test_importer.py Outdated
Comment thread test/test_importer.py Outdated
Comment thread test/test_importer.py Outdated
Comment thread test/test_importer.py Outdated
Comment thread test/test_importer.py Outdated
@snejus
snejus force-pushed the keep-path-based-properties-in-helpers branch from d0844f4 to 34ef4b0 Compare July 17, 2026 09:53
@snejus
snejus force-pushed the make-rsrc-pathlib-path branch from 97c01e1 to 9e54dce Compare July 17, 2026 09:54
@snejus
snejus force-pushed the keep-path-based-properties-in-helpers branch from 34ef4b0 to b22c194 Compare July 21, 2026 00:19
@snejus
snejus force-pushed the make-rsrc-pathlib-path branch from 9e54dce to 0757fb3 Compare July 21, 2026 00:19
@snejus
snejus force-pushed the keep-path-based-properties-in-helpers branch from b22c194 to bb0e6bb Compare July 21, 2026 10:15
@snejus
snejus force-pushed the make-rsrc-pathlib-path branch from 0757fb3 to 6a4f3fc Compare July 21, 2026 10:15
Base automatically changed from keep-path-based-properties-in-helpers to master July 21, 2026 12:06
@snejus
snejus force-pushed the make-rsrc-pathlib-path branch from 6a4f3fc to 674758f Compare July 21, 2026 12:06
@snejus
snejus force-pushed the make-rsrc-pathlib-path branch from 674758f to bfd3b7e Compare July 21, 2026 15:24
@snejus snejus linked an issue Jul 21, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor tests to use pathlib.Path

3 participants