71 lines
2.2 KiB
Python
71 lines
2.2 KiB
Python
# Copyright 2021 (c) Anna Schumaker.
|
|
import db
|
|
import unittest
|
|
from gi.repository import GObject
|
|
from gi.repository import Gtk
|
|
from . import nowplaying
|
|
|
|
class FakeArtist(GObject.GObject):
|
|
def __init__(self):
|
|
self.name = "Test Artist"
|
|
|
|
class FakeTrack(GObject.GObject):
|
|
def __init__(self):
|
|
GObject.GObject.__init__(self)
|
|
self.title = "Test Title"
|
|
self.artist = FakeArtist()
|
|
|
|
class FakePlayer(GObject.GObject):
|
|
def __init__(self):
|
|
GObject.GObject.__init__(self)
|
|
self.track = None
|
|
|
|
@GObject.Signal(arg_types=(FakeTrack,FakeTrack))
|
|
def track_changed(self, prev, new): pass
|
|
|
|
|
|
class TestAudioTrackTitle(unittest.TestCase):
|
|
def test_track_title(self):
|
|
fake = FakePlayer()
|
|
title = nowplaying.TrackTitle(fake)
|
|
|
|
self.assertIsInstance(title, Gtk.Label)
|
|
self.assertTrue(title.has_css_class("title"))
|
|
self.assertEqual(title.get_text(), "Emmental")
|
|
|
|
fake.emit("track-changed", None, FakeTrack())
|
|
self.assertEqual(title.get_text(), "Test Title")
|
|
|
|
|
|
class TestAudioTrackArtist(unittest.TestCase):
|
|
def test_track_artist(self):
|
|
fake = FakePlayer()
|
|
artist = nowplaying.TrackArtist(fake)
|
|
|
|
self.assertIsInstance(artist, Gtk.Label)
|
|
self.assertTrue(artist.has_css_class("subtitle"))
|
|
self.assertEqual(artist.get_text(), "The Cheesy Music Player")
|
|
|
|
fake.emit("track-changed", None, FakeTrack())
|
|
self.assertEqual(artist.get_text(), "by Test Artist")
|
|
|
|
|
|
class TestNowPlaying(unittest.TestCase):
|
|
def test_now_playing(self):
|
|
fake = FakePlayer()
|
|
now = nowplaying.NowPlaying(fake)
|
|
child = now.box.get_first_child()
|
|
viewport = now.get_child()
|
|
|
|
self.assertIsInstance(now, Gtk.ScrolledWindow)
|
|
self.assertIsInstance(now.box, Gtk.Box)
|
|
self.assertIsInstance(child, nowplaying.TrackTitle)
|
|
self.assertIsInstance(child.get_next_sibling(), nowplaying.TrackArtist)
|
|
|
|
self.assertEqual(viewport.get_child(), now.box)
|
|
self.assertEqual(now.get_valign(), Gtk.Align.CENTER)
|
|
self.assertEqual(now.get_policy(), (Gtk.PolicyType.AUTOMATIC,
|
|
Gtk.PolicyType.NEVER))
|
|
|
|
self.assertTrue(now.get_hexpand())
|