gtk: Add an XunitView base class

The XunitView implements most of the work needed by our various views to
show xfstests results.

Signed-off-by: Anna Schumaker <anna@nowheycreamery.com>
This commit is contained in:
Anna Schumaker 2023-08-29 15:24:58 -04:00
parent a5d1ae4607
commit c861c49564
2 changed files with 144 additions and 256 deletions

View File

@ -6,8 +6,8 @@ import xfstestsdb.gtk.view
from gi.repository import Gtk
class TestPropertyView(unittest.TestCase):
"""Tests the PropertyView."""
class TestXunitView(unittest.TestCase):
"""Tests the XunitView base class."""
def setUp(self):
"""Set up common variables."""
@ -19,19 +19,16 @@ class TestPropertyView(unittest.TestCase):
self.xfstestsdb.run(["xunit", "read", "--name", "xunit-2",
"1", str(tests.xunit.XUNIT_1)])
self.model = xfstestsdb.gtk.model.PropertyList(self.xfstestsdb.sql, 1)
self.view = xfstestsdb.gtk.view.PropertyView()
self.model = xfstestsdb.gtk.model.XunitList(self.xfstestsdb.sql, 1)
self.view = xfstestsdb.gtk.view.XunitView("title")
def test_init(self):
"""Test that we created the ProeprtyView correctly."""
"""Test that we created the XunitView 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."""
"""Test that we set up the ColumnView child correctly."""
self.assertIsInstance(self.view.props.child, Gtk.ColumnView)
self.assertIsInstance(self.view.props.child.get_model(),
Gtk.NoSelection)
@ -39,51 +36,71 @@ class TestPropertyView(unittest.TestCase):
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())
self.assertTrue(self.view.props.child.has_css_class("data-table"))
def test_filter(self):
def test_filtermodel(self):
"""Test that we set up the Gtk.FilterModel correctly."""
self.assertIsInstance(self.view._filtermodel, Gtk.FilterListModel)
self.assertIsInstance(self.view._propfilter,
xfstestsdb.gtk.model.PropertyFilter)
self.assertIsInstance(self.view.filtermodel, Gtk.FilterListModel)
self.assertIsNone(self.view.filtermodel.props.filter)
self.assertEqual(self.view.props.child.get_model().get_model(),
self.view._filtermodel)
self.assertEqual(self.view._filtermodel.props.filter,
self.view._propfilter)
self.view.filtermodel)
def test_property_column(self):
"""Test that we set up the 'property' column correctly."""
self.assertIsInstance(self.view._property, Gtk.ColumnViewColumn)
self.assertIsInstance(self.view._property.props.factory,
def test_firstcol(self):
"""Test that we set up the first column correctly."""
self.assertIsInstance(self.view.firstcol, Gtk.ColumnViewColumn)
self.assertIsInstance(self.view.firstcol.props.factory,
xfstestsdb.gtk.row.LabelFactory)
self.assertEqual(self.view._property.props.factory.property, "name")
self.assertEqual(self.view._property.props.title, "property")
self.assertFalse(self.view._property.props.expand)
self.assertEqual(self.view.firstcol.props.factory.property, "name")
self.assertEqual(self.view.firstcol.props.title, "title")
self.assertFalse(self.view.firstcol.props.expand)
def test_model(self):
"""Test setting the model property."""
self.view.model = self.model
self.assertEqual(self.view._filtermodel.props.model, self.model)
"""Test the model property."""
columns = self.view.props.child.get_columns()
self.assertIsNone(self.view.model)
self.assertEqual(len(columns), 0)
self.view.model = self.model
self.assertEqual(self.view.filtermodel.props.model, self.model)
self.assertEqual(len(columns), 3)
self.assertEqual(columns[0], self.view._property)
self.assertEqual(columns[0], self.view.firstcol)
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.PropertyFactory)
xfstestsdb.gtk.row.XunitFactory)
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.assertEqual(len(columns), 0)
self.view.model = self.model
self.assertEqual(self.view.props.child.get_columns()[0],
self.view._property)
class TestPropertyView(unittest.TestCase):
"""Tests the PropertyView."""
def setUp(self):
"""Set up common variables."""
self.view = xfstestsdb.gtk.view.PropertyView()
def test_init(self):
"""Test that we created the ProeprtyView correctly."""
self.assertIsInstance(self.view, xfstestsdb.gtk.view.XunitView)
self.assertIsInstance(self.view.filtermodel.props.filter,
xfstestsdb.gtk.model.PropertyFilter)
self.assertIsNone(self.view.model)
self.assertEqual(self.view.props.vscrollbar_policy,
Gtk.PolicyType.NEVER)
self.assertEqual(self.view.firstcol.props.title, "property")
self.assertTrue(self.view.props.child.has_css_class("data-table"))
def test_make_factory(self):
"""Test the do_make_factory() implementation."""
factory = self.view.do_make_factory("xunit-1")
self.assertIsInstance(factory, xfstestsdb.gtk.row.PropertyFactory)
self.assertEqual(factory.xunit, "xunit-1")
class TestFilterButtons(unittest.TestCase):
@ -148,91 +165,40 @@ class TestTestCaseView(unittest.TestCase):
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.TestCaseList(self.xfstestsdb.sql, 1)
self.view = xfstestsdb.gtk.view.TestCaseView()
def test_init(self):
"""Test that we create the TestCaseView correctly."""
self.assertIsInstance(self.view, Gtk.ScrolledWindow)
self.assertTrue(self.view.has_css_class("card"))
self.assertIsInstance(self.view, xfstestsdb.gtk.view.XunitView)
self.assertIsInstance(self.view.filtermodel.props.filter,
xfstestsdb.gtk.model.TestCaseFilter)
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())
self.assertEqual(self.view.firstcol.props.title, "testcase")
self.assertTrue(self.view.props.child.get_vexpand())
def test_filter(self):
"""Test that we set up the Gtk.FilterModel and Buttons correctly."""
self.assertIsInstance(self.view._filtermodel, Gtk.FilterListModel)
self.assertIsInstance(self.view._testfilter,
xfstestsdb.gtk.model.TestCaseFilter)
self.assertIsInstance(self.view.filterbuttons,
xfstestsdb.gtk.view.FilterButtons)
self.assertEqual(self.view.props.child.get_model().get_model(),
self.view._filtermodel)
self.assertEqual(self.view._filtermodel.props.filter,
self.view._testfilter)
self.assertFalse(self.view._testfilter.passed)
self.assertFalse(self.view.filtermodel.props.filter.passed)
self.view.filterbuttons.passed = True
self.assertTrue(self.view._testfilter.passed)
self.assertTrue(self.view.filtermodel.props.filter.passed)
self.assertFalse(self.view._testfilter.skipped)
self.assertFalse(self.view.filtermodel.props.filter.skipped)
self.view.filterbuttons.skipped = True
self.assertTrue(self.view._testfilter.skipped)
self.assertTrue(self.view.filtermodel.props.filter.skipped)
self.assertTrue(self.view._testfilter.failure)
self.assertTrue(self.view.filtermodel.props.filter.failure)
self.view.filterbuttons.failure = False
self.assertFalse(self.view._testfilter.failure)
self.assertFalse(self.view.filtermodel.props.filter.failure)
def test_testcase_column(self):
"""Test that we set up the 'testcase' column correctly."""
self.assertIsInstance(self.view._testcase, Gtk.ColumnViewColumn)
self.assertIsInstance(self.view._testcase.props.factory,
xfstestsdb.gtk.row.LabelFactory)
self.assertEqual(self.view._testcase.props.factory.property, "name")
self.assertEqual(self.view._testcase.props.title, "testcase")
self.assertFalse(self.view._testcase.props.expand)
def test_model(self):
"""Test setting the model property."""
self.view.model = self.model
self.assertEqual(self.view._filtermodel.props.model, self.model)
columns = self.view.props.child.get_columns()
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)
self.view.model = self.model
self.assertEqual(self.view.props.child.get_columns()[0],
self.view._testcase)
def test_make_factory(self):
"""Test the do_make_factory() implementation."""
factory = self.view.do_make_factory("xunit-1")
self.assertIsInstance(factory, xfstestsdb.gtk.row.ResultFactory)
self.assertEqual(factory.xunit, "xunit-1")
class TestSummaryView(unittest.TestCase):
@ -240,68 +206,24 @@ class TestSummaryView(unittest.TestCase):
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.assertIsInstance(self.view, xfstestsdb.gtk.view.XunitView)
self.assertIsNone(self.view.filtermodel.props.filter)
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())
self.assertEqual(self.view.props.vscrollbar_policy,
Gtk.PolicyType.NEVER)
self.assertEqual(self.view.firstcol.props.title, "summary")
self.assertTrue(self.view.props.child.has_css_class("data-table"))
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)
def test_make_factory(self):
"""Test the do_make_factory() implementation."""
factory = self.view.do_make_factory("xunit-1")
self.assertIsInstance(factory, xfstestsdb.gtk.row.SummaryFactory)
self.assertEqual(factory.xunit, "xunit-1")
class TestXfstestsView(unittest.TestCase):

