Commit graph

187 commits

Author SHA1 Message Date
Šarūnas Nejus
09b22949c0
Refactor test_query
And rewrite test_query.py
2025-07-06 16:15:30 +01:00
Šarūnas Nejus
2c6f314f4f
Replace assertNegationProperties 2025-07-06 16:15:29 +01:00
Šarūnas Nejus
2b306de0fe
Replace assertInResult and assertNotInResult 2025-07-06 16:15:29 +01:00
Šarūnas Nejus
8937978d5f
Refactor PathQuery and add docs 2025-07-06 16:09:50 +01:00
Šarūnas Nejus
45f92ac641
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.
2025-07-06 16:09:50 +01:00
Šarūnas Nejus
a38918380d
Rewrite path query tests using pytest.mark.parametrize
And remove `force_implicit_query_detection` attribute from `PathQuery`
class.
2025-07-06 16:09:49 +01:00
Šarūnas Nejus
1a045c9166
Copy paste query, types from library to dbcore 2025-07-06 16:03:46 +01:00
Šarūnas Nejus
c9f98fca55
Use unittest.TestCase for tests that don't require the dir setup 2025-05-26 12:40:38 +01:00
Šarūnas Nejus
d22c497dc0
Use table-qualified names in any field query
In order to include the table name for fields in this query, use the
`field_query` method.

Since `AnyFieldQuery` is just an `OrQuery` under the hood, remove it and
construct `OrQuery` explicitly instead.
2025-01-19 01:09:11 +00:00
valrus
80a10c7e4e lint 2024-12-31 15:14:32 -08:00
valrus
21c734bff8 patch rather than overwriting Item 2024-12-31 14:50:44 -08:00
Šarūnas Nejus
5f78d1b82b
Remove some lint exclusions and fix the issues
* Replace `noqa` comments in `assert...` method definitions with
  a configuration option to ignore these names.
* Use the `__all__` variable to specify importable items from the
  module, replacing `*` imports and `noqa` comments for unused imports.
* Address issues with poorly named variables and methods by renaming
  them appropriately.
2024-09-21 11:59:19 +01:00
Šarūnas Nejus
85a17ee503
Reformat the codebase 2024-09-21 11:57:48 +01:00
Šarūnas Nejus
4b69b493d2
Use f-string syntax 2024-08-16 17:47:23 +01:00
Šarūnas Nejus
f9359df0d1
Replace assertNotEqual 2024-08-12 08:43:42 +01:00
Šarūnas Nejus
847e3858a6
Replace assertRaises 2024-08-12 08:43:42 +01:00
Šarūnas Nejus
9a05d27acf
Replace assertEqual 2024-08-12 08:43:42 +01:00
Šarūnas Nejus
6631b6aef6
Replace assertNotIn 2024-08-12 08:43:42 +01:00
Šarūnas Nejus
11e948121c
Replace assertIn 2024-08-12 08:43:42 +01:00
Šarūnas Nejus
5d4911e905
Replace assertIsNone 2024-08-12 08:43:41 +01:00
Šarūnas Nejus
cb82917fe0
Replace assertFalse 2024-08-12 08:43:41 +01:00
Šarūnas Nejus
0ecc345143
Replace assertTrue 2024-08-05 17:11:16 +01:00
Šarūnas Nejus
fcff5d72af
Remove def suite TestLoader definitions 2024-07-28 18:58:51 +01:00
Šarūnas Nejus
7d7f16395c
Remove redundant library setUp instructions 2024-07-28 18:58:34 +01:00
Šarūnas Nejus
b64eaeda0a
Rename LibTestCase to ItemInDBTestCase 2024-07-28 18:58:34 +01:00
Šarūnas Nejus
6c1e26acc9
Replace unittest.TestCase, TestHelper by BeetsTestCase 2024-07-28 18:58:34 +01:00
Šarūnas Nejus
3e278159ed
Dedupe TestHelper and _common.TestCase setup 2024-07-28 18:58:33 +01:00
Šarūnas Nejus
bcc2826000
Make sure we can filter common fields 2024-06-21 15:05:29 +01:00
Šarūnas Nejus
981a61bd56
Add support for filtering relations 2024-06-21 15:05:29 +01:00
Šarūnas Nejus
2800a323a2
Revert "Make queries fast, filter all flexible attributes (#5240)"
This reverts commit 143b9202f3, reversing
changes made to 8508a57d77.
2024-06-19 21:51:44 +01:00
Šarūnas Nejus
6792a75c7e
Ensure that any field query uses the table name
In order to include the table name for fields in this query, use the
`field_query` method.

Since `AnyFieldQuery` is just an `OrQuery` under the hood, remove it and
construct `OrQuery` explicitly instead.
2024-06-16 15:28:46 +01:00
Šarūnas Nejus
9207b17d13
Enable querying related flexible attributes
Unify query creation logic from
- queryparse.py:construct_query_part,
- Model.field_query,
- DefaultTemplateFunctions._tmpl_unique

