emmental/tests/test_gsetup.py

92 lines
3.9 KiB
Python

# Copyright 2022 (c) Anna Schumaker.
"""Test that the gi.repository has been configured correctly."""
import unittest
import pathlib
import emmental
import gi
import io
import xdg.BaseDirectory
class TestGSetup(unittest.TestCase):
"""GObject Introspection configuration test case."""
def test_require_version(self):
"""Check that gi.require_version() has been called."""
self.assertEqual(gi.get_required_version("Gtk"), "4.0")
self.assertEqual(gi.get_required_version("Adw"), "1")
self.assertEqual(gi.get_required_version("Gst"), "1.0")
self.assertEqual(gi.get_required_version("Pango"), "1.0")
def test_adw(self):
"""Check that libadwaita style has been set."""
style = gi.repository.Adw.StyleManager.get_default()
self.assertEqual(style.get_color_scheme(),
gi.repository.Adw.ColorScheme.DEFAULT)
def test_gst(self):
"""Check that gstreamer has been initialized."""
self.assertTrue(gi.repository.Gst.is_initialized())
def test_import(self):
"""Check that modules have been imported."""
self.assertIsNotNone(emmental.gsetup.gi)
def test_application_id(self):
"""Check that the application id is generated properly."""
self.assertEqual(emmental.gsetup.DEBUG_STR, "-debug")
self.assertEqual(emmental.gsetup.APPLICATION_ID,
"com.nowheycreamery.emmental-debug")
def test_css(self):
"""Check that our custom stylesheet is configured."""
path = pathlib.Path(emmental.__file__).parent / "emmental.css"
self.assertEqual(emmental.gsetup.CSS_FILE, path)
self.assertEqual(emmental.gsetup.CSS_PRIORITY,
gi.repository.Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
self.assertIsInstance(emmental.gsetup.CSS_PROVIDER,
gi.repository.Gtk.CssProvider)
def test_resource(self):
"""Check that emmental.resource has been loaded."""
path = pathlib.Path(emmental.__file__).parent.parent
path = path / "emmental.gresource"
self.assertEqual(emmental.gsetup.RESOURCE_PATH,
"/com/nowheycreamery/emmental")
icons = f"{emmental.gsetup.RESOURCE_PATH}/icons/scalable/apps"
self.assertEqual(emmental.gsetup.RESOURCE_ICONS, icons)
self.assertEqual(emmental.gsetup.RESOURCE_FILE, path)
self.assertTrue(emmental.gsetup.RESOURCE_FILE.is_file())
self.assertIsInstance(emmental.gsetup.RESOURCE,
gi.repository.Gio.Resource)
def test_cache_dir(self):
"""Check that the CACHE_DIR points to the right place."""
cache_path = xdg.BaseDirectory.save_cache_path("emmental")
self.assertEqual(emmental.gsetup.CACHE_DIR,
pathlib.Path(cache_path) / "debug")
def test_data_dir(self):
"""Check that the DATA_DIR points to the right place."""
data_path = xdg.BaseDirectory.save_data_path("emmental")
self.assertEqual(emmental.gsetup.DATA_DIR, pathlib.Path(data_path))
def test_env_string(self):
"""Check that the env_string() function works as expected."""
self.assertRegex(emmental.gsetup.env_string(),
r" ⋅ Python \d+\.\d+\.\d+\n"
r" ⋅ Gtk \d+\.\d+\.\d+\n"
r" ⋅ Libadwaita \d+\.\d+\.\d+\n"
r" ⋅ GStreamer \d+\.\d+\.\d+\n"
r" ⋅ Pango \d+\.\d+\.\d+\n"
r" ⋅ SQLite \d+\.\d+\.\d+$")
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
def test_print_env(self, mock_stdout: io.StringIO):
"""Check that the print_env() function prints the env_string()."""
emmental.gsetup.print_env()
self.assertEqual(mock_stdout.getvalue(),
emmental.gsetup.env_string() + "\n")