File: test_fromfilename.py

package info (click to toggle)
beets 2.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,016 kB
  • sloc: python: 46,429; javascript: 8,018; xml: 334; sh: 261; makefile: 125
file content (99 lines) | stat: -rw-r--r-- 2,953 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# This file is part of beets.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.

"""Tests for the fromfilename plugin."""

import pytest

from beetsplug import fromfilename


class Session:
    pass


class Item:
    def __init__(self, path):
        self.path = path
        self.track = 0
        self.artist = ""
        self.title = ""


class Task:
    def __init__(self, items):
        self.items = items
        self.is_album = True


@pytest.mark.parametrize(
    "song1, song2",
    [
        (
            (
                "/tmp/01 - The Artist - Song One.m4a",
                1,
                "The Artist",
                "Song One",
            ),
            (
                "/tmp/02. - The Artist - Song Two.m4a",
                2,
                "The Artist",
                "Song Two",
            ),
        ),
        (
            ("/tmp/01-The_Artist-Song_One.m4a", 1, "The_Artist", "Song_One"),
            ("/tmp/02.-The_Artist-Song_Two.m4a", 2, "The_Artist", "Song_Two"),
        ),
        (
            ("/tmp/01 - Song_One.m4a", 1, "", "Song_One"),
            ("/tmp/02. - Song_Two.m4a", 2, "", "Song_Two"),
        ),
        (
            ("/tmp/Song One by The Artist.m4a", 0, "The Artist", "Song One"),
            ("/tmp/Song Two by The Artist.m4a", 0, "The Artist", "Song Two"),
        ),
        (("/tmp/01.m4a", 1, "", "01"), ("/tmp/02.m4a", 2, "", "02")),
        (
            ("/tmp/Song One.m4a", 0, "", "Song One"),
            ("/tmp/Song Two.m4a", 0, "", "Song Two"),
        ),
    ],
)
def test_fromfilename(song1, song2):
    """
    Each "song" is a tuple of path, expected track number, expected artist,
    expected title.

    We use two songs for each test for two reasons:
    - The plugin needs more than one item to look for uniform strings in paths
      in order to guess if the string describes an artist or a title.
    - Sometimes we allow for an optional "." after the track number in paths.
    """

    session = Session()
    item1 = Item(song1[0])
    item2 = Item(song2[0])
    task = Task([item1, item2])

    f = fromfilename.FromFilenamePlugin()
    f.filename_task(task, session)

    assert task.items[0].track == song1[1]
    assert task.items[0].artist == song1[2]
    assert task.items[0].title == song1[3]
    assert task.items[1].track == song2[1]
    assert task.items[1].artist == song2[2]
    assert task.items[1].title == song2[3]