gtk: Create a SummaryView

The SummaryView displays a summary of the passed, failed, and skipped
tests for each xunit along with the time it took the xunit to run.

Signed-off-by: Anna Schumaker <anna@nowheycreamery.com>
This commit is contained in:
Anna Schumaker 2023-08-14 14:23:58 -04:00
parent 8a5bc1527a
commit 455d933fc4
4 changed files with 131 additions and 0 deletions

View File

@ -155,6 +155,75 @@ class TestTestCaseView(unittest.TestCase):
self.view._testcase)
class TestSummaryView(unittest.TestCase):
"""Tests the SummaryView."""
def setUp(self):
"""Set up common variables."""
self.xfstestsdb = xfstestsdb.Command()
with unittest.mock.patch("sys.stdout"):
self.xfstestsdb.run(["new", "/dev/vda1"])
self.xfstestsdb.run(["xunit", "read", "--name", "xunit-1",
"1", str(tests.xunit.XUNIT_1)])
self.xfstestsdb.run(["xunit", "read", "--name", "xunit-2",
"1", str(tests.xunit.XUNIT_1)])
self.model = xfstestsdb.gtk.model.SummaryList(self.xfstestsdb.sql, 1)
self.view = xfstestsdb.gtk.view.SummaryView()
def test_init(self):
"""Test that we created the SummaryView correctly."""
self.assertIsInstance(self.view, Gtk.ScrolledWindow)
self.assertEqual(self.view.props.vscrollbar_policy,
Gtk.PolicyType.NEVER)
self.assertTrue(self.view.has_css_class("card"))
self.assertIsNone(self.view.model)
def test_columnview(self):
"""Test that we set up the Columnview correctly."""
self.assertIsInstance(self.view.props.child, Gtk.ColumnView)
self.assertIsInstance(self.view.props.child.get_model(),
Gtk.NoSelection)
self.assertEqual(len(self.view.props.child.get_columns()), 0)
self.assertTrue(self.view.props.child.get_show_column_separators())
self.assertTrue(self.view.props.child.get_show_row_separators())
self.assertTrue(self.view.props.child.get_hexpand())
def test_summary_column(self):
"""Test that we set up the 'summary' column correctly."""
self.assertIsInstance(self.view._summary, Gtk.ColumnViewColumn)
self.assertIsInstance(self.view._summary.props.factory,
xfstestsdb.gtk.row.LabelFactory)
self.assertEqual(self.view._summary.props.factory.property, "name")
self.assertEqual(self.view._summary.props.title, "summary")
self.assertFalse(self.view._summary.props.expand)
def test_model(self):
"""Test setting the model property."""
self.view.model = self.model
self.assertEqual(self.view.props.child.get_model().get_model(),
self.model)
columns = self.view.props.child.get_columns()
self.assertEqual(len(columns), 3)
self.assertEqual(columns[0], self.view._summary)
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.SummaryFactory)
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)
self.view.model = self.model
self.assertEqual(self.view.props.child.get_columns()[0],
self.view._summary)
class TestXfstestsView(unittest.TestCase):
"""Test the XfstestsView."""
@ -169,6 +238,7 @@ class TestXfstestsView(unittest.TestCase):
"1", str(tests.xunit.XUNIT_1)])
self.model = xfstestsdb.gtk.model.TestCaseList(self.xfstestsdb.sql, 1)
self.summary = xfstestsdb.gtk.model.SummaryList(self.xfstestsdb.sql, 1)
self.view = xfstestsdb.gtk.view.XfstestsView()
def test_init(self):
@ -182,12 +252,26 @@ class TestXfstestsView(unittest.TestCase):
xfstestsdb.gtk.view.TestCaseView)
self.assertEqual(self.view.get_first_child(), self.view._testcaseview)
def test_summary_view(self):
"""Check that the XfstestsView sets up a SummaryView correctly."""
sep = self.view._testcaseview.get_next_sibling()
self.assertIsInstance(sep, Gtk.Separator)
self.assertIsInstance(self.view._summaryview,
xfstestsdb.gtk.view.SummaryView)
self.assertEqual(sep.get_next_sibling(), self.view._summaryview)
def test_model(self):
"""Test the XfstestsView 'model' property."""
self.assertIsNone(self.view.model)
self.view.model = self.model
self.assertEqual(self.view._testcaseview.model, self.model)
def test_summary(self):
"""Test the XfstestsView 'summary' property."""
self.assertIsNone(self.view.summary)
self.view.summary = self.summary
self.assertEqual(self.view._summaryview.model, self.summary)
def test_filterbuttons(self):
"""Test the XfstestsView 'filterbuttons' property."""
self.assertEqual(self.view.filterbuttons,

View File

@ -90,6 +90,10 @@ class TestApplication(unittest.TestCase):
self.application.model = model
self.assertEqual(self.application.view.model, model)
summary = xfstestsdb.gtk.model.SummaryList(self.xfstestsdb.sql, 42)
self.application.summary = summary
self.assertEqual(self.application.view.summary, summary)
@unittest.mock.patch("gi.repository.Adw.Application.add_window")
@unittest.mock.patch("gi.repository.Adw.Application.do_startup")
@unittest.mock.patch("gi.repository.Adw.Application.do_activate")

View File

@ -57,6 +57,7 @@ class Application(Adw.Application):
self.bind_property("runid", self.win, "runid")
self.bind_property("model", self.view, "model")
self.bind_property("summary", self.view, "summary")
self.add_window(self.win)
def do_activate(self) -> None:

View File

@ -4,6 +4,7 @@ from gi.repository import GObject
from gi.repository import Gtk
from .model import TestCaseList
from .model import TestCaseFilter
from .model import SummaryList
from . import button
from . import row
@ -84,19 +85,60 @@ class TestCaseView(Gtk.ScrolledWindow):
self.props.child.append_column(self.__xunit_column(xunit))
class SummaryView(Gtk.ScrolledWindow):
"""Displays our SummaryList model to the user."""
def __init__(self):
"""Initialize a SummaryView."""
super().__init__(child=Gtk.ColumnView(model=Gtk.NoSelection(),
show_row_separators=True,
show_column_separators=True,
hexpand=True),
vscrollbar_policy=Gtk.PolicyType.NEVER)
self._summary = Gtk.ColumnViewColumn(title="summary",
factory=row.LabelFactory("name"))
self.add_css_class("card")
def __summary_column(self, xunit: str) -> None:
return Gtk.ColumnViewColumn(title=xunit, expand=True,
factory=row.SummaryFactory(xunit))
@GObject.Property(type=SummaryList)
def model(self) -> SummaryList:
"""Get the SummaryList shown by the View."""
return self.props.child.get_model().get_model()
@model.setter
def model(self, new: SummaryList) -> None:
for col in [col for col in self.props.child.get_columns()]:
self.props.child.remove_column(col)
self.props.child.get_model().set_model(new)
if new is not None:
self.props.child.append_column(self._summary)
for xunit in new.get_xunits():
self.props.child.append_column(self.__summary_column(xunit))
class XfstestsView(Gtk.Box):
"""A widget to display the results of an Xfstests runs."""
model = GObject.Property(type=TestCaseList)
summary = GObject.Property(type=SummaryList)
def __init__(self):
"""Initialize an XfstestsView."""
super().__init__(orientation=Gtk.Orientation.VERTICAL)
self._testcaseview = TestCaseView()
self._summaryview = SummaryView()
self.bind_property("model", self._testcaseview, "model")
self.bind_property("summary", self._summaryview, "model")
self.append(self._testcaseview)
self.append(Gtk.Separator())
self.append(self._summaryview)
@GObject.Property(type=FilterButtons)
def filterbuttons(self) -> FilterButtons: