Debian Codegraph @

test/plugins/test_filefilter.py

raw
1 """Tests for the `filefilter` plugin."""
2
3 from beets.test.helper import ImportHelper, PluginMixin
4
5
6 class FileFilterPluginHelper(PluginMixin, ImportHelper):
7 plugin = "filefilter"
8 preload_plugin = False
9
10 def setup_beets(self):
11 super().setup_beets()
12 self.prepare_tracks_for_import()
13
14 def prepare_tracks_for_import(self):
15 self.album_track, self.other_album_track, self.single_track = (
16 self.prepare_album_for_import(1, album_path=p)[0]
17 for p in [
18 self.import_path / "album",
19 self.import_path / "other_album",
20 self.import_path,
21 ]
22 )
23 self.all_tracks = {
24 self.album_track,
25 self.other_album_track,
26 self.single_track,
27 }
28
29 def _run(self, config, expected_album_count, expected_paths):
30 with self.configure_plugin(config):
31 self.importer.run()
32
33 assert len(self.lib.albums()) == expected_album_count
34 assert {i.filepath for i in self.lib.items()} == expected_paths
35
36
37 class TestFileFilterPluginNonSingleton(FileFilterPluginHelper):
38 def setup_beets(self):
39 super().setup_beets()
40 self.importer = self.setup_importer(autotag=False, copy=False)
41
42 def test_import_default(self):
43 """The default configuration should import everything."""
44 self._run({}, 3, self.all_tracks)
45
46 def test_import_nothing(self):
47 self._run({"path": "not_there"}, 0, set())
48
49 def test_global_config(self):
50 self._run(
51 {"path": ".*album.*"}, 2, {self.album_track, self.other_album_track}
52 )
53
54 def test_album_config(self):
55 self._run(
56 {"album_path": ".*other_album.*"}, 1, {self.other_album_track}
57 )
58
59 def test_singleton_config(self):
60 """Check that singleton configuration is ignored for album import."""
61 self._run({"singleton_path": ".*other_album.*"}, 3, self.all_tracks)
62
63
64 class TestFileFilterPluginSingleton(FileFilterPluginHelper):
65 def setup_beets(self):
66 super().setup_beets()
67 self.importer = self.setup_singleton_importer(autotag=False, copy=False)
68
69 def test_global_config(self):
70 self._run(
71 {"path": ".*album.*"}, 0, {self.album_track, self.other_album_track}
72 )
73
74 def test_album_config(self):
75 """Check that album configuration is ignored for singleton import."""
76 self._run({"album_path": ".*other_album.*"}, 0, self.all_tracks)
77
78 def test_singleton_config(self):
79 self._run(
80 {"singleton_path": ".*other_album.*"}, 0, {self.other_album_track}
81 )