|
| 1 | +# This file is part of beets. |
| 2 | +# |
| 3 | +# Permission is hereby granted, free of charge, to any person obtaining |
| 4 | +# a copy of this software and associated documentation files (the |
| 5 | +# "Software"), to deal in the Software without restriction, including |
| 6 | +# without limitation the rights to use, copy, modify, merge, publish, |
| 7 | +# distribute, sublicense, and/or sell copies of the Software, and to |
| 8 | +# permit persons to whom the Software is furnished to do so, subject to |
| 9 | +# the following conditions: |
| 10 | +# |
| 11 | +# The above copyright notice and this permission notice shall be |
| 12 | +# included in all copies or substantial portions of the Software. |
| 13 | + |
| 14 | +"""Tests for the fromfilename plugin.""" |
| 15 | + |
| 16 | +import pytest |
| 17 | + |
| 18 | +from beetsplug import fromfilename |
| 19 | + |
| 20 | + |
| 21 | +class Session: |
| 22 | + pass |
| 23 | + |
| 24 | + |
| 25 | +class Item: |
| 26 | + def __init__(self, path): |
| 27 | + self.path = path |
| 28 | + self.track = 0 |
| 29 | + self.artist = "" |
| 30 | + self.title = "" |
| 31 | + |
| 32 | + |
| 33 | +class Task: |
| 34 | + def __init__(self, items): |
| 35 | + self.items = items |
| 36 | + self.is_album = True |
| 37 | + |
| 38 | + |
| 39 | +@pytest.mark.parametrize( |
| 40 | + "song1, song2", |
| 41 | + [ |
| 42 | + ( |
| 43 | + ( |
| 44 | + "/tmp/01 - The Artist - Song One.m4a", |
| 45 | + 1, |
| 46 | + "The Artist", |
| 47 | + "Song One", |
| 48 | + ), |
| 49 | + ( |
| 50 | + "/tmp/02. - The Artist - Song Two.m4a", |
| 51 | + 2, |
| 52 | + "The Artist", |
| 53 | + "Song Two", |
| 54 | + ), |
| 55 | + ), |
| 56 | + ( |
| 57 | + ("/tmp/01-The_Artist-Song_One.m4a", 1, "The_Artist", "Song_One"), |
| 58 | + ("/tmp/02.-The_Artist-Song_Two.m4a", 2, "The_Artist", "Song_Two"), |
| 59 | + ), |
| 60 | + ( |
| 61 | + ("/tmp/01 - Song_One.m4a", 1, "", "Song_One"), |
| 62 | + ("/tmp/02. - Song_Two.m4a", 2, "", "Song_Two"), |
| 63 | + ), |
| 64 | + ( |
| 65 | + ("/tmp/Song One by The Artist.m4a", 0, "The Artist", "Song One"), |
| 66 | + ("/tmp/Song Two by The Artist.m4a", 0, "The Artist", "Song Two"), |
| 67 | + ), |
| 68 | + (("/tmp/01.m4a", 1, "", "01"), ("/tmp/02.m4a", 2, "", "02")), |
| 69 | + ( |
| 70 | + ("/tmp/Song One.m4a", 0, "", "Song One"), |
| 71 | + ("/tmp/Song Two.m4a", 0, "", "Song Two"), |
| 72 | + ), |
| 73 | + ], |
| 74 | +) |
| 75 | +def test_fromfilename(song1, song2): |
| 76 | + """ |
| 77 | + Each "song" is a tuple of path, expected track number, expected artist, |
| 78 | + expected title. |
| 79 | +
|
| 80 | + We use two songs for each test for two reasons: |
| 81 | + - The plugin needs more than one item to look for uniform strings in paths |
| 82 | + in order to guess if the string describes an artist or a title. |
| 83 | + - Sometimes we allow for an optional "." after the track number in paths. |
| 84 | + """ |
| 85 | + |
| 86 | + session = Session() |
| 87 | + item1 = Item(song1[0]) |
| 88 | + item2 = Item(song2[0]) |
| 89 | + task = Task([item1, item2]) |
| 90 | + |
| 91 | + f = fromfilename.FromFilenamePlugin() |
| 92 | + f.filename_task(task, session) |
| 93 | + |
| 94 | + assert task.items[0].track == song1[1] |
| 95 | + assert task.items[0].artist == song1[2] |
| 96 | + assert task.items[0].title == song1[3] |
| 97 | + assert task.items[1].track == song2[1] |
| 98 | + assert task.items[1].artist == song2[2] |
| 99 | + assert task.items[1].title == song2[3] |
0 commit comments