Debian Codegraph @

test/ui/commands/test_remove.py

raw
1 from beets import library
2 from beets.test.helper import BeetsTestCase, IOMixin
3 from beets.util import MoveOperation
4
5
6 class RemoveTest(IOMixin, BeetsTestCase):
7 def setUp(self):
8 super().setUp()
9
10 # Copy a file into the library.
11 self.i = library.Item.from_path(self.resource_path)
12 self.lib.add(self.i)
13 self.i.move(operation=MoveOperation.COPY)
14
15 def test_remove_items_no_delete(self):
16 self.io.addinput("y")
17 self.run_command("remove")
18 items = self.lib.items()
19 assert len(list(items)) == 0
20 assert self.i.filepath.exists()
21
22 def test_remove_albums_no_delete(self):
23 album = self.add_album_fixture(2)
24 self.io.addinput("y")
25 output = self.run_with_output("remove", "-a")
26 items = self.lib.items(f"album:{album.album}")
27 assert len(list(items)) == 0
28 assert "Really remove 2 items and 1 album from the library?" in output
29
30 def test_remove_items_with_delete(self):
31 self.io.addinput("y")
32 self.run_command("remove", "-d")
33 items = self.lib.items()
34 assert len(list(items)) == 0
35 assert not self.i.filepath.exists()
36
37 def test_remove_items_with_force_no_delete(self):
38 self.run_command("remove", "-f")
39 items = self.lib.items()
40 assert len(list(items)) == 0
41 assert self.i.filepath.exists()
42
43 def test_remove_items_with_force_delete(self):
44 self.run_command("remove", "-d", "-f")
45 items = self.lib.items()
46 assert len(list(items)) == 0
47 assert not self.i.filepath.exists()
48
49 def test_remove_items_select_with_delete(self):
50 i2 = library.Item.from_path(self.resource_path)
51 self.lib.add(i2)
52 i2.move(operation=MoveOperation.COPY)
53
54 for s in ("s", "y", "n"):
55 self.io.addinput(s)
56 output = self.run_with_output("remove", "-d")
57 assert "Really DELETE 2 files?" in output
58 items = self.lib.items()
59 assert len(list(items)) == 1
60 # There is probably no guarantee that the items are queried in any
61 # spcecific order, thus just ensure that exactly one was removed.
62 # To improve upon this, self.io would need to have the capability to
63 # generate input that depends on previous output.
64 num_existing = 0
65 num_existing += 1 if self.i.filepath.exists() else 0
66 num_existing += 1 if i2.filepath.exists() else 0
67 assert num_existing == 1
68
69 def test_remove_albums_select_with_delete(self):
70 a1 = self.add_album_fixture()
71 a2 = self.add_album_fixture()
72 path1 = a1.items()[0].filepath
73 path2 = a2.items()[0].filepath
74 items = self.lib.items()
75 assert len(list(items)) == 3
76
77 for s in ("s", "y", "n"):
78 self.io.addinput(s)
79 output = self.run_with_output("remove", "-d", "-a")
80 assert "Really DELETE 2 files and 2 albums?" in output
81
82 items = self.lib.items()
83 assert len(list(items)) == 2 # incl. the item from setUp()
84 # See test_remove_items_select_with_delete()
85 num_existing = 0
86 num_existing += 1 if path1.exists() else 0
87 num_existing += 1 if path2.exists() else 0
88 assert num_existing == 1