| 1 |
import pytest |
| 2 |
|
| 3 |
from beets.test.helper import IOMixin, PluginMixin, TestHelper |
| 4 |
|
| 5 |
|
| 6 |
class TestDuplicatesPlugin(PluginMixin, TestHelper, IOMixin): |
| 7 |
plugin = "duplicates" |
| 8 |
|
| 9 |
@pytest.fixture(autouse=True) |
| 10 |
def setup(self): |
| 11 |
self.setup_beets() |
| 12 |
self.dup_item = self.create_item( |
| 13 |
album="Pretend Album", |
| 14 |
albumartist="Pretend Artist", |
| 15 |
artist="Pretend Artist", |
| 16 |
title="Pretend Track", |
| 17 |
genres=["Original Genre"], |
| 18 |
mb_trackid="abc", |
| 19 |
mb_albumid="def", |
| 20 |
) |
| 21 |
try: |
| 22 |
yield |
| 23 |
finally: |
| 24 |
self.teardown_beets() |
| 25 |
self.dup_item = None |
| 26 |
|
| 27 |
def run_cmd(self, count=False, path=False) -> str: |
| 28 |
args = ["duplicates"] |
| 29 |
if count: |
| 30 |
args.append("--count") |
| 31 |
if path: |
| 32 |
args.append("--path") |
| 33 |
|
| 34 |
return self.run_with_output(*args).strip() |
| 35 |
|
| 36 |
def create_dups(self, count: int): |
| 37 |
for _ in range(count): |
| 38 |
self.lib.add(self.dup_item) |
| 39 |
|
| 40 |
def test_duplicate(self): |
| 41 |
self.create_dups(2) |
| 42 |
out = self.run_cmd() |
| 43 |
|
| 44 |
assert self.dup_item.artist in out |
| 45 |
assert self.dup_item.album in out |
| 46 |
assert self.dup_item.title in out |
| 47 |
|
| 48 |
def test_duplicate_path(self): |
| 49 |
self.create_dups(2) |
| 50 |
out = self.run_cmd(path=True) |
| 51 |
|
| 52 |
assert str(self.dup_item.filepath) in out |
| 53 |
|
| 54 |
def test_duplicate_with_count(self): |
| 55 |
self.create_dups(4) |
| 56 |
out = self.run_cmd(count=True) |
| 57 |
|
| 58 |
assert self.dup_item.artist in out |
| 59 |
assert self.dup_item.album in out |
| 60 |
assert self.dup_item.title in out |
| 61 |
assert out.endswith("3") |
| 62 |
|
| 63 |
def test_duplicate_path_with_count(self): |
| 64 |
self.create_dups(6) |
| 65 |
out = self.run_cmd(count=True, path=True) |
| 66 |
|
| 67 |
assert str(self.dup_item.filepath) in out |
| 68 |
assert out.endswith("5") |