Commit graph

81 commits

Author SHA1 Message Date
Š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
a57c164348
Remove NamedQuery
Remove 'NamedQuery' since it is not being used by any queries any more.

This simplifies query parsing logic in 'queryparse.py'. We know that
this logic can only receive 'FieldQuery' thus I adjusted types and
removed the logic that handles other cases.

Effectively, this means that the query parsing logic does not any more
care whether the query is named by the corresponding DB field. Instead,
queries like 'SingletonQuery' and 'PlaylistQuery' are responsible for
translating 'singleton' and 'playlist' to the underlying DB filters.
2024-04-30 22:20:36 +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
wisp3rwind
09d2c87f29 typings: corrections for dbcore/queryparse
- Add NamedQuery abstract class to be able to express the expectation
  that a query should be such a query (and have a specific constructor
  signature) in construct_query_part
- slightly (and probably completely irrelevantly) improve Query.__hash__
- also, sprinkle some ABC/abstractmethod around to clarify things
2023-06-23 10:59:51 +02:00
wisp3rwind
0d1fa172de tests: explicitly close sqlite3 connections
on Python 3.11, the Windows CI started crashing due to the database file
remainig open unexpectly in test shutdown; this attemps to fix that
2023-05-07 18:43:43 +02:00
alicezou
2886296c86 fix code review comments 2022-03-29 21:24:13 -04:00
alicezou
67e778fec6 switch to control_stdin 2022-03-29 20:04:56 -04:00
alicezou
a0b0028874 working db 2022-03-29 19:58:15 -04:00
alicezou
c0d05f8545 add test cases 2022-03-27 17:09:30 -04:00
Andrew Rogl
ee4268dabb Remove unused imports
Fix imports
Fix formatting
2021-08-26 20:59:48 +10:00
Andrew Rogl
1ec87a3bdd pyupgrade beetsplug and tests
All tests working
More tidy up to be done
2021-08-26 19:12:51 +10:00
FichteFoll
eda9930c59
Merge remote-tracking branch 'upstream/master' into pr/item-album-fallback 2020-07-27 19:32:44 +02:00
Adam Jakab
5fc4d7c35e - added field_two as type STRING in ModelFixture1
- renamed test test_format_fixed_field to test_format_fixed_field_string
- test_format_fixed_field_string not tests `field_two` with string values
- added new test_format_fixed_field_integer to test field `field_one` as INTEGER
- added new test_format_fixed_field_integer_normalized to test rounding float values
2020-03-02 13:00:15 +01:00
FichteFoll
dfc23e8efe
Implement database and model revision checking
Prevents reloading a model from the database when it hasn't changed.

Now we're back to almost the same speed as before the addition of album
field fallbacks.
2019-06-05 02:58:42 +02:00
Carl Suster
10d41a1cbb tests: avoid non-test classes named Test*
When using pytest's test collector, any class with a name starting with
Test is collected. If it notices that the class has an `__init__` member
then it skips it with a warning since it's probably a false positive.
This isn't a big deal, but we can avoid warnings like this:

    test/test_ui_importer.py:33
      beets/test/test_ui_importer.py:33: PytestCollectionWarning: cannot collect test class 'TestTerminalImportSession' because it has a __init__ constructor
        class TestTerminalImportSession(TerminalImportSession):

simply by renaming TestX to XFixture.
2019-06-02 16:35:37 +10:00
Adrian Sampson
d8e167637e Prototype support for named (pseudo-field) queries
As discussed here:
https://github.com/beetbox/beets/pull/3145#pullrequestreview-204523870

This would replace the need for #3149.
2019-02-17 13:41:05 -05:00
David Logie
27f0b57d2b Remove pointless print call. 2018-10-10 15:40:21 +01:00
David Logie
932609933f Allow "deleting" fixed attributes via beet modify.
Deleting a fixed field isn't possible so we just reset the
field back to it's "null" value.

