# Copyright 2022 (c) Anna Schumaker. """Tests our Album Art widget.""" import unittest import emmental.nowplaying.artwork import tests.util from gi.repository import Gtk class TestArtwork(unittest.TestCase): """Test case for our Album Art widget.""" def setUp(self): """Set up common variables.""" self.fallback = emmental.nowplaying.artwork.FALLBACK_RESOURCE self.artwork = emmental.nowplaying.artwork.Artwork() def test_constants(self): """Test constant values.""" self.assertEqual(self.fallback, f"{emmental.gsetup.RESOURCE_ICONS}/emmental.svg") def test_init(self): """Test that the artwork widget is configured correctly.""" self.assertIsInstance(self.artwork, Gtk.Picture) self.assertEqual(self.artwork.get_content_fit(), Gtk.ContentFit.CONTAIN) self.assertEqual(self.artwork.get_halign(), Gtk.Align.CENTER) self.assertEqual(self.artwork.get_valign(), Gtk.Align.CENTER) self.assertEqual(self.artwork.get_margin_top(), 6) self.assertEqual(self.artwork.get_margin_bottom(), 6) self.assertEqual(self.artwork.get_margin_start(), 6) self.assertEqual(self.artwork.get_margin_end(), 6) self.assertTrue(self.artwork.has_css_class("card")) def test_filepath(self): """Test that the filepath property works as expected.""" self.assertIsNone(self.artwork.filepath) self.assertIsNotNone(self.artwork.get_paintable()) self.assertEqual(self.artwork.get_file().get_parse_name(), f"resource://{self.fallback}") self.artwork.filepath = tests.util.COVER_JPG self.assertIsNotNone(self.artwork.get_paintable()) self.assertEqual(self.artwork.get_file().get_parse_name(), str(tests.util.COVER_JPG)) self.assertEqual(self.artwork.filepath, tests.util.COVER_JPG) self.artwork.filepath = None self.assertIsNotNone(self.artwork.get_paintable()) self.assertEqual(self.artwork.get_file().get_parse_name(), f"resource://{self.fallback}") def test_fullsize(self): """Test that the fullsize picture is configured correctly.""" self.assertIsInstance(self.artwork._fullsize, Gtk.Picture) self.assertEqual(self.artwork._fullsize.get_content_fit(), Gtk.ContentFit.FILL) self.assertEqual(self.artwork._popover.get_child(), self.artwork._fullsize) self.assertIsNotNone(self.artwork._fullsize.get_paintable()) self.assertEqual(self.artwork._fullsize.get_file().get_parse_name(), f"resource://{self.fallback}") self.artwork.filepath = tests.util.COVER_JPG self.assertIsNotNone(self.artwork._fullsize.get_paintable()) self.assertEqual(self.artwork._fullsize.get_file().get_parse_name(), str(tests.util.COVER_JPG)) self.artwork.filepath = None self.assertIsNotNone(self.artwork._fullsize.get_paintable()) self.assertEqual(self.artwork._fullsize.get_file().get_parse_name(), f"resource://{self.fallback}") def test_popover(self): """Test that the popover picture is configured correctly.""" self.assertIsInstance(self.artwork._popover, Gtk.Popover) self.assertIsInstance(self.artwork._clicked, Gtk.GestureClick) self.assertEqual(self.artwork._popover.get_parent(), self.artwork) self.assertEqual(self.artwork._clicked.get_widget(), self.artwork) with unittest.mock.patch.object(self.artwork._popover, "popup") as mock_popup: self.artwork._clicked.emit("released", 1, 1, 1) mock_popup.assert_called()