|
15 | 15 | """Tests for the 'ftintitle' plugin.""" |
16 | 16 |
|
17 | 17 | from collections.abc import Generator |
| 18 | +from typing import cast |
18 | 19 |
|
19 | 20 | import pytest |
20 | 21 |
|
| 22 | +from beets.importer import ImportSession, ImportTask |
21 | 23 | from beets.library.models import Item |
22 | 24 | from beets.test.helper import PluginTestCase |
23 | 25 | from beetsplug import ftintitle |
@@ -68,6 +70,16 @@ def add_item( |
68 | 70 | ) |
69 | 71 |
|
70 | 72 |
|
| 73 | +class DummyImportTask: |
| 74 | + """Minimal stand-in for ImportTask used to exercise import hooks.""" |
| 75 | + |
| 76 | + def __init__(self, items: list[Item]) -> None: |
| 77 | + self._items = items |
| 78 | + |
| 79 | + def imported_items(self) -> list[Item]: |
| 80 | + return self._items |
| 81 | + |
| 82 | + |
71 | 83 | @pytest.mark.parametrize( |
72 | 84 | "cfg, cmd_args, given, expected", |
73 | 85 | [ |
@@ -312,6 +324,31 @@ def test_ftintitle_functional( |
312 | 324 | assert item["title"] == expected_title |
313 | 325 |
|
314 | 326 |
|
| 327 | +def test_imported_stage_moves_featured_artist( |
| 328 | + env: FtInTitlePluginFunctional, |
| 329 | +) -> None: |
| 330 | + """The import-stage hook should fetch config settings and process items.""" |
| 331 | + set_config(env, None) |
| 332 | + plugin = ftintitle.FtInTitlePlugin() |
| 333 | + item = add_item( |
| 334 | + env, |
| 335 | + "/imported-hook", |
| 336 | + "Alice feat. Bob", |
| 337 | + "Song 1 (Carol Remix)", |
| 338 | + "Various Artists", |
| 339 | + ) |
| 340 | + task = DummyImportTask([item]) |
| 341 | + |
| 342 | + plugin.imported( |
| 343 | + cast(ImportSession, None), |
| 344 | + cast(ImportTask, task), |
| 345 | + ) |
| 346 | + item.load() |
| 347 | + |
| 348 | + assert item["artist"] == "Alice" |
| 349 | + assert item["title"] == "Song 1 feat. Bob (Carol Remix)" |
| 350 | + |
| 351 | + |
315 | 352 | @pytest.mark.parametrize( |
316 | 353 | "artist,albumartist,expected", |
317 | 354 | [ |
|
0 commit comments