| 1 |
"""Tests for the fuzzy query plugin.""" |
| 2 |
|
| 3 |
import pytest |
| 4 |
|
| 5 |
from beets.test.helper import PluginTestHelper |
| 6 |
|
| 7 |
|
| 8 |
class TestFuzzyPlugin(PluginTestHelper): |
| 9 |
plugin = "fuzzy" |
| 10 |
|
| 11 |
@pytest.mark.parametrize( |
| 12 |
"query,expected_titles", |
| 13 |
[ |
| 14 |
pytest.param("~foo", ["seafood"], id="all-fields-substring"), |
| 15 |
pytest.param("title:~foo", ["seafood"], id="field-substring"), |
| 16 |
pytest.param("~seafood", ["seafood"], id="all-fields-equal-length"), |
| 17 |
pytest.param("~zzz", [], id="all-fields-no-match"), |
| 18 |
], |
| 19 |
) |
| 20 |
def test_fuzzy_queries(self, query, expected_titles): |
| 21 |
self.add_item(title="seafood", artist="alpha") |
| 22 |
self.add_item(title="bread", artist="beta") |
| 23 |
|
| 24 |
with self.configure_plugin({}): |
| 25 |
items = self.lib.items(query) |
| 26 |
|
| 27 |
assert [item.title for item in items] == expected_titles |