File: test_formats_all.py

package info (click to toggle)
quodlibet 4.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,228 kB
  • sloc: python: 89,728; sh: 381; xml: 110; makefile: 91
file content (84 lines) | stat: -rw-r--r-- 2,435 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
# 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.

import os

from tests import TestCase, get_data_path

from quodlibet.formats import MusicFile, AudioFileError, EmbeddedImage

from .helper import get_temp_copy


FILES = [
    get_data_path("empty.ogg"),
    get_data_path("empty.flac"),
    get_data_path("silence-44-s.mp3"),
    get_data_path("silence-44-s.mpc"),
    get_data_path("test.wma"),
    get_data_path("coverart.wv"),
    get_data_path("test.m4a"),
    get_data_path("empty.opus"),
    get_data_path("silence-44-s.tta"),
    get_data_path("empty.aac"),
    get_data_path("test.mid"),
    get_data_path("test.wav"),
    get_data_path("silence-44-s.ape"),
    get_data_path("test.vgm"),
    get_data_path("silence-44-s.spx"),
    get_data_path("test.spc"),
]


class TAudioFileAllBase:
    FILE = None

    def setUp(self):
        self.filename = get_temp_copy(self.FILE)
        self.song = MusicFile(self.filename)

    def tearDown(self):
        try:
            os.remove(self.filename)
        except OSError:
            pass

    def test_clear_images_noent(self):
        os.remove(self.filename)
        self.assertRaises(AudioFileError, self.song.clear_images)

    def test_set_image_noent(self):
        os.remove(self.filename)
        image = EmbeddedImage(None, "image/png")
        self.assertRaises(AudioFileError, self.song.set_image, image)

    def test_get_primary_image_noent(self):
        os.remove(self.filename)
        assert self.song.get_primary_image() is None

    def test_get_images_noent(self):
        os.remove(self.filename)
        self.assertEqual(self.song.get_images(), [])

    def test_write_noent(self):
        os.remove(self.filename)
        try:
            self.song.write()
        except AudioFileError:
            pass

    def test_load_noent(self):
        os.remove(self.filename)
        self.assertRaises(AudioFileError, type(self.song), self.filename)

    @classmethod
    def create_tests(cls):
        for i, file_ in enumerate(FILES):
            new_type = type(cls.__name__ + str(i), (cls, TestCase), {"FILE": file_})
            assert new_type.__name__ not in globals()
            globals()[new_type.__name__] = new_type


TAudioFileAllBase.create_tests()