File: test_info.py

package info (click to toggle)
beets 2.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 7,988 kB
  • sloc: python: 46,429; javascript: 8,018; xml: 334; sh: 261; makefile: 125
file content (118 lines) | stat: -rw-r--r-- 3,833 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# This file is part of beets.
# Copyright 2016, Thomas Scholtes.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.


from mediafile import MediaFile

from beets.test.helper import PluginTestCase
from beets.util import displayable_path


class InfoTest(PluginTestCase):
    plugin = "info"

    def test_path(self):
        path = self.create_mediafile_fixture()

        mediafile = MediaFile(path)
        mediafile.albumartist = "AAA"
        mediafile.disctitle = "DDD"
        mediafile.genres = ["a", "b", "c"]
        mediafile.composer = None
        mediafile.save()

        out = self.run_with_output("info", path)
        assert displayable_path(path) in out
        assert "albumartist: AAA" in out
        assert "disctitle: DDD" in out
        assert "genres: a; b; c" in out
        assert "composer:" not in out

    def test_item_query(self):
        item1, item2 = self.add_item_fixtures(count=2)
        item1.album = "xxxx"
        item1.write()
        item1.album = "yyyy"
        item1.store()

        out = self.run_with_output("info", "album:yyyy")
        assert displayable_path(item1.path) in out
        assert "album: xxxx" in out

        assert displayable_path(item2.path) not in out

    def test_item_library_query(self):
        (item,) = self.add_item_fixtures()
        item.album = "xxxx"
        item.store()

        out = self.run_with_output("info", "--library", "album:xxxx")
        assert displayable_path(item.path) in out
        assert "album: xxxx" in out

    def test_collect_item_and_path(self):
        path = self.create_mediafile_fixture()
        mediafile = MediaFile(path)
        (item,) = self.add_item_fixtures()

        item.album = mediafile.album = "AAA"
        item.tracktotal = mediafile.tracktotal = 5
        item.title = "TTT"
        mediafile.title = "SSS"

        item.write()
        item.store()
        mediafile.save()

        out = self.run_with_output("info", "--summarize", "album:AAA", path)
        assert "album: AAA" in out
        assert "tracktotal: 5" in out
        assert "title: [various]" in out

    def test_collect_item_and_path_with_multi_values(self):
        path = self.create_mediafile_fixture()
        mediafile = MediaFile(path)
        (item,) = self.add_item_fixtures()

        item.album = mediafile.album = "AAA"
        item.tracktotal = mediafile.tracktotal = 5
        item.title = "TTT"
        mediafile.title = "SSS"

        item.albumartists = ["Artist A", "Artist B"]
        mediafile.albumartists = ["Artist C", "Artist D"]

        item.artists = ["Artist A", "Artist Z"]
        mediafile.artists = ["Artist A", "Artist Z"]

        item.write()
        item.store()
        mediafile.save()

        out = self.run_with_output("info", "--summarize", "album:AAA", path)
        assert "album: AAA" in out
        assert "tracktotal: 5" in out
        assert "title: [various]" in out
        assert "albumartists: [various]" in out
        assert "artists: Artist A; Artist Z" in out

    def test_custom_format(self):
        self.add_item_fixtures()
        out = self.run_with_output(
            "info",
            "--library",
            "--format",
            "$track. $title - $artist ($length)",
        )
        assert "02. tïtle 0 - the artist (0:01)\n" == out