2022-05-26 14:42:09 -04:00
|
|
|
# Copyright 2022 (c) Anna Schumaker.
|
|
|
|
"""Test as much as we can of the Emmental Application."""
|
2022-06-15 09:08:54 -04:00
|
|
|
import io
|
2022-05-26 14:42:09 -04:00
|
|
|
import unittest
|
2022-05-26 17:17:03 -04:00
|
|
|
import unittest.mock
|
2022-05-26 14:42:09 -04:00
|
|
|
import gi
|
|
|
|
import emmental
|
|
|
|
|
|
|
|
|
|
|
|
class TestEmmental(unittest.TestCase):
|
|
|
|
"""Emmental Application test case."""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""Set up common variables."""
|
|
|
|
self.application = emmental.Application()
|
|
|
|
|
2022-05-26 17:17:03 -04:00
|
|
|
def tearDown(self):
|
|
|
|
"""Clean up."""
|
|
|
|
self.application.do_shutdown()
|
|
|
|
|
2022-05-26 14:42:09 -04:00
|
|
|
def test_version(self):
|
|
|
|
"""Check that version constants have been set properly."""
|
|
|
|
self.assertEqual(emmental.MAJOR_VERSION, 3)
|
|
|
|
self.assertEqual(emmental.MINOR_VERSION, 0)
|
|
|
|
self.assertEqual(emmental.VERSION_STRING, "Emmental 3.0-debug")
|
|
|
|
|
|
|
|
def test_application(self):
|
|
|
|
"""Check that the application instance is initialized properly."""
|
|
|
|
self.assertIsInstance(self.application, gi.repository.Adw.Application)
|
|
|
|
self.assertEqual(self.application.get_application_id(),
|
|
|
|
"com.nowheycreamery.emmental-debug")
|
2022-07-15 14:53:04 -04:00
|
|
|
self.assertEqual(self.application.get_property("resource-base-path"),
|
|
|
|
"/com/nowheycreamery/emmental")
|
2022-05-26 17:17:03 -04:00
|
|
|
|
2022-06-15 09:08:54 -04:00
|
|
|
@unittest.mock.patch("sys.stdout")
|
2022-05-30 11:47:14 -04:00
|
|
|
@unittest.mock.patch("gi.repository.Adw.Application.add_window")
|
2022-05-26 17:18:21 -04:00
|
|
|
@unittest.mock.patch("emmental.db.Connection.load")
|
2022-05-26 17:17:03 -04:00
|
|
|
@unittest.mock.patch("gi.repository.Adw.Application.do_startup")
|
2022-05-26 17:18:21 -04:00
|
|
|
def test_startup(self, mock_startup: unittest.mock.Mock,
|
2022-05-30 11:47:14 -04:00
|
|
|
mock_load: unittest.mock.Mock,
|
2022-06-15 09:08:54 -04:00
|
|
|
mock_add_window: unittest.mock.Mock,
|
|
|
|
mock_stdout: unittest.mock.Mock):
|
2022-05-26 17:17:03 -04:00
|
|
|
"""Test that the startup signal works as expected."""
|
|
|
|
self.assertIsNone(self.application.db)
|
2022-10-20 16:50:17 -04:00
|
|
|
self.assertIsNone(self.application.mpris)
|
2022-06-15 09:08:54 -04:00
|
|
|
self.assertIsNone(self.application.player)
|
2022-05-30 11:47:14 -04:00
|
|
|
self.assertIsNone(self.application.win)
|
2022-05-26 17:17:03 -04:00
|
|
|
|
|
|
|
self.application.emit("startup")
|
|
|
|
self.assertIsInstance(self.application.db, emmental.db.Connection)
|
2022-10-20 16:50:17 -04:00
|
|
|
self.assertIsInstance(self.application.mpris,
|
|
|
|
emmental.mpris2.Connection)
|
2022-06-15 09:08:54 -04:00
|
|
|
self.assertIsInstance(self.application.player, emmental.audio.Player)
|
2022-05-30 11:47:14 -04:00
|
|
|
self.assertIsInstance(self.application.win, emmental.window.Window)
|
2022-10-20 16:50:17 -04:00
|
|
|
|
2022-05-26 17:17:03 -04:00
|
|
|
mock_startup.assert_called()
|
2022-05-26 17:18:21 -04:00
|
|
|
mock_load.assert_called()
|
2022-05-30 11:47:14 -04:00
|
|
|
mock_add_window.assert_called_with(self.application.win)
|
2022-05-26 17:17:03 -04:00
|
|
|
|
2022-06-15 09:08:54 -04:00
|
|
|
@unittest.mock.patch("sys.stdout")
|
2022-05-30 11:47:14 -04:00
|
|
|
@unittest.mock.patch("gi.repository.Adw.Application.add_window")
|
|
|
|
@unittest.mock.patch("gi.repository.Adw.Application.do_startup")
|
|
|
|
def test_activate(self, mock_startup: unittest.mock.Mock,
|
2022-06-15 09:08:54 -04:00
|
|
|
mock_add_window: unittest.mock.Mock,
|
|
|
|
mock_stdout: unittest.mock.Mock):
|
2022-05-30 11:47:14 -04:00
|
|
|
"""Test activating the application."""
|
|
|
|
self.application.emit("startup")
|
|
|
|
|
|
|
|
with unittest.mock.patch.object(self.application.win,
|
|
|
|
"present") as mock_present:
|
|
|
|
self.application.emit("activate")
|
|
|
|
mock_present.assert_called()
|
|
|
|
|
|
|
|
@unittest.mock.patch("gi.repository.Adw.Window.close")
|
|
|
|
def test_shutdown(self, mock_close: unittest.mock.Mock):
|
2022-05-26 17:17:03 -04:00
|
|
|
"""Test that the shutdown signal works as expected."""
|
|
|
|
db = self.application.db = emmental.db.Connection()
|
2022-10-20 16:50:17 -04:00
|
|
|
mpris = self.application.mpris = emmental.mpris2.Connection()
|
2022-05-30 11:47:14 -04:00
|
|
|
self.application.win = emmental.window.Window("Test 1.2.3")
|
2022-06-15 09:08:54 -04:00
|
|
|
player = self.application.player = emmental.audio.Player()
|
2022-05-26 17:17:03 -04:00
|
|
|
|
|
|
|
self.application.emit("shutdown")
|
|
|
|
self.assertIsNone(self.application.db)
|
2022-10-20 16:50:17 -04:00
|
|
|
self.assertIsNone(self.application.mpris)
|
2022-06-15 09:08:54 -04:00
|
|
|
self.assertIsNone(self.application.player)
|
2022-05-30 11:47:14 -04:00
|
|
|
self.assertIsNone(self.application.win)
|
2022-10-20 16:50:17 -04:00
|
|
|
|
|
|
|
self.assertIsNone(mpris.dbus)
|
2022-05-26 17:17:03 -04:00
|
|
|
self.assertFalse(db.connected)
|
2022-06-15 09:08:54 -04:00
|
|
|
self.assertEqual(player.get_state(), gi.repository.Gst.State.NULL)
|
2022-05-30 11:47:14 -04:00
|
|
|
mock_close.assert_called()
|
|
|
|
|
2022-06-15 09:08:54 -04:00
|
|
|
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
|
|
|
|
def test_window_widgets(self, mock_stdout: io.StringIO):
|
2022-05-30 11:47:14 -04:00
|
|
|
"""Check that the window widgets are added properly."""
|
|
|
|
self.application.db = emmental.db.Connection()
|
2022-06-15 09:08:54 -04:00
|
|
|
self.application.player = emmental.audio.Player()
|
2022-05-30 11:47:14 -04:00
|
|
|
win = self.application.build_window()
|
|
|
|
|
|
|
|
self.assertIsInstance(win, emmental.window.Window)
|
2022-05-31 10:18:53 -04:00
|
|
|
self.assertIsInstance(win.header, emmental.header.Header)
|
2022-05-31 10:18:53 -04:00
|
|
|
self.assertIsInstance(win.now_playing, emmental.nowplaying.Card)
|
|
|
|
|
2022-05-31 10:18:53 -04:00
|
|
|
self.assertEqual(win.header.title, emmental.VERSION_STRING)
|
2022-06-15 09:08:54 -04:00
|
|
|
|
|
|
|
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
|
|
|
|
def test_replaygain(self, mock_stdout: io.StringIO):
|
|
|
|
"""Test setting replaygain modes."""
|
|
|
|
self.application.db = emmental.db.Connection()
|
|
|
|
self.application.player = emmental.audio.Player()
|
|
|
|
win = self.application.build_window()
|
|
|
|
player = self.application.player
|
|
|
|
|
|
|
|
win.header.rg_enabled = True
|
|
|
|
self.assertEqual(player.get_replaygain(), (True, "track"))
|
|
|
|
win.header.rg_mode = "album"
|
|
|
|
self.assertEqual(player.get_replaygain(), (True, "album"))
|