Debian Codegraph @

test/ui/commands/test_list.py

raw
1 import os
2
3 import pytest
4
5 from beets.exceptions import UserError
6 from beets.test import _common
7 from beets.test.helper import BeetsTestCase, IOMixin
8
9
10 class ListTest(IOMixin, BeetsTestCase):
11 def setUp(self):
12 super().setUp()
13 self.item = _common.item(
14 path=os.fsencode(self.lib_path / "xxx/yyy"), flex=1
15 )
16 self.lib.add(self.item)
17 self.lib.add_album([self.item])
18 self.another_item = _common.item(
19 path=os.fsencode(self.lib_path / "another/path"), flex=2
20 )
21 self.lib.add(self.another_item)
22
23 def test_list_outputs_item(self):
24 stdout = self.run_with_output("list")
25 assert "the title" in stdout
26
27 def test_list_unicode_query(self):
28 self.item.title = "na\xefve"
29 self.item.store()
30 self.lib._connection().commit()
31
32 stdout = self.run_with_output("list", "na\xefve")
33 out = stdout
34 assert "na\xefve" in out
35
36 def test_list_item_path(self):
37 stdout = self.run_with_output("list", "flex:1", "-f", "$path")
38 assert stdout.strip() == str(self.lib_path / "xxx/yyy")
39
40 def test_list_album_outputs_something(self):
41 stdout = self.run_with_output("list", "-a")
42 assert len(stdout) > 0
43
44 def test_list_album_path(self):
45 stdout = self.run_with_output("list", "-a", "-f", "$path")
46 assert stdout.strip() == str(self.lib_path / "xxx")
47
48 def test_list_album_omits_title(self):
49 stdout = self.run_with_output("list", "-a")
50 assert "the title" not in stdout
51
52 def test_list_uses_track_artist(self):
53 stdout = self.run_with_output("list")
54 assert "the artist" in stdout
55 assert "the album artist" not in stdout
56
57 def test_list_album_uses_album_artist(self):
58 stdout = self.run_with_output("list", "-a")
59 assert "the artist" not in stdout
60 assert "the album artist" in stdout
61
62 def test_list_item_format_artist(self):
63 stdout = self.run_with_output("list", "-f", "$artist")
64 assert "the artist" in stdout
65
66 def test_list_item_format_multiple(self):
67 stdout = self.run_with_output(
68 "list", "flex:1", "-f", "$artist - $album - $year"
69 )
70 assert stdout.strip() == "the artist - the album - 0001"
71
72 def test_list_album_format(self):
73 stdout = self.run_with_output("list", "-a", "-f", "$genres")
74 assert "the genre" in stdout
75 assert "the album" not in stdout
76
77 def test_limit_query_results(self):
78 args = "list", "-p"
79
80 stdout = self.run_with_output(*args).strip()
81 assert len(stdout.splitlines()) == 2
82
83 stdout = self.run_with_output(*args, "-l", "1").strip()
84 assert len(stdout.splitlines()) == 1
85
86 with pytest.raises(UserError, match="must be a non-negative integer"):
87 self.run_with_output(*args, "-l", "-1")
88
89 def test_limit_sort_by_flex_attr(self):
90 args = "list", "-p", "-l", "1"
91
92 stdout = self.run_with_output(*args, "flex+").strip()
93 assert stdout == os.fsdecode(self.item.path)
94
95 stdout = self.run_with_output(*args, "flex-").strip()
96 assert stdout == os.fsdecode(self.another_item.path)