Commit Graph
30 Commits
Author SHA1 Message Date
Šarūnas Nejus 27900f58fb Prefer imports from modules that provide import aliases 2026-08-18 23:20:39 +01:00
Šarūnas Nejus 9adcb601f8 typing: make dbcore.db.Results a Sequence
Now we are able to type Results simply as a Sequence. This way, we can
also now use a more generic representation `Sequence[LibModel]` to refer
to *any* of the two models.
2026-08-18 23:20:38 +01:00
Vincent Gao 2fe5dc7a0e Fix storing flex media fields during update 2026-08-04 08:29:44 +02:00
Sebastian Cao c7a842941d Fix queries for flexible attributes with uppercase names 2026-08-03 20:31:12 +08:00
Šarūnas Nejus 951e32a852 Use pathlib.Path wherever possible in tests 2026-07-30 12:18:49 +01:00
TowyTowyandClaude 348b87dd3e Normalise reversed date ranges instead of crashing
A date range query whose start lies after its end, such as
`beet ls added:2024..2020`, crashed with an uncaught ValueError
raised by DateInterval's endpoint-order check:

    ValueError: start date 2024-01-01 00:00:00 is not before end date
    2021-01-01 00:00:00

Only InvalidQueryArgumentValueError is converted into a user-facing
InvalidQueryError by Library._get_results, so the plain ValueError
escaped all the way up as a traceback.

Rather than reporting an error, accept the range and swap its two
endpoints, so `added:2024..2020` means the same as `added:2020..2024`.

The swap lives in `DateInterval.from_periods`, which is the only place
where the two user-supplied endpoints are still available as `Period`
objects. Swapping further down, in `DateInterval.__init__`, would swap
the already-derived datetimes, and those are derived asymmetrically:
the start contributes `Period.date` while the end contributes
`Period.open_right_endpoint()`. For `2024..2020` that would yield
[2021-01-01, 2024-01-01), which excludes both 2020 and 2024 -- not the
interval the user asked for. Swapping the periods first yields
[2020-01-01, 2025-01-01), which is exactly `2020..2024`.

`DateInterval.__init__` keeps raising ValueError, since it remains the
invariant guard for callers constructing an interval from datetimes
directly, where there is no notion of the order the user typed.

The swap only triggers when the interval would otherwise be empty, so
partially overlapping mixed-precision ranges that are valid today, such
as `2000-06..2000`, are unaffected. Genuinely malformed input such as
`added:notadate` still raises InvalidQueryArgumentValueError from
`Period.parse` as before.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-30 12:36:04 +02:00
Šarūnas Nejus 856087258b dbcore: rename Database._fetch to Database.get_results
This removes ambiguity with Library._fetch
2026-07-16 13:11:16 +01:00
Šarūnas Nejus 3f277ad5a0 typing: feed PathLike as database path 2026-07-16 13:11:16 +01:00
TowyTowyandClaude 4a1e9164a1 Fix uncaught KeyError on date queries containing a stray pipe
The relative-date regex used character classes [+|-] and [y|m|w|d],
which mistakenly treat | as a literal member rather than alternation.
As a result a value like added:2000|2001 (as a user might type expecting
| to mean "or") captured | as the relative-date unit and crashed with
an uncaught KeyError in Period.parse instead of raising the documented
InvalidQueryArgumentValueError.

Remove the stray | from both character classes so malformed date strings
fall through to the normal invalid-date error path.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-15 21:55:46 +02:00
Šarūnas Nejus 1266256f5e typing: fix beets.dbcore.types 2026-07-15 20:23:55 +01:00
Valentyn Kit eb7c832fc9 Make InQuery hashable when its pattern is a list
InQuery inherited FieldQuery.__hash__, which hashes the pattern directly.
A list pattern raises `unhashable type: 'list'`, which broke the
smartplaylist `splupdate` command whenever a `playlist:` query was configured.
2026-07-15 08:02:01 +01:00
TowyTowyandClaude 2293d2f60a Fix crash when sorting by a nullable field missing on some items
Sorting by a field whose declared type is nullable (its null value is
`None`, e.g. `NullInteger`/`NullFloat`) raised `TypeError: '<' not
supported between instances of ...` when the field was present on some
objects but missing on others, because `FieldSort.sort` compared `None`
against real values.

Group missing values together in the sort key so they are never compared
against present ones: they are ordered first when sorting ascending and
last when descending, matching SQLite's default ordering of NULLs used by
the fast `FixedFieldSort` path.

Fixes #3461.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-13 13:36:23 +01:00
Šarūnas Nejus 230bf19c7f Remove redundant test logic exposed by full coverage
- Removing the coverage omit configuration exposed unused branches, helpers, and
  fixtures across the test suite.
- Delete that redundant logic and simplify affected tests while preserving their
  behavior.
2026-07-07 15:57:35 +01:00
Šarūnas Nejus 79c7d69311 Remove wrongly added copyright markers 2026-07-07 15:57:35 +01:00
Šarūnas Nejus 7cf8896597 Make the global config fixture function-scoped 2026-07-03 21:21:19 +01:00
Šarūnas Nejus 900543baca Move test modules under folders that they belong to 2026-06-30 21:48:40 +01:00
Sebastian Mohr 54a2bd20e1 Removed This file is part of beets... headers. 2026-06-29 11:20:15 +02:00
Šarūnas Nejus de5c690181 Use class-scoped config across the test module 2026-06-24 17:01:19 +01:00
Šarūnas Nejus af1e6ceb4d Remove duplicate branches 2026-06-24 17:01:19 +01:00
Šarūnas Nejus 31f7cd4360 Tighten config sort tests
- Combine default and override sort assertions for items and albums.
- Use the config fixture and exact ordered results to avoid global config state.
2026-06-24 17:01:19 +01:00
Šarūnas Nejus 616b1b2b0b Refactor TestNonExistingField
- Consolidate duplicate sort test coverage with parametrized cases.
- Keep missing-field and mixed-presence behavior covered while reducing repeated
  assertions.
2026-06-24 17:01:19 +01:00
Šarūnas Nejus 85e4c607d2 Simplify TestCaseSensitivity 2026-06-24 17:01:19 +01:00
Šarūnas Nejus fb812daebe Simplify paths 2026-06-24 17:01:19 +01:00
Šarūnas Nejus eb07fa3a40 Consolidate sort query tests
- Replace duplicate direct MultipleSort checks with parametrized query-string
  cases covering single-field, multi-field, fixed, flex, and computed sort
  behavior.
- Reduce test repetition while keeping the same sort behavior coverage.
2026-06-24 17:01:19 +01:00
Šarūnas Nejus 349b082232 Parametrize descending sort coverage 2026-06-24 17:01:19 +01:00
Šarūnas Nejus 2d98777205 Parametrize ascending sort coverage
- Consolidate duplicate ascending sort tests across item and album fixed and
  flexible fields.
2026-06-24 17:01:19 +01:00
Šarūnas Nejus da1969125b Only set required fields 2026-06-24 17:01:19 +01:00
Šarūnas Nejus 100a645ffa Use pytest 2026-06-24 17:01:19 +01:00
Šarūnas Nejus 0cd20798aa sort: Update dotted sort references 2026-05-17 07:39:13 +01:00
Šarūnas Nejus 2db5383850 Move test_sort.py under test/dbcore 2026-05-17 07:39:13 +01:00