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 gi.repository import Gtk, GdkPixbuf, Gdk 9 10from tests import TestCase, mkstemp, init_fake_app, destroy_fake_app 11from quodlibet import config 12from quodlibet.formats import AudioFile 13from quodlibet.qltk.cover import (CoverImage, BigCenteredImage, ResizeImage, 14 get_no_cover_pixbuf) 15 16 17class TCoverImage(TestCase): 18 def setUp(self): 19 config.init() 20 init_fake_app() 21 fd, self.fn = mkstemp() 22 os.close(fd) 23 pb = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 150, 10) 24 pb.savev(self.fn, "png", [], []) 25 26 def tearDown(self): 27 destroy_fake_app() 28 config.quit() 29 os.remove(self.fn) 30 31 def test_set_song(self): 32 c = CoverImage() 33 c.set_song(AudioFile({"~filename": "woo"})) 34 event = Gdk.Event.new(Gdk.EventType.BUTTON_PRESS) 35 event.type.button = 1 36 c.emit("button-press-event", event) 37 c.destroy() 38 39 def test_big_window(self): 40 parent = Gtk.Window() 41 w = BigCenteredImage("foobar", open(self.fn, "rb"), parent) 42 w.destroy() 43 44 def test_resize(self): 45 w = ResizeImage(False) 46 w.set_file(open(self.fn, "rb")) 47 w.set_file(None) 48 w.destroy() 49 50 def test_no_cover(self): 51 pb = get_no_cover_pixbuf(5, 10) 52 self.assertEqual(pb.get_width(), 5) 53 self.assertEqual(pb.get_height(), 5) 54 55 pb = get_no_cover_pixbuf(10, 5) 56 self.assertEqual(pb.get_width(), 5) 57 self.assertEqual(pb.get_height(), 5) 58