Skip to content

Commit 6491c43

Browse files
committed
test(ftintitle): mock import task to exercise import hooks
1 parent d587916 commit 6491c43

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test/plugins/test_ftintitle.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
"""Tests for the 'ftintitle' plugin."""
1616

1717
from collections.abc import Generator
18+
from typing import cast
1819

1920
import pytest
2021

22+
from beets.importer import ImportSession, ImportTask
2123
from beets.library.models import Item
2224
from beets.test.helper import PluginTestCase
2325
from beetsplug import ftintitle
@@ -68,6 +70,16 @@ def add_item(
6870
)
6971

7072

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+
7183
@pytest.mark.parametrize(
7284
"cfg, cmd_args, given, expected",
7385
[
@@ -312,6 +324,31 @@ def test_ftintitle_functional(
312324
assert item["title"] == expected_title
313325

314326

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+
315352
@pytest.mark.parametrize(
316353
"artist,albumartist,expected",
317354
[

0 commit comments

Comments
 (0)