1# This program is free software; you can redistribute it and/or modify 2# it under the terms of the GNU General Public License as published by 3# the Free Software Foundation; either version 2 of the License, or 4# (at your option) any later version. 5 6import os 7 8from tests import TestCase, get_data_path 9 10from quodlibet.formats import MusicFile, AudioFileError, EmbeddedImage 11 12from .helper import get_temp_copy 13 14 15FILES = [ 16 get_data_path("empty.ogg"), 17 get_data_path("empty.flac"), 18 get_data_path("silence-44-s.mp3"), 19 get_data_path("silence-44-s.mpc"), 20 get_data_path("test.wma"), 21 get_data_path("coverart.wv"), 22 get_data_path("test.m4a"), 23 get_data_path("empty.opus"), 24 get_data_path("silence-44-s.tta"), 25 get_data_path("empty.aac"), 26 get_data_path("test.mid"), 27 get_data_path("test.wav"), 28 get_data_path("silence-44-s.ape"), 29 get_data_path("test.vgm"), 30 get_data_path("silence-44-s.spx"), 31 get_data_path("test.spc"), 32] 33 34 35class TAudioFileAllBase(object): 36 37 FILE = None 38 39 def setUp(self): 40 self.filename = get_temp_copy(self.FILE) 41 self.song = MusicFile(self.filename) 42 43 def tearDown(self): 44 try: 45 os.remove(self.filename) 46 except OSError: 47 pass 48 49 def test_clear_images_noent(self): 50 os.remove(self.filename) 51 self.assertRaises(AudioFileError, self.song.clear_images) 52 53 def test_set_image_noent(self): 54 os.remove(self.filename) 55 image = EmbeddedImage(None, "image/png") 56 self.assertRaises(AudioFileError, self.song.set_image, image) 57 58 def test_get_primary_image_noent(self): 59 os.remove(self.filename) 60 self.assertTrue(self.song.get_primary_image() is None) 61 62 def test_get_images_noent(self): 63 os.remove(self.filename) 64 self.assertEqual(self.song.get_images(), []) 65 66 def test_write_noent(self): 67 os.remove(self.filename) 68 try: 69 self.song.write() 70 except AudioFileError: 71 pass 72 73 def test_load_noent(self): 74 os.remove(self.filename) 75 self.assertRaises(AudioFileError, type(self.song), self.filename) 76 77 @classmethod 78 def create_tests(cls): 79 for i, file_ in enumerate(FILES): 80 new_type = type(cls.__name__ + str(i), 81 (cls, TestCase), {"FILE": file_}) 82 assert new_type.__name__ not in globals() 83 globals()[new_type.__name__] = new_type 84 85 86TAudioFileAllBase.create_tests() 87