Skip to content

Commit b850363

Browse files
committed
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.
1 parent 58d70aa commit b850363

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

beets/dbcore/query.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -283,26 +283,20 @@ class PathQuery(FieldQuery[bytes]):
283283
and case-sensitive otherwise.
284284
"""
285285

286-
def __init__(self, field, pattern, fast=True, case_sensitive=None):
286+
def __init__(self, field, pattern, fast=True):
287287
"""Create a path query.
288288
289289
`pattern` must be a path, either to a file or a directory.
290-
291-
`case_sensitive` can be a bool or `None`, indicating that the
292-
behavior should depend on the filesystem.
293290
"""
294291
super().__init__(field, pattern, fast)
295292

296293
path = util.normpath(pattern)
297294

298-
# By default, the case sensitivity depends on the filesystem
299-
# that the query path is located on.
300-
if case_sensitive is None:
301-
case_sensitive = util.case_sensitive(path)
302-
self.case_sensitive = case_sensitive
295+
# Case sensitivity depends on the filesystem that the query path is located on.
296+
self.case_sensitive = util.case_sensitive(path)
303297

304298
# Use a normalized-case pattern for case-insensitive matches.
305-
if not case_sensitive:
299+
if not self.case_sensitive:
306300
# We need to lowercase the entire path, not just the pattern.
307301
# In particular, on Windows, the drive letter is otherwise not
308302
# lowercased.

test/test_query.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,9 @@ def lib(self, helper):
903903
_p("path:/c/\\\\x", ["with backslash"], id="backslash-escaped"),
904904
],
905905
)
906-
def test_explicit(self, lib, q, expected_titles):
906+
def test_explicit(self, monkeypatch, lib, q, expected_titles):
907+
monkeypatch.setattr("beets.util.case_sensitive", lambda *_: True)
908+
907909
assert {i.title for i in lib.items(q)} == set(expected_titles)
908910

909911
@pytest.mark.skipif(sys.platform == "win32", reason=WIN32_NO_IMPLICIT_PATHS)

0 commit comments

Comments
 (0)