137 lines
5.3 KiB
Python
137 lines
5.3 KiB
Python
# Copyright 2022 (c) Anna Schumaker.
|
|
"""Tests our Now Playing card."""
|
|
import unittest
|
|
import unittest.mock
|
|
import emmental
|
|
import tests.util
|
|
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.assertIsInstance(self.card._bottom_box, Gtk.Box)
|
|
|
|
self.assertEqual(self.card._bottom_box.get_orientation(),
|
|
Gtk.Orientation.HORIZONTAL)
|
|
self.assertEqual(self.card._bottom_box.get_spacing(), 0)
|
|
|
|
self.assertEqual(self.card._artwork.get_next_sibling(),
|
|
self.card._grid)
|
|
self.assertEqual(self.card._grid.get_child_at(0, 1),
|
|
self.card._bottom_box)
|
|
self.assertEqual(self.card._grid.get_child_at(1, 1),
|
|
self.card._bottom_box)
|
|
|
|
self.assertTrue(self.card.has_css_class("card"))
|
|
|
|
def test_artwork(self):
|
|
"""Test that an Artwork instance has been added."""
|
|
self.assertIsInstance(self.card._artwork,
|
|
emmental.nowplaying.artwork.Artwork)
|
|
self.assertEqual(self.card.get_first_child(), self.card._artwork)
|
|
|
|
self.card.artwork = tests.util.COVER_JPG
|
|
self.assertEqual(self.card._artwork.filepath, tests.util.COVER_JPG)
|
|
|
|
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_seeker(self):
|
|
"""Test the seeker widget."""
|
|
self.assertIsInstance(self.card._seeker,
|
|
emmental.nowplaying.seeker.Scale)
|
|
self.assertEqual(self.card._bottom_box.get_last_child(),
|
|
self.card._seeker)
|
|
|
|
self.assertFalse(self.card._seeker.get_sensitive())
|
|
self.card.have_track = True
|
|
self.assertTrue(self.card._seeker.get_sensitive())
|
|
|
|
handler = unittest.mock.Mock()
|
|
self.card.connect("seek", handler)
|
|
self.card._seeker.emit("change-value", Gtk.ScrollType.JUMP, 10)
|
|
handler.assert_called_with(self.card, 10)
|
|
|
|
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)
|
|
|
|
def test_duration(self):
|
|
"""Test the 'duration' property."""
|
|
self.assertEqual(self.card.duration, 1)
|
|
self.card.duration = 10
|
|
self.assertEqual(self.card._seeker.duration, 10)
|
|
|
|
def test_position(self):
|
|
"""Test the 'position' property."""
|
|
self.assertEqual(self.card.position, 0)
|
|
self.card.position = 0.5
|
|
self.assertEqual(self.card._seeker.position, 0.5)
|