Remove case_sensitive from PathQuery.__init__

The case_sensitive parameter was only used in tests, which now use
monkeypatch to control the behavior of util.case_sensitive() instead.
This simplifies the PathQuery initialization logic while maintaining
test coverage.
This commit is contained in:
Šarūnas Nejus 2025-05-12 09:48:40 +01:00
parent a38918380d
commit 45f92ac641
No known key found for this signature in database
GPG key ID: DD28F6704DBE3435
2 changed files with 7 additions and 11 deletions

View file

@ -283,26 +283,20 @@ class PathQuery(FieldQuery[bytes]):
and case-sensitive otherwise.
"""
def __init__(self, field, pattern, fast=True, case_sensitive=None):
def __init__(self, field, pattern, fast=True):
"""Create a path query.
`pattern` must be a path, either to a file or a directory.
`case_sensitive` can be a bool or `None`, indicating that the
behavior should depend on the filesystem.
"""
super().__init__(field, pattern, fast)
path = util.normpath(pattern)
# By default, the case sensitivity depends on the filesystem
# that the query path is located on.
if case_sensitive is None:
case_sensitive = util.case_sensitive(path)
self.case_sensitive = case_sensitive
# Case sensitivity depends on the filesystem that the query path is located on.
self.case_sensitive = util.case_sensitive(path)
# Use a normalized-case pattern for case-insensitive matches.
if not case_sensitive:
if not self.case_sensitive:
# We need to lowercase the entire path, not just the pattern.
# In particular, on Windows, the drive letter is otherwise not
# lowercased.

View file

@ -904,7 +904,9 @@ class TestPathQuery:
_p("path:/c/\\\\x", ["with backslash"], id="backslash-escaped"),
],
)
def test_explicit(self, lib, q, expected_titles):
def test_explicit(self, monkeypatch, lib, q, expected_titles):
monkeypatch.setattr("beets.util.case_sensitive", lambda *_: True)
assert {i.title for i in lib.items(q)} == set(expected_titles)
@pytest.mark.skipif(sys.platform == "win32", reason=WIN32_NO_IMPLICIT_PATHS)