| 1 |
from unittest.mock import patch |
| 2 |
|
| 3 |
from beets import util |
| 4 |
from beets.library import Item |
| 5 |
from beets.test.helper import AsIsImporterMixin, ImportHelper, PluginMixin |
| 6 |
|
| 7 |
|
| 8 |
@patch("beets.util.command_output") |
| 9 |
class TestKeyFinder(AsIsImporterMixin, PluginMixin, ImportHelper): |
| 10 |
plugin = "keyfinder" |
| 11 |
|
| 12 |
def test_add_key(self, command_output): |
| 13 |
item = Item(path="/file") |
| 14 |
item.add(self.lib) |
| 15 |
|
| 16 |
command_output.return_value = util.CommandOutput(b"dbm", b"") |
| 17 |
self.run_command("keyfinder") |
| 18 |
|
| 19 |
item.load() |
| 20 |
assert item["initial_key"] == "C#m" |
| 21 |
command_output.assert_called_with( |
| 22 |
["KeyFinder", "-f", util.syspath(item.path)] |
| 23 |
) |
| 24 |
|
| 25 |
def test_add_key_on_import(self, command_output): |
| 26 |
command_output.return_value = util.CommandOutput(b"dbm", b"") |
| 27 |
self.run_asis_importer() |
| 28 |
|
| 29 |
item = self.lib.items().get() |
| 30 |
assert item["initial_key"] == "C#m" |
| 31 |
|
| 32 |
def test_force_overwrite(self, command_output): |
| 33 |
self.config["keyfinder"]["overwrite"] = True |
| 34 |
|
| 35 |
item = Item(path="/file", initial_key="F") |
| 36 |
item.add(self.lib) |
| 37 |
|
| 38 |
command_output.return_value = util.CommandOutput(b"C#m", b"") |
| 39 |
self.run_command("keyfinder") |
| 40 |
|
| 41 |
item.load() |
| 42 |
assert item["initial_key"] == "C#m" |
| 43 |
|
| 44 |
def test_do_not_overwrite(self, command_output): |
| 45 |
item = Item(path="/file", initial_key="F") |
| 46 |
item.add(self.lib) |
| 47 |
|
| 48 |
command_output.return_value = util.CommandOutput(b"dbm", b"") |
| 49 |
self.run_command("keyfinder") |
| 50 |
|
| 51 |
item.load() |
| 52 |
assert item["initial_key"] == "F" |
| 53 |
|
| 54 |
def test_no_key(self, command_output): |
| 55 |
item = Item(path="/file") |
| 56 |
item.add(self.lib) |
| 57 |
|
| 58 |
command_output.return_value = util.CommandOutput(b"", b"") |
| 59 |
self.run_command("keyfinder") |
| 60 |
|
| 61 |
item.load() |
| 62 |
assert item["initial_key"] is None |