Fixes #2497.
2018-09-27 11:22:17 +01:00
Adrian Sampson
2a9be17cf6 Fix some brittle query tests
These were written to incidentally depend on Nones; the behavior they're
actually testing doesn't really have anything to say about None-ness.
2017-06-20 15:56:33 -04:00
Adrian Sampson
a88682e7bb Undo from _common import unittest indirection
This was a vestige from when we used to need the unittest2 library for pre-2.7
compatibility. Now that we require Python 2.7, we aren't using that library
and this indirection wasn't doing any good.
2016-11-26 18:46:44 -05:00
Johnny Robeson
7a2bdf502f s/utf8/utf-8/ in all encoding/decoding contexts
This matches up with the python documentation.
2016-09-06 23:10:24 -04:00
Johnny Robeson
e8afcbe7ec replace unicode with six.text_type 2016-06-24 05:53:49 -04:00
Johnny Robeson
7b66dfec4b use renamed test assertions from six 2016-06-23 04:40:18 -04:00
Johnny Robeson
cd1f79340f remove explicit b' from sql query dict key names 2016-05-30 18:50:11 -04:00
Adrian Sampson
71b9fd785c Revert "Do __name__ comparison with bytes and not unicode"
This reverts commit 9c41c39913.
That commit used byte strings for the `if __name__ == '__main__'` pattern,
which was necessary when we were doing unicode_literals. But it is wrong on
Python 3, and now that we're liberated from unicode_literals, we need to go
back to native strings for this comparison.
2016-05-29 19:19:59 -07:00
Johnny Robeson
b99a6acc54 use next() instead of iter.next() throughout 2016-05-27 17:00:40 -04:00
Adrian Sampson
e54c7eec3d Standardize __future__ imports without parentheses
Since the list is short enough now, we don't need parentheses for the line
wrap. This is a little less ugly.
2016-02-28 15:03:51 -08:00
Peter Kessen
bdaafdb147 Removed unicode_literals from test_dbcore 2016-02-22 09:11:21 +01:00
Jesse Weinstein
72ce9ea3eb use underscore in name for pep-8s sake 2016-01-12 22:14:12 -08:00
Jesse Weinstein
d93f723263 Convert SKIP_SLOW_TESTS to its own decorator 2016-01-12 21:53:52 -08:00
Jesse Weinstein
760298b8e4 Mark slow tests to be skipped if SKIP_SLOW_TESTS env var is defined
Saves over 100 seconds.
2016-01-10 23:18:47 -08:00
Jesse Weinstein
f770125e3c Avoid repeating expensive db creation
Saves about 3 seconds
2016-01-10 21:01:28 -08:00
Jesse Weinstein
11c8af724d Add more tests for dbcore 2016-01-10 21:00:39 -08:00
Jack Wilsdon
12cd5306b7 Update copyright dates to 2016 2015-12-30 15:42:06 +00:00
Adrian Sampson
6cb8db3b2e Merge pull request #1728 from diego-plan9/notquery
Add boolean "not" query operator
2015-11-20 10:00:05 -08:00
Peter Kessen
3eb8008b11 added encoding as comment in files
added line like
# -*- coding: utf-8 -*-
to all files with correct license in header
2015-11-19 18:41:01 +01:00
Diego Moreda
e457479558 Add NotQuery syntax tests
* Add tests to NotQueryTest for testing the results of using queries with
negation.
* Fix issue on test_dbcore due to the modifications on the tuple returned by
parse_query_part (the number of elements was changed from 3 to 4).
2015-11-18 17:27:22 +01:00
Adrian Sampson
f4a124e7e2 Fix #1605: parsing bare + and - in queries 2015-09-15 13:53:41 -07:00
Adrian Sampson
0979148866 Slightly more legible tests 2015-04-16 19:31:27 -07:00
Adrian Sampson
7c1cf6632e Add test for leading comma (#1423) 2015-04-16 19:28:03 -07:00
Tom Jaspers
13eabe25dd "or"-operator tests on dbcore:parse_sorted_query 2015-04-16 10:04:32 +02:00
Bruno Cauet
bcd57bd2b5 Test queries building sort management in smartplaylist
Slighly modify Sort parsing: avoid building MultiplSort() instances
comptised of a single sort, but return that sort instead, since it wraps
things with any gain.
2015-03-18 18:53:41 +01:00
Bruno Cauet
9c41c39913 Do __name__ comparison with bytes and not unicode 2015-01-20 12:03:57 +01:00
Bruno Cauet
6fff7a954c Import unicode_literals in beets.dbcore 2015-01-19 17:18:50 +01:00
Bruno Cauet
90b388b775 Use __future__ imports but unicode_literals everywhere
Include import of __future__ features division, absolute_imports and
print_function everywhere. Don't add unicode_literals yet for it is
harder to convert.

Goal is smoothing the transition to python 3.
2015-01-19 12:25:16 +01:00
Bruno Cauet
2902cda036 tests: use absolute imports everywhere 2015-01-19 12:25:15 +01:00