gtk: Add a PropertyFactory
The PropertyFactory is used to display the individual property rows from each xunit. Signed-off-by: Anna Schumaker <anna@nowheycreamery.com>
This commit is contained in:
parent
59cb699bd9
commit
7ae246677b
|
@ -28,7 +28,9 @@ class TestFactory(unittest.TestCase):
|
|||
self.factory.emit("setup", self.listitem)
|
||||
self.assertIsInstance(self.listitem.get_child(), Gtk.Inscription)
|
||||
self.assertEqual(self.listitem.get_child().props.xalign, 0.5)
|
||||
self.assertEqual(self.listitem.get_child().props.nat_chars, 10)
|
||||
self.assertEqual(self.listitem.get_child().props.nat_chars, 18)
|
||||
self.assertEqual(self.listitem.get_child().props.text_overflow,
|
||||
Gtk.InscriptionOverflow.ELLIPSIZE_END)
|
||||
self.assertTrue(self.listitem.get_child().has_css_class("numeric"))
|
||||
mock_setup.assert_called_with(self.listitem.get_child())
|
||||
|
||||
|
@ -134,6 +136,31 @@ class TestLabelFactory(unittest.TestCase):
|
|||
self.assertFalse(child.has_css_class(expected))
|
||||
|
||||
|
||||
class TestPropertyFactory(unittest.TestCase):
|
||||
"""Tests our Gtk.Factory to show xunit properties."""
|
||||
|
||||
def setUp(self):
|
||||
"""Set up common variables."""
|
||||
self.property = xfstestsdb.gtk.model.Property("property")
|
||||
self.listitem = Gtk.ListItem()
|
||||
self.listitem.get_item = unittest.mock.Mock(return_value=self.property)
|
||||
|
||||
self.factory = xfstestsdb.gtk.row.PropertyFactory("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")
|
||||
|
||||
def test_bind_different(self):
|
||||
"""Test binding to the a property when all values are different."""
|
||||
self.property.add_xunit("xunit-1", "property", "value")
|
||||
self.factory.emit("setup", self.listitem)
|
||||
self.factory.emit("bind", self.listitem)
|
||||
self.assertEqual(self.listitem.get_child().get_text(), "value")
|
||||
self.assertEqual(self.listitem.get_child().get_tooltip_text(), "value")
|
||||
|
||||
|
||||
class TestResultFactory(unittest.TestCase):
|
||||
"""Tests our Gtk.Factory to show test results."""
|
||||
|
||||
|
|
|
@ -23,7 +23,8 @@ class Factory(Gtk.SignalListItemFactory):
|
|||
|
||||
def __setup(self, factory: typing.Self, listitem: Gtk.ListItem) -> None:
|
||||
"""Set up a ListItem child widget."""
|
||||
child = Gtk.Inscription(xalign=0.5, nat_chars=10)
|
||||
child = Gtk.Inscription(xalign=0.5, nat_chars=18)
|
||||
child.props.text_overflow = Gtk.InscriptionOverflow.ELLIPSIZE_END
|
||||
child.add_css_class("numeric")
|
||||
self.do_setup(child)
|
||||
listitem.set_child(child)
|
||||
|
@ -86,6 +87,22 @@ class LabelFactory(Factory):
|
|||
LabelFactory.group.remove_widget(child)
|
||||
|
||||
|
||||
class PropertyFactory(Factory):
|
||||
"""Factory for making property widgets."""
|
||||
|
||||
xunit = GObject.Property(type=str)
|
||||
|
||||
def __init__(self, xunit: str):
|
||||
"""Initialize our InscriptionFactory."""
|
||||
super().__init__(xunit=xunit)
|
||||
|
||||
def do_bind(self, row: model.TestCase, child: Gtk.Inscription) -> None:
|
||||
"""Bind a ListItem to the child widget."""
|
||||
property = row[self.xunit]
|
||||
child.set_text(property.value)
|
||||
child.set_tooltip_text(property.value)
|
||||
|
||||
|
||||
class ResultFactory(Factory):
|
||||
"""Factory for making test result widgets."""
|
||||
|
||||
|
|
Loading…
Reference in New Issue