Debian Codegraph @

test/plugins/test_badfiles.py

raw
1 """Tests for the 'badfiles' plugin."""
2
3 from types import SimpleNamespace
4 from unittest.mock import patch
5
6 from beets import importer
7 from beets.test.helper import (
8 AutotagImportTestCase,
9 PluginMixin,
10 PluginTestCase,
11 TerminalImportMixin,
12 )
13 from beetsplug.badfiles import BadFiles
14
15
16 class BadFilesPluginTest(PluginTestCase):
17 plugin = "badfiles"
18
19 def test_quiet_import_skips_prompt(self):
20 plugin = BadFiles()
21 task = SimpleNamespace(_badfiles_checks_failed=[["bad: error"]])
22
23 self.config["import"]["quiet"] = True
24
25 with patch("beetsplug.badfiles.ui.input_options", return_value="s"):
26 result = plugin.on_import_task_before_choice(task, session=None)
27
28 assert result is None
29
30 def test_non_quiet_import_calls_prompt(self):
31 plugin = BadFiles()
32 task = SimpleNamespace(_badfiles_checks_failed=[["bad: error"]])
33
34 self.config["import"]["quiet"] = False
35
36 with patch("beetsplug.badfiles.ui.input_options", return_value="s"):
37 result = plugin.on_import_task_before_choice(task, session=None)
38
39 assert result == importer.Action.SKIP
40
41
42 class BadfilesOnImportTest(
43 TerminalImportMixin, PluginMixin, AutotagImportTestCase
44 ):
45 plugin = "badfiles"
46
47 def setUp(self):
48 super().setUp()
49 self.prepare_album_for_import(1)
50 self.importer = self.setup_importer()
51
52 def test_play_on_import(self):
53 BadFiles()
54 self.importer.add_choice("b")
55 checker = self.temp_path / "checker"
56 checker.write_text("#!/bin/sh\nexit 1")
57 checker.chmod(0o755)
58 with self.configure_plugin(
59 {"check_on_import": True, "commands": {"mp3": str(checker)}}
60 ):
61 self.importer.run()
62
63 assert not self.lib.items()