gtk: Create an EnvironmentFactory

This is different from our other xunit factories. Instead of displaying
values for each xunit, it looks into what we determine to be environment
properties and displays those instead.

Signed-off-by: Anna Schumaker <anna@nowheycreamery.com>
This commit is contained in:
Anna Schumaker 2023-08-29 17:15:17 -04:00
parent 7c7e279648
commit 02452069da
2 changed files with 51 additions and 0 deletions

View File

@ -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."""

View File

@ -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."""