diff --git a/tests/gtk/test_row.py b/tests/gtk/test_row.py index 6174db6..d195b25 100644 --- a/tests/gtk/test_row.py +++ b/tests/gtk/test_row.py @@ -2,6 +2,7 @@ """Tests our row widgets and factories.""" import unittest import xfstestsdb.gtk.row +import tests.xunit from gi.repository import Gtk from gi.repository import Adw @@ -136,6 +137,39 @@ class TestLabelFactory(unittest.TestCase): self.assertFalse(child.has_css_class(expected)) +class TestEnvironmentFactory(unittest.TestCase): + """Tests our Gtk.Factory to show environment properties.""" + + 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.props = xfstestsdb.gtk.model.PropertyList(self.xfstestsdb.sql, 1) + self.listitem = Gtk.ListItem() + self.listitem.get_item = unittest.mock.Mock(return_value=self.props) + + self.factory = xfstestsdb.gtk.row.EnvironmentFactory(property="FSTYP") + + def test_init(self): + """Test that the factory was initialized correctly.""" + self.assertIsInstance(self.factory, xfstestsdb.gtk.row.Factory) + self.assertEqual(self.factory.property, "FSTYP") + + def test_bind(self): + """Test binding to a property.""" + self.factory.emit("setup", self.listitem) + self.factory.emit("bind", self.listitem) + self.assertEqual(self.listitem.get_child().get_xalign(), 0) + self.assertEqual(self.listitem.get_child().get_text(), "myfs") + self.assertEqual(self.listitem.get_child().get_tooltip_text(), "myfs") + + class TestXunitFactory(unittest.TestCase): """Tests our XunitFactory base class.""" diff --git a/xfstestsdb/gtk/row.py b/xfstestsdb/gtk/row.py index ee5ac9e..f17dec7 100644 --- a/xfstestsdb/gtk/row.py +++ b/xfstestsdb/gtk/row.py @@ -87,6 +87,23 @@ class LabelFactory(Factory): LabelFactory.group.remove_widget(child) +class EnvironmentFactory(Factory): + """Factory for Environment property columns.""" + + property = GObject.Property(type=str) + + def __init__(self, *, property: str): + """Initialize our Environment Factory.""" + super().__init__(property=property) + + def do_bind(self, row: model.PropertyList, child: Gtk.Inscription) -> None: + """Bind an Environment property to the child widget.""" + text = row.get_environment()[self.property] + child.set_xalign(0) + child.set_text(text) + child.set_tooltip_text(text) + + class XunitFactory(Factory): """Factory base class for Xunit columns."""