189 lines
6.6 KiB
Python
189 lines
6.6 KiB
Python
# Copyright 2021 (c) Anna Schumaker.
|
|
import unittest
|
|
from gi.repository import GObject
|
|
from gi.repository import Gtk
|
|
from gi.repository import Gst
|
|
from . import controls
|
|
from . import scale
|
|
|
|
class FakePlayer(GObject.GObject):
|
|
def __init__(self):
|
|
GObject.GObject.__init__(self)
|
|
self.prev = False
|
|
self.nxt = False
|
|
self.play = False
|
|
self.vol = 1.0
|
|
|
|
def previous(self): self.prev = True
|
|
def next(self): self.nxt = True
|
|
def get_volume(self): return self.vol
|
|
def playpause(self):
|
|
states = { True : Gst.State.PLAYING, False : Gst.State.PAUSED }
|
|
self.play = not self.play
|
|
self.emit("state-changed", Gst.State.NULL, states[self.play], Gst.State.NULL)
|
|
|
|
@GObject.Signal(arg_types=(Gst.State, Gst.State, Gst.State))
|
|
def state_changed(self, old, new, pending): pass
|
|
|
|
|
|
class TestControlButton(unittest.TestCase):
|
|
def test_control_button(self):
|
|
fake = FakePlayer()
|
|
ctrl = controls.ControlButton(fake, "missing-icon")
|
|
self.assertIsInstance(ctrl, Gtk.Button)
|
|
self.assertTrue(ctrl.has_css_class("large-icons"))
|
|
self.assertEqual(ctrl.get_icon_name(), "missing-icon")
|
|
self.assertEqual(ctrl.player, fake)
|
|
|
|
|
|
class TestPreviousButton(unittest.TestCase):
|
|
def test_previous_button(self):
|
|
fake = FakePlayer()
|
|
prev = controls.PreviousButton(fake)
|
|
|
|
self.assertIsInstance(prev, controls.ControlButton)
|
|
self.assertEqual(prev.get_icon_name(), "media-skip-backward")
|
|
prev.emit("clicked")
|
|
self.assertTrue(fake.prev)
|
|
|
|
|
|
class TestNextButton(unittest.TestCase):
|
|
def test_next_button(self):
|
|
fake = FakePlayer()
|
|
next = controls.NextButton(fake)
|
|
|
|
self.assertIsInstance(next, controls.ControlButton)
|
|
self.assertEqual(next.get_icon_name(), "media-skip-forward")
|
|
next.emit("clicked")
|
|
self.assertTrue(fake.nxt)
|
|
|
|
|
|
class TestPlayPauseButton(unittest.TestCase):
|
|
def test_play_pause_button(self):
|
|
fake = FakePlayer()
|
|
play = controls.PlayPauseButton(fake)
|
|
|
|
self.assertIsInstance(play, controls.ControlButton)
|
|
self.assertEqual(play.get_icon_name(), "media-playback-start")
|
|
|
|
play.emit("clicked")
|
|
self.assertTrue(fake.play)
|
|
self.assertEqual(play.get_icon_name(), "media-playback-pause")
|
|
|
|
play.emit("clicked")
|
|
self.assertFalse(fake.play)
|
|
self.assertEqual(play.get_icon_name(), "media-playback-start")
|
|
|
|
|
|
class TestControlScaleBox(unittest.TestCase):
|
|
def test_control_scale_box(self):
|
|
splus = scale.ScalePlus(1, 10, 1, 5)
|
|
ctrlbox = controls.ControlScaleBox(splus)
|
|
self.assertIsInstance(ctrlbox, scale.ScaleButtonBox)
|
|
self.assertIsInstance(ctrlbox.get_first_child(), Gtk.Image)
|
|
self.assertTrue(ctrlbox.get_first_child().has_css_class("large-icons"))
|
|
|
|
|
|
class TestAutoPauseControlBox(unittest.TestCase):
|
|
def test_autopause_control_box(self):
|
|
apscale = scale.AutoPauseScale()
|
|
apbox = controls.AutoPauseControlBox(apscale)
|
|
icon = apbox.get_first_child()
|
|
|
|
self.assertIsInstance(apbox, controls.ControlScaleBox)
|
|
apscale.set_value(-1)
|
|
self.assertEqual(icon.get_icon_name(), "media-playback-start")
|
|
apscale.set_value(0)
|
|
self.assertEqual(icon.get_icon_name(), "media-playback-pause")
|
|
|
|
|
|
class TestVolumeControlbox(unittest.TestCase):
|
|
def test_volume_control_box(self):
|
|
fake = FakePlayer()
|
|
vcb = controls.VolumeControlBox(fake)
|
|
icon = vcb.get_first_child()
|
|
volume = icon.get_next_sibling().scale
|
|
|
|
self.assertIsInstance(vcb, controls.ControlScaleBox)
|
|
self.assertIsInstance(volume, scale.VolumeScale)
|
|
|
|
volume.set_value(0)
|
|
self.assertEqual(icon.get_icon_name(), "audio-volume-muted-symbolic")
|
|
volume.set_value(0.3)
|
|
self.assertEqual(icon.get_icon_name(), "audio-volume-low-symbolic")
|
|
volume.set_value(0.6)
|
|
self.assertEqual(icon.get_icon_name(), "audio-volume-medium-symbolic")
|
|
volume.set_value(0.9)
|
|
self.assertEqual(icon.get_icon_name(), "audio-volume-high-symbolic")
|
|
|
|
|
|
class TestControlsPopover(unittest.TestCase):
|
|
def test_controls_popover(self):
|
|
fake = FakePlayer()
|
|
apscale = scale.AutoPauseScale()
|
|
pop = controls.ControlsPopover(fake, apscale)
|
|
|
|
self.assertIsInstance(pop, Gtk.Popover)
|
|
self.assertIsInstance(pop.box, Gtk.Box)
|
|
|
|
child = pop.box.get_first_child()
|
|
self.assertIsInstance(child, controls.AutoPauseControlBox)
|
|
child = child.get_next_sibling()
|
|
self.assertIsInstance(child, controls.VolumeControlBox)
|
|
|
|
self.assertEqual(pop.get_child(), pop.box)
|
|
self.assertEqual(pop.box.get_orientation(), Gtk.Orientation.VERTICAL)
|
|
|
|
|
|
class TestControlsMenuIcon(unittest.TestCase):
|
|
def test_controls_menu_icon(self):
|
|
apscale = scale.AutoPauseScale()
|
|
icon = controls.MenuIcon(apscale)
|
|
|
|
self.assertIsInstance(icon, Gtk.Overlay)
|
|
self.assertIsInstance(icon.icon, Gtk.Image)
|
|
self.assertIsInstance(icon.label, Gtk.Label)
|
|
|
|
self.assertEqual(icon.icon.get_icon_name(), "pan-down-symbolic")
|
|
self.assertEqual(icon.icon.get_margin_top(), 5)
|
|
self.assertEqual(icon.label.get_text(), " ")
|
|
self.assertEqual(icon.label.get_yalign(), 0)
|
|
|
|
apscale.set_value(0)
|
|
self.assertEqual(icon.label.get_text(), "0")
|
|
|
|
self.assertIn(icon.icon, icon)
|
|
self.assertIn(icon.label, icon)
|
|
|
|
|
|
class TestControlsMenuButton(unittest.TestCase):
|
|
def test_controls_menu_button(self):
|
|
fake = FakePlayer()
|
|
apscale = scale.AutoPauseScale()
|
|
menu = controls.MenuButton(fake, apscale)
|
|
|
|
self.assertIsInstance(menu, Gtk.ToggleButton)
|
|
self.assertIsInstance(menu.popover, controls.ControlsPopover)
|
|
self.assertIsInstance(menu.get_child(), controls.MenuIcon)
|
|
self.assertEqual(menu.popover.get_parent(), menu)
|
|
|
|
|
|
class TestAudioControls(unittest.TestCase):
|
|
def test_audio_controls(self):
|
|
fake = FakePlayer()
|
|
apscale = scale.AutoPauseScale()
|
|
ctrl = controls.AudioControls(fake, apscale)
|
|
|
|
self.assertIsInstance(ctrl, Gtk.Box)
|
|
self.assertEqual(ctrl.get_orientation(), Gtk.Orientation.HORIZONTAL)
|
|
self.assertTrue(ctrl.has_css_class("linked"))
|
|
|
|
child = ctrl.get_first_child()
|
|
self.assertIsInstance(child, controls.PreviousButton)
|
|
child = child.get_next_sibling()
|
|
self.assertIsInstance(child, controls.PlayPauseButton)
|
|
child = child.get_next_sibling()
|
|
self.assertIsInstance(child, controls.NextButton)
|
|
child = child.get_next_sibling()
|
|
self.assertIsInstance(child, controls.MenuButton)
|