# Copyright 2022 (c) Anna Schumaker. """Tests our Now Playing card.""" import unittest import unittest.mock import emmental from gi.repository import Gtk class TestNowPlaying(unittest.TestCase): """Test case for our custom Now Playing card.""" def setUp(self): """Set up common variables.""" self.card = emmental.nowplaying.Card() def test_init(self): """Test that the card has been initialized correctly.""" self.assertIsInstance(self.card, Gtk.Box) self.assertIsInstance(self.card._grid, Gtk.Grid) self.assertEqual(self.card.get_last_child(), self.card._grid) self.assertTrue(self.card.has_css_class("card")) def test_prefer_artist(self): """Test the 'prefer-artist' property.""" self.assertTrue(self.card.prefer_artist) self.card.prefer_artist = False self.assertFalse(self.card.prefer_artist) self.assertFalse(self.card._tags.prefer_artist) self.card._tags.prefer_artist = True self.assertTrue(self.card.prefer_artist) self.assertTrue(self.card._tags.prefer_artist) def test_tags(self): """Test tag properties.""" self.assertIsInstance(self.card._tags, emmental.nowplaying.tags.TagInfo) self.assertEqual(self.card._grid.get_child_at(0, 0), self.card._tags) for tag in ["title", "album", "artist", "album-artist"]: with self.subTest(tag=tag): self.card.set_property(tag, f"test {tag}") self.assertEqual(self.card.get_property(tag), f"test {tag}") self.assertEqual(self.card._tags.get_property(tag), f"test {tag}") def test_controls(self): """Test the now playing controls.""" self.assertIsInstance(self.card._controls, emmental.nowplaying.controls.Controls) self.assertEqual(self.card._grid.get_child_at(1, 0), self.card._controls) for signal in ["play", "pause", "previous", "next"]: with self.subTest(signal=signal): handler = unittest.mock.Mock() self.card.connect(signal, handler) self.card.emit(signal) handler.assert_called_with(self.card) def test_playing(self): """Test the 'playing' property.""" self.assertFalse(self.card.playing) self.card.playing = True self.assertTrue(self.card._controls.playing) self.card.playing = False self.assertFalse(self.card._controls.playing) def test_have_properties(self): """Test the 'have-{next, previous, track} properties.""" for property in ["have-next", "have-previous", "have-track"]: with self.subTest(property=property): self.assertFalse(self.card.get_property(property)) self.card.set_property(property, True) self.assertTrue(self.card._controls.get_property(property)) def test_autopause(self): """Test the 'autopause' property.""" self.assertEqual(self.card.autopause, -1) self.card._controls.autopause = 1 self.assertEqual(self.card.autopause, 1) self.card.autopause = 3 self.assertEqual(self.card.autopause, 3) self.assertEqual(self.card._controls.autopause, 3)