| 1 |
import os |
| 2 |
|
| 3 |
from mediafile import MediaFile |
| 4 |
|
| 5 |
from beets.test.helper import IOMixin, PluginTestCase |
| 6 |
|
| 7 |
|
| 8 |
class InfoTest(IOMixin, PluginTestCase): |
| 9 |
plugin = "info" |
| 10 |
|
| 11 |
def test_path(self): |
| 12 |
path = self.create_mediafile_fixture() |
| 13 |
|
| 14 |
mediafile = MediaFile(path) |
| 15 |
mediafile.albumartist = "AAA" |
| 16 |
mediafile.disctitle = "DDD" |
| 17 |
mediafile.genres = ["a", "b", "c"] |
| 18 |
mediafile.composer = None |
| 19 |
mediafile.save() |
| 20 |
|
| 21 |
out = self.run_with_output("info", str(path)) |
| 22 |
assert os.fsdecode(path) in out |
| 23 |
assert "albumartist: AAA" in out |
| 24 |
assert "disctitle: DDD" in out |
| 25 |
assert "genres: a; b; c" in out |
| 26 |
assert "composer:" not in out |
| 27 |
|
| 28 |
def test_item_query(self): |
| 29 |
item1, item2 = self.add_item_fixtures(count=2) |
| 30 |
item1.album = "xxxx" |
| 31 |
item1.write() |
| 32 |
item1.album = "yyyy" |
| 33 |
item1.store() |
| 34 |
|
| 35 |
out = self.run_with_output("info", "album:yyyy") |
| 36 |
assert str(item1.filepath) in out |
| 37 |
assert "album: xxxx" in out |
| 38 |
|
| 39 |
assert str(item2.filepath) not in out |
| 40 |
|
| 41 |
def test_item_library_query(self): |
| 42 |
(item,) = self.add_item_fixtures() |
| 43 |
item.album = "xxxx" |
| 44 |
item.store() |
| 45 |
|
| 46 |
out = self.run_with_output("info", "--library", "album:xxxx") |
| 47 |
assert str(item.filepath) in out |
| 48 |
assert "album: xxxx" in out |
| 49 |
|
| 50 |
def test_collect_item_and_path(self): |
| 51 |
path = self.create_mediafile_fixture() |
| 52 |
mediafile = MediaFile(path) |
| 53 |
(item,) = self.add_item_fixtures() |
| 54 |
|
| 55 |
item.album = mediafile.album = "AAA" |
| 56 |
item.tracktotal = mediafile.tracktotal = 5 |
| 57 |
item.title = "TTT" |
| 58 |
mediafile.title = "SSS" |
| 59 |
|
| 60 |
item.write() |
| 61 |
item.store() |
| 62 |
mediafile.save() |
| 63 |
|
| 64 |
out = self.run_with_output( |
| 65 |
"info", "--summarize", "album:AAA", str(path) |
| 66 |
) |
| 67 |
assert "album: AAA" in out |
| 68 |
assert "tracktotal: 5" in out |
| 69 |
assert "title: [various]" in out |
| 70 |
|
| 71 |
def test_collect_item_and_path_with_multi_values(self): |
| 72 |
path = self.create_mediafile_fixture() |
| 73 |
mediafile = MediaFile(path) |
| 74 |
(item,) = self.add_item_fixtures() |
| 75 |
|
| 76 |
item.album = mediafile.album = "AAA" |
| 77 |
item.tracktotal = mediafile.tracktotal = 5 |
| 78 |
item.title = "TTT" |
| 79 |
mediafile.title = "SSS" |
| 80 |
|
| 81 |
item.albumartists = ["Artist A", "Artist B"] |
| 82 |
mediafile.albumartists = ["Artist C", "Artist D"] |
| 83 |
|
| 84 |
item.artists = ["Artist A", "Artist Z"] |
| 85 |
mediafile.artists = ["Artist A", "Artist Z"] |
| 86 |
|
| 87 |
item.write() |
| 88 |
item.store() |
| 89 |
mediafile.save() |
| 90 |
|
| 91 |
out = self.run_with_output( |
| 92 |
"info", "--summarize", "album:AAA", str(path) |
| 93 |
) |
| 94 |
assert "album: AAA" in out |
| 95 |
assert "tracktotal: 5" in out |
| 96 |
assert "title: [various]" in out |
| 97 |
assert "albumartists: [various]" in out |
| 98 |
assert "artists: Artist A; Artist Z" in out |
| 99 |
|
| 100 |
def test_custom_format(self): |
| 101 |
self.add_item_fixtures() |
| 102 |
out = self.run_with_output( |
| 103 |
"info", |
| 104 |
"--library", |
| 105 |
"--format", |
| 106 |
"$track. $title - $artist ($length)", |
| 107 |
) |
| 108 |
assert "02. tïtle 0 - the artist (0:01)\n" == out |