to a single implementation under `LibModel.field_query` class method.
This method should be used for query resolution for model (flex)fields.

Allow filtering item attributes in album queries and vice versa by
merging `flex_attrs` from Album and Item together as `all_flex_attrs`.
This field is only used for filtering and is discarded after.
2024-06-16 15:28:46 +01:00
Šarūnas Nejus
484c00e223
Add ability to filter flexible attributes through the Query
For a flexible attribute query, replace the `col_name` property with
a function call that extracts that attribute from the `field_attrs`
field introduced in the earlier commit.

Additionally, for boolean, numeric and date queries CAST the value to
NUMERIC SQLite affinity to ensure that our queries like 'flex:1..5' and
'flex:true' continue working fine.

This removes the concept of 'slow query', since every query for any
field now has an SQL clause.
2024-06-16 15:28:46 +01:00
Šarūnas Nejus
b0154d5cde
Fix querying fields present in both tables 2024-06-16 15:28:45 +01:00
Šarūnas Nejus
3347020c6c
Add support for filtering relations 2024-06-16 15:28:45 +01:00
freddiewanah
e0de6e1b89 refactor the test methods to avoid suboptimal asserts. 2024-04-08 21:39:25 +08:00
Lars Kruse
508d28f66b tests: move reusable test-related modules into the beets package
External Python packages interfacing beets may want to use an in-memory
beets library instance for testing beets-related code.
The `TestHelper` class is very helpful for this purpose.
Previously `TestHelper` was located in the `test/` directory.
Now it is part of `beets` itself (`beets.test.helper.TestHelper`) and
can be easily imported.
2024-01-15 19:40:57 +01:00
Serene-Arc
a6e5201ff3 Apply formatting tools to all files
This is 'the big one', which touches every file so that it all conforms
to the given standard.
2023-10-22 09:53:18 +10:00
Jesse Bannon
f72261e44f
Add support for artists and albumartists multi-valued tags (#4743)
Adds the following fields with id3v2.4 multi-valued tag support to autotag:
    - artists, artists_sort, artists_credit
    - albumartists, albumartists_sort, albumartists_credit
    - mb_artistids, mb_albumartistids

MusicBrainz support to populate + write the above multi-valued tags by default. Can be toggled to use id3v2.3 or id3v2.4 tags via the existing beets configuration option `id3v23`.

Big thanks to @JOJ0, @OxygenCobalt, @arsaboo for testing + @sampsyo for the initial code review .
2023-09-09 09:46:26 +02:00
wisp3rwind
1ef6b90786 add missing syspath conversions (1/3, tests)
these are mostly in the tests, which didn't cause issues since the
affected directories usually have nice ASCII paths. For consistency, it
is nicer to always invoke syspath. That also avoids deprecation warnings
for the bytestring interfaces on Python <= 3.5. The bytestring
interfaces were undeprecated with PEP 529 in Python 3.6, such that we
didn't observe any actual failures.
2023-06-24 14:52:46 +02:00
Šarūnas Nejus
724b06a77d
Define SingletonQuery to perform filtering through SQL
This slightly speeds up the queries and there's a nice side-effect where
`singleton:1` and `singleton:0` now work fine!

This is ultimately building towards replacing as many python-only
queries with SQL equivalents.
2023-04-08 06:15:04 +01:00
wisp3rwind
e6fd038b0e tests: robustify path query / case_sensitive tests
- samefile exists on all platforms for recent python
- don't rely on monkey-patching os/os.path and on specifics on the
  implementation: as a result of doing so, the tests start failing in
  obscure ways as soon as the implementation (and its usage of
  os.path.exists and os.path.samefile) is changed
2023-02-12 16:16:43 +01:00
wisp3rwind
a6d74686d8 test: separate case_sensitive unit tests from PathQueryTest
- move tests for case_sensitive to test_util.py, since this is not
  really the concern of PathQueryTest
- removes part of the tests, since the tests that patch os.path.samefile
  and os.path.exists are super brittle since they test the
  implementation rather than the functionality of case_sensitive().
  This is a prepartory step for actually changing the implementation,
  which would otherwise break the tests in a confusing way...
2022-12-24 13:36:53 +01:00
Adrian Sampson
32ce44f589
One more test fix 2022-08-17 16:25:17 -07:00
Adrian Sampson
495c8accc0
Update exact query prefix tests 2022-08-17 16:11:16 -07:00
Šarūnas Nejus
72c5302004
Fix lints 2022-05-31 22:45:05 +01:00
Šarūnas Nejus
ba777dda50
Skip implicit paths tests for win32 2022-05-31 22:34:40 +01:00
Šarūnas Nejus
d68ed1adca
Make implicit path queries explicit and simplify their handling 2022-05-31 21:51:47 +01:00
Rob Crowell
2cab2d670a Fix bug in StringQuery.string_match 2022-01-25 16:24:04 -08:00
Rob Crowell
6457532274 Add query prefixes :~ and := 2022-01-24 19:19:48 -08:00