File: test_tagger_message_parsing.py

package info (click to toggle)
picard 2.13.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,012 kB
  • sloc: python: 68,818; ansic: 89; makefile: 14
file content (79 lines) | stat: -rw-r--r-- 2,949 bytes parent folder | download | duplicates (2)
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
# -*- coding: utf-8 -*-
#
# Picard, the next-generation MusicBrainz tagger
#
# Copyright (C) 2022 skelly37
# Copyright (C) 2022 Bob Swift
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

from test.picardtestcase import PicardTestCase

from picard.const.sys import IS_WIN
from picard.tagger import ParseItemsToLoad


class TestMessageParsing(PicardTestCase):
    def test(self):
        test_cases = {
            "test_case.mp3",
            "file:///home/picard/music/test.flac",
            "mbid://recording/7cd3782d-86dc-4dd1-8d9b-e37f9cbe6b94",
            "https://musicbrainz.org/recording/7cd3782d-86dc-4dd1-8d9b-e37f9cbe6b94",
            "http://musicbrainz.org/recording/7cd3782d-86dc-4dd1-8d9b-e37f9cbe6b94",
        }

        result = ParseItemsToLoad(test_cases)
        self.assertSetEqual(result.files, {"test_case.mp3", "/home/picard/music/test.flac"}, "Files test")
        self.assertSetEqual(result.mbids, {"recording/7cd3782d-86dc-4dd1-8d9b-e37f9cbe6b94"}, "MBIDs test")
        self.assertSetEqual(result.urls, {"recording/7cd3782d-86dc-4dd1-8d9b-e37f9cbe6b94",
            "recording/7cd3782d-86dc-4dd1-8d9b-e37f9cbe6b94"}, "URLs test")

    def test_bool_files_true(self):
        test_cases = {
            "test_case.mp3",
        }
        self.assertTrue(ParseItemsToLoad(test_cases))

    def test_bool_mbids_true(self):
        test_cases = {
            "mbid://recording/7cd3782d-86dc-4dd1-8d9b-e37f9cbe6b94",
        }
        self.assertTrue(ParseItemsToLoad(test_cases))

    def test_bool_urls_true(self):
        test_cases = {
            "https://musicbrainz.org/recording/7cd3782d-86dc-4dd1-8d9b-e37f9cbe6b94",
        }
        self.assertTrue(ParseItemsToLoad(test_cases))

    def test_bool_invalid_false(self):
        test_cases = {
            "mbd://recording/7cd3782d-86dc-4dd1-8d9b-e37f9cbe6b94",
        }
        self.assertFalse(ParseItemsToLoad(test_cases))

    def test_bool_empty_false(self):
        test_cases = {}
        self.assertFalse(ParseItemsToLoad(test_cases))

    def test_windows_file_with_drive(self):
        test_cases = {
            "C:\\test_case.mp3",
        }
        if IS_WIN:
            self.assertTrue(ParseItemsToLoad(test_cases))
        else:
            self.assertFalse(ParseItemsToLoad(test_cases))