61 lines
2.2 KiB
Python
61 lines
2.2 KiB
Python
# Copyright 2022 (c) Anna Schumaker.
|
|
"""Test as much as we can of the Emmental Application."""
|
|
import unittest
|
|
import unittest.mock
|
|
import gi
|
|
import emmental
|
|
|
|
|
|
class TestEmmental(unittest.TestCase):
|
|
"""Emmental Application test case."""
|
|
|
|
def setUp(self):
|
|
"""Set up common variables."""
|
|
self.application = emmental.Application()
|
|
|
|
def tearDown(self):
|
|
"""Clean up."""
|
|
self.application.do_shutdown()
|
|
|
|
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")
|
|
self.assertEqual(self.application.get_property("resource-base-path"),
|
|
"/com/nowheycreamery/emmental")
|
|
|
|
@unittest.mock.patch("emmental.db.Connection.load")
|
|
@unittest.mock.patch("gi.repository.Adw.Application.do_startup")
|
|
def test_startup(self, mock_startup: unittest.mock.Mock,
|
|
mock_load: unittest.mock.Mock):
|
|
"""Test that the startup signal works as expected."""
|
|
self.assertIsNone(self.application.db)
|
|
self.assertIsNone(self.application.mpris)
|
|
|
|
self.application.emit("startup")
|
|
self.assertIsInstance(self.application.db, emmental.db.Connection)
|
|
self.assertIsInstance(self.application.mpris,
|
|
emmental.mpris2.Connection)
|
|
|
|
mock_startup.assert_called()
|
|
mock_load.assert_called()
|
|
|
|
def test_shutdown(self):
|
|
"""Test that the shutdown signal works as expected."""
|
|
db = self.application.db = emmental.db.Connection()
|
|
mpris = self.application.mpris = emmental.mpris2.Connection()
|
|
|
|
self.application.emit("shutdown")
|
|
self.assertIsNone(self.application.db)
|
|
self.assertIsNone(self.application.mpris)
|
|
|
|
self.assertIsNone(mpris.dbus)
|
|
self.assertFalse(db.connected)
|