View File

@ -7,50 +7,67 @@ from .model import PropertyFilter
from .model import TestCaseList
from .model import TestCaseFilter
from .model import SummaryList
from .model import XunitList
from . import button
from . import row
class PropertyView(Gtk.ScrolledWindow):
class XunitView(Gtk.ScrolledWindow):
"""Our XunitView base class."""
filtermodel = GObject.Property(type=Gtk.FilterListModel)
firstcol = GObject.Property(type=Gtk.ColumnViewColumn)
def __init__(self, title: str, **kwargs):
"""Initialize an XunitView."""
factory = row.LabelFactory("name")
super().__init__(filtermodel=Gtk.FilterListModel(),
firstcol=Gtk.ColumnViewColumn(title=title,
factory=factory),
child=Gtk.ColumnView(model=Gtk.NoSelection(),
show_row_separators=True,
show_column_separators=True,
hexpand=True),
**kwargs)
self.props.child.get_model().set_model(self.filtermodel)
self.add_css_class("card")
def do_make_factory(self, xunit: str) -> row.XunitFactory:
"""Make an XunitFactory for the given xunit."""
return row.XunitFactory(xunit=xunit)
@GObject.Property(type=XunitList)
def model(self) -> XunitList | None:
"""Get the XunitList shown by the XunitView."""
return self.filtermodel.props.model
@model.setter
def model(self, new: XunitList) -> None:
for col in list(self.props.child.get_columns()):
self.props.child.remove_column(col)
self.filtermodel.props.model = new
if new is not None:
self.props.child.append_column(self.firstcol)
for xunit in new.get_xunits():
col = Gtk.ColumnViewColumn(title=xunit, expand=True,
factory=self.do_make_factory(xunit))
self.props.child.append_column(col)
class PropertyView(XunitView):
"""Displays our PropertyList model to the user."""
def __init__(self):
"""Initialize a PropertyView."""
super().__init__(child=Gtk.ColumnView(model=Gtk.NoSelection(),
show_row_separators=True,
show_column_separators=True,
hexpand=True),
vscrollbar_policy=Gtk.PolicyType.NEVER)
self._property = Gtk.ColumnViewColumn(title="property",
factory=row.LabelFactory("name"))
self._propfilter = PropertyFilter()
self._filtermodel = Gtk.FilterListModel(filter=self._propfilter)
self.props.child.get_model().set_model(self._filtermodel)
super().__init__("property", vscrollbar_policy=Gtk.PolicyType.NEVER)
self.filtermodel.set_filter(PropertyFilter())
self.props.child.add_css_class("data-table")
self.add_css_class("card")
def __property_column(self, xunit: str) -> None:
return Gtk.ColumnViewColumn(title=xunit, expand=True,
factory=row.PropertyFactory(xunit=xunit))
@GObject.Property(type=PropertyList)
def model(self) -> PropertyList:
"""Get the PropertyList shown by the View."""
return self._filtermodel.props.model
@model.setter
def model(self, new: PropertyList) -> None:
for col in [col for col in self.props.child.get_columns()]:
self.props.child.remove_column(col)
self._filtermodel.props.model = new
if new is not None:
self.props.child.append_column(self._property)
for xunit in new.get_xunits():
self.props.child.append_column(self.__property_column(xunit))
def do_make_factory(self, xunit: str) -> row.PropertyFactory:
"""Make a new PropertyFactory instance."""
return row.PropertyFactory(xunit=xunit)
class FilterButtons(Gtk.Box):
@ -79,90 +96,39 @@ class FilterButtons(Gtk.Box):
self.append(self._failure)
class TestCaseView(Gtk.ScrolledWindow):
class TestCaseView(XunitView):
"""Displays our TestCaseList model to the user."""
filterbuttons = GObject.Property(type=FilterButtons)
def __init__(self):
"""Initialize a TestCaseView."""
super().__init__(child=Gtk.ColumnView(model=Gtk.NoSelection(),
show_row_separators=True,
show_column_separators=True,
hexpand=True, vexpand=True),
filterbuttons=FilterButtons())
self._testcase = Gtk.ColumnViewColumn(title="testcase",
factory=row.LabelFactory("name"))
self._testfilter = TestCaseFilter()
self._filtermodel = Gtk.FilterListModel(filter=self._testfilter)
super().__init__("testcase", filterbuttons=FilterButtons())
self.filtermodel.props.filter = TestCaseFilter()
for prop in ["passed", "skipped", "failure"]:
self.filterbuttons.bind_property(prop, self._testfilter, prop)
self.filterbuttons.bind_property(prop,
self.filtermodel.props.filter,
prop)
self.props.child.get_model().set_model(self._filtermodel)
self.add_css_class("card")
self.props.child.set_vexpand(True)
def __xunit_column(self, xunit: str) -> None:
return Gtk.ColumnViewColumn(title=xunit, expand=True,
factory=row.ResultFactory(xunit=xunit))
def make_buttons(self) -> FilterButtons:
"""Make a new FilterButtons instance connected to this View."""
return FilterButtons()
@GObject.Property(type=TestCaseList)
def model(self) -> TestCaseList:
"""Get the TestCaseList shown by the View."""
return self._filtermodel.props.model
@model.setter
def model(self, new: TestCaseList) -> None:
for col in [col for col in self.props.child.get_columns()]:
self.props.child.remove_column(col)
self._filtermodel.props.model = new
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))
def do_make_factory(self, xunit: str) -> row.ResultFactory:
"""Make a new ResultFactory instance."""
return row.ResultFactory(xunit=xunit)
class SummaryView(Gtk.ScrolledWindow):
class SummaryView(XunitView):
"""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")
super().__init__("summary", vscrollbar_policy=Gtk.PolicyType.NEVER)
self.props.child.add_css_class("data-table")
def __summary_column(self, xunit: str) -> None:
return Gtk.ColumnViewColumn(title=xunit, expand=True,
factory=row.SummaryFactory(xunit=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))
def do_make_factory(self, xunit: str) -> row.SummaryFactory:
"""Make a new SummaryFactory instance."""
return row.SummaryFactory(xunit=xunit)
class XfstestsView(Gtk.Box):