File: test_scan.py

package info (click to toggle)
mopidy 3.4.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 2,616 kB
  • sloc: python: 16,656; sh: 159; makefile: 126
file content (122 lines) | stat: -rw-r--r-- 3,831 bytes parent folder | download | duplicates (3)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import unittest

from mopidy import exceptions
from mopidy.audio import scan
from mopidy.internal.path import path_to_uri

from tests import path_to_data_dir


class ScannerTest(unittest.TestCase):
    def setUp(self):  # noqa: N802
        self.errors = {}
        self.result = {}

    def find(self, path):
        dir_path = path_to_data_dir(path)
        if not dir_path.is_dir():
            return
        for file_path in dir_path.iterdir():
            yield dir_path / file_path

    def scan(self, paths):
        scanner = scan.Scanner()
        for path in paths:
            uri = path_to_uri(path)
            try:
                self.result[path] = scanner.scan(uri)
            except exceptions.ScannerError as error:
                self.errors[path] = error

    def check(self, name, key, value):
        name = path_to_data_dir(name)
        assert self.result[name].tags[key] == value

    def check_if_missing_plugin(self):
        for path, result in self.result.items():
            if path.suffix != ".mp3":
                continue
            if not result.playable and result.mime == "audio/mpeg":
                raise unittest.SkipTest("Missing MP3 support?")

    def test_tags_is_set(self):
        self.scan(self.find("scanner/simple"))

        assert list(self.result.values())[0].tags

    def test_errors_is_not_set(self):
        self.scan(self.find("scanner/simple"))

        self.check_if_missing_plugin()

        assert not self.errors

    def test_duration_is_set(self):
        self.scan(self.find("scanner/simple"))

        self.check_if_missing_plugin()

        ogg = path_to_data_dir("scanner/simple/song1.ogg")
        mp3 = path_to_data_dir("scanner/simple/song1.mp3")
        assert self.result[mp3].duration == 4608
        assert self.result[ogg].duration == 4704

    def test_artist_is_set(self):
        self.scan(self.find("scanner/simple"))

        self.check_if_missing_plugin()

        self.check("scanner/simple/song1.mp3", "artist", ["name"])
        self.check("scanner/simple/song1.ogg", "artist", ["name"])

    def test_album_is_set(self):
        self.scan(self.find("scanner/simple"))

        self.check_if_missing_plugin()

        self.check("scanner/simple/song1.mp3", "album", ["albumname"])
        self.check("scanner/simple/song1.ogg", "album", ["albumname"])

    def test_track_is_set(self):
        self.scan(self.find("scanner/simple"))

        self.check_if_missing_plugin()

        self.check("scanner/simple/song1.mp3", "title", ["trackname"])
        self.check("scanner/simple/song1.ogg", "title", ["trackname"])

    def test_nonexistant_dir_does_not_fail(self):
        self.scan(self.find("scanner/does-not-exist"))
        assert not self.errors

    def test_other_media_is_ignored(self):
        self.scan(self.find("scanner/image"))
        assert not list(self.result.values())[0].playable

    def test_log_file_that_gst_thinks_is_mpeg_1_is_ignored(self):
        self.scan([path_to_data_dir("scanner/example.log")])

        self.check_if_missing_plugin()

        log = path_to_data_dir("scanner/example.log")
        assert self.result[log].duration is None

    def test_empty_wav_file(self):
        self.scan([path_to_data_dir("scanner/empty.wav")])
        wav = path_to_data_dir("scanner/empty.wav")
        assert self.result[wav].duration == 0

    def test_uri_list(self):
        path = path_to_data_dir("scanner/playlist.m3u")
        self.scan([path])
        assert self.result[path].mime == "text/uri-list"

    def test_text_plain(self):
        # GStreamer decode bin hardcodes bad handling of text plain :/
        path = path_to_data_dir("scanner/plain.txt")
        self.scan([path])
        assert path in self.errors

    @unittest.SkipTest
    def test_song_without_time_is_handeled(self):
        pass