Debian Codegraph @

test/plugins/test_fromfilename.py

raw
1 """Tests for the fromfilename plugin."""
2
3 import pytest
4
5 from beetsplug import fromfilename
6
7
8 class Session:
9 pass
10
11
12 class Item:
13 def __init__(self, path):
14 self.path = path
15 self.track = 0
16 self.artist = ""
17 self.title = ""
18
19
20 class Task:
21 def __init__(self, items):
22 self.items = items
23 self.is_album = True
24
25
26 @pytest.mark.parametrize(
27 "song1, song2",
28 [
29 (
30 (
31 "/tmp/01 - The Artist - Song One.m4a",
32 1,
33 "The Artist",
34 "Song One",
35 ),
36 (
37 "/tmp/02. - The Artist - Song Two.m4a",
38 2,
39 "The Artist",
40 "Song Two",
41 ),
42 ),
43 (
44 ("/tmp/01-The_Artist-Song_One.m4a", 1, "The_Artist", "Song_One"),
45 ("/tmp/02.-The_Artist-Song_Two.m4a", 2, "The_Artist", "Song_Two"),
46 ),
47 (
48 ("/tmp/01 - Song_One.m4a", 1, "", "Song_One"),
49 ("/tmp/02. - Song_Two.m4a", 2, "", "Song_Two"),
50 ),
51 (
52 ("/tmp/Song One by The Artist.m4a", 0, "The Artist", "Song One"),
53 ("/tmp/Song Two by The Artist.m4a", 0, "The Artist", "Song Two"),
54 ),
55 (("/tmp/01.m4a", 1, "", "01"), ("/tmp/02.m4a", 2, "", "02")),
56 (
57 ("/tmp/Song One.m4a", 0, "", "Song One"),
58 ("/tmp/Song Two.m4a", 0, "", "Song Two"),
59 ),
60 (
61 ("/tmp/track01.m4a", 1, "", "track01"),
62 ("/tmp/track 2.m4a", 2, "", "track 2"),
63 ),
64 ],
65 )
66 def test_fromfilename(song1, song2):
67 """
68 Each "song" is a tuple of path, expected track number, expected artist,
69 expected title.
70
71 We use two songs for each test for two reasons:
72 - The plugin needs more than one item to look for uniform strings in paths
73 in order to guess if the string describes an artist or a title.
74 - Sometimes we allow for an optional "." after the track number in paths.
75 """
76
77 session = Session()
78 item1 = Item(song1[0])
79 item2 = Item(song2[0])
80 task = Task([item1, item2])
81
82 f = fromfilename.FromFilenamePlugin()
83 f.filename_task(task, session)
84
85 assert task.items[0].track == song1[1]
86 assert task.items[0].artist == song1[2]
87 assert task.items[0].title == song1[3]
88 assert task.items[1].track == song2[1]
89 assert task.items[1].artist == song2[2]
90 assert task.items[1].title == song2[3]