From 45f92ac6416e1200d941b410e42041dc147ecaa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Mon, 12 May 2025 09:48:40 +0100 Subject: [PATCH] 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. --- beets/dbcore/query.py | 14 ++++---------- test/test_query.py | 4 +++- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/beets/dbcore/query.py b/beets/dbcore/query.py index e02ebb76a..c814c5966 100644 --- a/beets/dbcore/query.py +++ b/beets/dbcore/query.py @@ -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. diff --git a/test/test_query.py b/test/test_query.py index 11537e039..a8646f1bb 100644 --- a/test/test_query.py +++ b/test/test_query.py @@ -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)