gtk: Display TestCase results in the TestCaseView

I use the ResultFactory to do this. I also create a custom css
stylesheet to use for each cell in the Gtk.ColumnView displaying the
results. This lets us add custom colors so we can easily see at a glance
what is failing, passing, or skipped.

Signed-off-by: Anna Schumaker <anna@nowheycreamery.com>
This commit is contained in:
Anna Schumaker 2023-08-01 16:43:15 -04:00
parent 8ef06e9571
commit e0bb2d7be7
8 changed files with 74 additions and 2 deletions

View File

@ -1,6 +1,7 @@
# Copyright 2023 (c) Anna Schumaker.
"""Tests our Gtk Setup."""
import gi
import pathlib
import unittest
import xfstestsdb.gtk.gsetup
@ -17,3 +18,25 @@ class TestGSetup(unittest.TestCase):
self.assertEqual(xfstestsdb.gtk.gsetup.DEBUG_STR, "-debug")
self.assertEqual(xfstestsdb.gtk.gsetup.APPLICATION_ID,
"com.nowheycreamery.xfstestsdb.gtk-debug")
@unittest.mock.patch.object(gi.repository.Gdk.Display, "get_default")
@unittest.mock.patch.object(gi.repository.Gtk.StyleContext,
"add_provider_for_display")
def test_add_style(self, mock_add: unittest.mock.Mock,
mock_get_default: unittest.mock.Mock):
"""Check that the CSS stylesheet is loaded correctly."""
gtk_init_py = pathlib.Path(xfstestsdb.gtk.__file__)
stylesheet = gtk_init_py.parent / "xfstestsdb.css"
self.assertEqual(xfstestsdb.gtk.gsetup.CSS_FILE, stylesheet)
self.assertEqual(xfstestsdb.gtk.gsetup.CSS_PRIORITY,
gi.repository.Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
self.assertIsInstance(xfstestsdb.gtk.gsetup.CSS_PROVIDER,
gi.repository.Gtk.CssProvider)
self.assertNotEqual(xfstestsdb.gtk.gsetup.CSS_PROVIDER.to_string(), "")
xfstestsdb.gtk.gsetup.add_style()
mock_add.assert_called_with(mock_get_default.return_value,
xfstestsdb.gtk.gsetup.CSS_PROVIDER,
xfstestsdb.gtk.gsetup.CSS_PRIORITY)

View File

@ -55,9 +55,17 @@ class TestTestCaseView(unittest.TestCase):
self.model)
columns = self.view.props.child.get_columns()
self.assertEqual(len(columns), 1)
self.assertEqual(len(columns), 3)
self.assertEqual(columns[0], self.view._testcase)
for i, title in enumerate(["xunit-1", "xunit-2"], start=1):
with self.subTest(i=i, title=title):
self.assertIsInstance(columns[i].props.factory,
xfstestsdb.gtk.row.ResultFactory)
self.assertEqual(columns[i].props.factory.xunit, title)
self.assertEqual(columns[i].props.title, title)
self.assertTrue(columns[i].props.expand)
self.view.model = None
self.assertEqual(len(self.view.props.child.get_columns()), 0)

View File

@ -56,10 +56,12 @@ class TestApplication(unittest.TestCase):
xfstestsdb.gtk.model.TestCaseList)
self.assertEqual(self.application.model.runid, 42)
@unittest.mock.patch("xfstestsdb.gtk.gsetup.add_style")
@unittest.mock.patch("gi.repository.Adw.Application.add_window")
@unittest.mock.patch("gi.repository.Adw.Application.do_startup")
def test_startup(self, mock_startup: unittest.mock.Mock,
mock_add_window: unittest.mock.Mock):
mock_add_window: unittest.mock.Mock,
mock_add_style: unittest.mock.Mock):
"""Check that startup sets up our application instance correctly."""
self.assertIsNone(self.application.win)
self.assertIsNone(self.application.view)
@ -73,6 +75,7 @@ class TestApplication(unittest.TestCase):
self.assertEqual(self.application.win.child, self.application.view)
mock_startup.assert_called_with(self.application)
mock_add_window.assert_called_with(self.application.win)
mock_add_style.assert_called()
self.application.runid = 42
self.assertEqual(self.application.win.runid, 42)

View File

@ -46,6 +46,8 @@ class Application(Adw.Application):
def do_startup(self) -> None:
"""Handle the Adw.Application::startup signal."""
Adw.Application.do_startup(self)
gsetup.add_style()
self.view = view.XfstestsView()
self.win = window.Window(child=self.view)
self.bind_property("runid", self.win, "runid")

View File

@ -1,8 +1,22 @@
# Copyright 2023 (c) Anna Schumaker.
"""Early setup of Gtk modules to avoid errors later."""
import gi
import pathlib
gi.require_version("Adw", "1")
gi.importlib.import_module("gi.repository.Adw")
DEBUG_STR = "-debug" if __debug__ else ""
APPLICATION_ID = f"com.nowheycreamery.xfstestsdb.gtk{DEBUG_STR}"
CSS_FILE = pathlib.Path(__file__).parent / "xfstestsdb.css"
CSS_PRIORITY = gi.repository.Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
CSS_PROVIDER = gi.repository.Gtk.CssProvider()
CSS_PROVIDER.load_from_path(str(CSS_FILE))
def add_style():
"""Add our custom stylesheet to the Gdk.Display."""
style = gi.repository.Gtk.StyleContext
style.add_provider_for_display(gi.repository.Gdk.Display.get_default(),
CSS_PROVIDER, CSS_PRIORITY)

Binary file not shown.

View File

@ -19,6 +19,10 @@ class TestCaseView(Gtk.ScrolledWindow):
factory=row.LabelFactory("name"))
self.add_css_class("card")
def __xunit_column(self, xunit: str) -> None:
return Gtk.ColumnViewColumn(title=xunit, expand=True,
factory=row.ResultFactory(xunit))
@GObject.Property(type=TestCaseList)
def model(self) -> TestCaseList:
"""Get the TestCaseList shown by the View."""
@ -33,6 +37,8 @@ class TestCaseView(Gtk.ScrolledWindow):
if new is not None:
self.props.child.append_column(self._testcase)
for xunit in new.get_xunits():
self.props.child.append_column(self.__xunit_column(xunit))
class XfstestsView(Gtk.Box):

View File

@ -0,0 +1,16 @@
/* Copyright 2023 (c) Anna Schumaker. */
cell.passed {
color: @success_fg_color;
background-color: @success_bg_color;
}
cell.skipped {
color: @warning_fg_color;
background-color: @warning_bg_color;
}
cell.failure {
color: @error_fg_color;
background-color: @error_bg_color;
}