gtk: Create an XunitFactory base class

And convert most of our Factory implementations to inherit from it. This
lets me set up the xunit property in one single place, and soon I'll be
using this factory for a XunitView base class.

Signed-off-by: Anna Schumaker <anna@nowheycreamery.com>
This commit is contained in:
Anna Schumaker 2023-08-29 15:23:25 -04:00
parent 2deb484754
commit a5d1ae4607
3 changed files with 34 additions and 32 deletions

View File

@ -136,6 +136,19 @@ class TestLabelFactory(unittest.TestCase):
self.assertFalse(child.has_css_class(expected))
class TestXunitFactory(unittest.TestCase):
"""Tests our XunitFactory base class."""
def setUp(self):
"""Set up common variables."""
self.factory = xfstestsdb.gtk.row.XunitFactory(xunit="xunit-1")
def test_init(self):
"""Test that the factory was initialized correctly."""
self.assertIsInstance(self.factory, xfstestsdb.gtk.row.Factory)
self.assertEqual(self.factory.xunit, "xunit-1")
class TestPropertyFactory(unittest.TestCase):
"""Tests our Gtk.Factory to show xunit properties."""
@ -145,15 +158,14 @@ class TestPropertyFactory(unittest.TestCase):
self.listitem = Gtk.ListItem()
self.listitem.get_item = unittest.mock.Mock(return_value=self.property)
self.factory = xfstestsdb.gtk.row.PropertyFactory("xunit-1")
self.factory = xfstestsdb.gtk.row.PropertyFactory(xunit="xunit-1")
def test_init(self):
"""Test that the factory was initialized correctly."""
self.assertIsInstance(self.factory, xfstestsdb.gtk.row.Factory)
self.assertEqual(self.factory.xunit, "xunit-1")
self.assertIsInstance(self.factory, xfstestsdb.gtk.row.XunitFactory)
def test_bind_different(self):
"""Test binding to the a property when all values are different."""
def test_bind(self):
"""Test binding to a property."""
self.property.add_xunit("xunit-1", "property", "value")
self.factory.emit("setup", self.listitem)
self.factory.emit("bind", self.listitem)
@ -176,13 +188,12 @@ class TestResultFactory(unittest.TestCase):
self.listitem = Gtk.ListItem()
self.listitem.get_item = unittest.mock.Mock(return_value=self.testcase)
self.factory = xfstestsdb.gtk.row.ResultFactory("xunit-1")
self.factory = xfstestsdb.gtk.row.ResultFactory(xunit="xunit-1")
self.factory.connect("setup", self.setup_parent)
def test_init(self):
"""Test that the factory was initialized correctly."""
self.assertIsInstance(self.factory, xfstestsdb.gtk.row.Factory)
self.assertEqual(self.factory.xunit, "xunit-1")
self.assertIsInstance(self.factory, xfstestsdb.gtk.row.XunitFactory)
def test_bind_passed(self):
"""Test binding to a passing test."""
@ -242,12 +253,11 @@ class TestSummaryFactory(unittest.TestCase):
self.listitem = Gtk.ListItem()
self.listitem.get_item = unittest.mock.Mock(return_value=self.summary)
self.factory = xfstestsdb.gtk.row.SummaryFactory("xunit-1")
self.factory = xfstestsdb.gtk.row.SummaryFactory(xunit="xunit-1")
def test_init(self):
"""Test that the factory was initialized correctly."""
self.assertIsInstance(self.factory, xfstestsdb.gtk.row.Factory)
self.assertEqual(self.factory.xunit, "xunit-1")
self.assertIsInstance(self.factory, xfstestsdb.gtk.row.XunitFactory)
def test_bind_passed(self):
"""Test binding to the passed tests summary."""

View File

@ -87,15 +87,19 @@ class LabelFactory(Factory):
LabelFactory.group.remove_widget(child)
class PropertyFactory(Factory):
"""Factory for making property widgets."""
class XunitFactory(Factory):
"""Factory base class for Xunit columns."""
xunit = GObject.Property(type=str)
def __init__(self, xunit: str):
"""Initialize our InscriptionFactory."""
def __init__(self, *, xunit: str):
"""Initialize our Xunit Factory."""
super().__init__(xunit=xunit)
class PropertyFactory(XunitFactory):
"""Factory for making property widgets."""
def do_bind(self, row: model.TestCase, child: Gtk.Inscription) -> None:
"""Bind a ListItem to the child widget."""
property = row[self.xunit]
@ -103,15 +107,9 @@ class PropertyFactory(Factory):
child.set_tooltip_text(property.value)
class ResultFactory(Factory):
class ResultFactory(XunitFactory):
"""Factory for making test result widgets."""
xunit = GObject.Property(type=str)
def __init__(self, xunit: str):
"""Initialize our ResultFactory."""
super().__init__(xunit=xunit)
def do_bind(self, row: model.TestCase, child: Gtk.Inscription) -> None:
"""Bind a ListItem to the child widget."""
if (result := row[self.xunit]) is None:
@ -130,15 +128,9 @@ class ResultFactory(Factory):
child.get_parent().remove_css_class(result.status)
class SummaryFactory(Factory):
class SummaryFactory(XunitFactory):
"""Factory for making test summary widgets."""
xunit = GObject.Property(type=str)
def __init__(self, xunit: str):
"""Initialize our ResultFactory."""
super().__init__(xunit=xunit)
def do_bind(self, row: model.Summary, child: Gtk.Inscription) -> None:
"""Bind a ListItem to the child widget."""
result = row[self.xunit]

View File

@ -33,7 +33,7 @@ class PropertyView(Gtk.ScrolledWindow):
def __property_column(self, xunit: str) -> None:
return Gtk.ColumnViewColumn(title=xunit, expand=True,
factory=row.PropertyFactory(xunit))
factory=row.PropertyFactory(xunit=xunit))
@GObject.Property(type=PropertyList)
def model(self) -> PropertyList:
@ -105,7 +105,7 @@ class TestCaseView(Gtk.ScrolledWindow):
def __xunit_column(self, xunit: str) -> None:
return Gtk.ColumnViewColumn(title=xunit, expand=True,
factory=row.ResultFactory(xunit))
factory=row.ResultFactory(xunit=xunit))
def make_buttons(self) -> FilterButtons:
"""Make a new FilterButtons instance connected to this View."""
@ -145,7 +145,7 @@ class SummaryView(Gtk.ScrolledWindow):
def __summary_column(self, xunit: str) -> None:
return Gtk.ColumnViewColumn(title=xunit, expand=True,
factory=row.SummaryFactory(xunit))
factory=row.SummaryFactory(xunit=xunit))
@GObject.Property(type=SummaryList)
def model(self) -> SummaryList: