Debian Codegraph @

test/plugins/test_autobpm.py

raw
1 import pytest
2
3 from beets.test.helper import ImportHelper, PluginTestHelper
4
5 pytestmark = pytest.mark.requires_import("librosa")
6
7
8 class TestAutoBPMPlugin(ImportHelper, PluginTestHelper):
9 plugin = "autobpm"
10
11 @pytest.fixture
12 def item(self):
13 return self.add_item_fixture()
14
15 @pytest.fixture
16 def importer(self):
17 self.import_media = []
18 self.prepare_album_for_import(1)
19 track = self.import_media[0]
20 track.bpm = None
21 track.save()
22 return self.setup_importer(autotag=False)
23
24 def test_command(self, item):
25 item.bpm = None
26 item.store()
27 self.run_command("autobpm")
28
29 item.load()
30 assert item.bpm == 117
31
32 def test_command_force(self, item):
33 item.bpm = 10
34 item.store()
35
36 self.run_command("autobpm")
37 item.load()
38 assert item.bpm == 10
39
40 self.run_command("autobpm", "--force")
41 item.load()
42 assert item.bpm == 117
43
44 def test_command_overwrite(self, item):
45 item.bpm = 10
46 item.store()
47
48 self.unload_plugins()
49 self.config[self.plugin]["overwrite"] = True
50 self.load_plugins()
51
52 self.run_command("autobpm")
53 item.load()
54 assert item.bpm == 117
55
56 def test_command_quiet(self, item, caplog):
57 item.bpm = 10
58 item.store()
59
60 with caplog.at_level("DEBUG"):
61 self.run_command("autobpm", "--quiet")
62 assert not any("already exists" in msg for msg in caplog.messages)
63
64 with caplog.at_level("DEBUG"):
65 self.run_command("autobpm")
66 assert any("already exists" in msg for msg in caplog.messages)
67
68 def test_import(self, importer):
69 importer.run()
70
71 assert self.lib.items().get().bpm == 117