From 7ae246677b8f4967caaf3595e12acc7a56f33e3e Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 15 Aug 2023 14:36:38 -0400 Subject: [PATCH] gtk: Add a PropertyFactory The PropertyFactory is used to display the individual property rows from each xunit. Signed-off-by: Anna Schumaker --- tests/gtk/test_row.py | 29 ++++++++++++++++++++++++++++- xfstestsdb/gtk/row.py | 19 ++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/tests/gtk/test_row.py b/tests/gtk/test_row.py index 9572568..0c2fde7 100644 --- a/tests/gtk/test_row.py +++ b/tests/gtk/test_row.py @@ -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.""" diff --git a/xfstestsdb/gtk/row.py b/xfstestsdb/gtk/row.py index 4fe5e91..c00dd32 100644 --- a/xfstestsdb/gtk/row.py +++ b/xfstestsdb/gtk/row.py @@ -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."""