gtk: Add a PropertyView
The PropertyView displays the properties of each Xunit added to the displayed Xfstests run. Signed-off-by: Anna Schumaker <anna@nowheycreamery.com>
This commit is contained in:
parent
7ae246677b
commit
c145a67ae6
|
@ -6,6 +6,86 @@ import xfstestsdb.gtk.view
|
|||
from gi.repository import Gtk
|
||||
|
||||
|
||||
class TestPropertyView(unittest.TestCase):
|
||||
"""Tests the PropertyView."""
|
||||
|
||||
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.model = xfstestsdb.gtk.model.PropertyList(self.xfstestsdb.sql, 1)
|
||||
self.view = xfstestsdb.gtk.view.PropertyView()
|
||||
|
||||
def test_init(self):
|
||||
"""Test that we created the ProeprtyView correctly."""
|
||||
self.assertIsInstance(self.view, Gtk.ScrolledWindow)
|
||||
self.assertEqual(self.view.props.vscrollbar_policy,
|
||||
Gtk.PolicyType.NEVER)
|
||||
self.assertTrue(self.view.has_css_class("card"))
|
||||
self.assertIsNone(self.view.model)
|
||||
|
||||
def test_columnview(self):
|
||||
"""Test that we set up the Columnview correctly."""
|
||||
self.assertIsInstance(self.view.props.child, Gtk.ColumnView)
|
||||
self.assertIsInstance(self.view.props.child.get_model(),
|
||||
Gtk.NoSelection)
|
||||
self.assertEqual(len(self.view.props.child.get_columns()), 0)
|
||||
self.assertTrue(self.view.props.child.get_show_column_separators())
|
||||
self.assertTrue(self.view.props.child.get_show_row_separators())
|
||||
self.assertTrue(self.view.props.child.get_hexpand())
|
||||
self.assertTrue(self.view.props.child.has_css_class("data-table"))
|
||||
|
||||
def test_filter(self):
|
||||
"""Test that we set up the Gtk.FilterModel correctly."""
|
||||
self.assertIsInstance(self.view._filtermodel, Gtk.FilterListModel)
|
||||
self.assertIsInstance(self.view._propfilter,
|
||||
xfstestsdb.gtk.model.PropertyFilter)
|
||||
|
||||
self.assertEqual(self.view.props.child.get_model().get_model(),
|
||||
self.view._filtermodel)
|
||||
self.assertEqual(self.view._filtermodel.props.filter,
|
||||
self.view._propfilter)
|
||||
|
||||
def test_property_column(self):
|
||||
"""Test that we set up the 'property' column correctly."""
|
||||
self.assertIsInstance(self.view._property, Gtk.ColumnViewColumn)
|
||||
self.assertIsInstance(self.view._property.props.factory,
|
||||
xfstestsdb.gtk.row.LabelFactory)
|
||||
self.assertEqual(self.view._property.props.factory.property, "name")
|
||||
self.assertEqual(self.view._property.props.title, "property")
|
||||
self.assertFalse(self.view._property.props.expand)
|
||||
|
||||
def test_model(self):
|
||||
"""Test setting the model property."""
|
||||
self.view.model = self.model
|
||||
self.assertEqual(self.view._filtermodel.props.model, self.model)
|
||||
|
||||
columns = self.view.props.child.get_columns()
|
||||
self.assertEqual(len(columns), 3)
|
||||
self.assertEqual(columns[0], self.view._property)
|
||||
|
||||
for i, title in enumerate(["xunit-1", "xunit-2"], start=1):
|
||||
with self.subTest(i=i, title=title):
|
||||
self.assertIsInstance(columns[i].props.factory,
|
||||
xfstestsdb.gtk.row.PropertyFactory)
|
||||
self.assertEqual(columns[i].props.factory.xunit, title)
|
||||
self.assertEqual(columns[i].props.title, title)
|
||||
self.assertTrue(columns[i].props.expand)
|
||||
|
||||
self.view.model = None
|
||||
self.assertEqual(len(self.view.props.child.get_columns()), 0)
|
||||
|
||||
self.view.model = self.model
|
||||
self.assertEqual(self.view.props.child.get_columns()[0],
|
||||
self.view._property)
|
||||
|
||||
|
||||
class TestFilterButtons(unittest.TestCase):
|
||||
"""Test case for our TestCaseView FilterButtons."""
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
"""A view widget used to display our TestCaseModel."""
|
||||
from gi.repository import GObject
|
||||
from gi.repository import Gtk
|
||||
from .model import PropertyList
|
||||
from .model import PropertyFilter
|
||||
from .model import TestCaseList
|
||||
from .model import TestCaseFilter
|
||||
from .model import SummaryList
|
||||
|
@ -9,6 +11,48 @@ from . import button
|
|||
from . import row
|
||||
|
||||
|
||||
class PropertyView(Gtk.ScrolledWindow):
|
||||
"""Displays our PropertyList model to the user."""
|
||||
|
||||
def __init__(self):
|
||||
"""Initialize a PropertyView."""
|
||||
super().__init__(child=Gtk.ColumnView(model=Gtk.NoSelection(),
|
||||
show_row_separators=True,
|
||||
show_column_separators=True,
|
||||
hexpand=True),
|
||||
vscrollbar_policy=Gtk.PolicyType.NEVER)
|
||||
self._property = Gtk.ColumnViewColumn(title="property",
|
||||
factory=row.LabelFactory("name"))
|
||||
|
||||
self._propfilter = PropertyFilter()
|
||||
self._filtermodel = Gtk.FilterListModel(filter=self._propfilter)
|
||||
|
||||
self.props.child.get_model().set_model(self._filtermodel)
|
||||
self.props.child.add_css_class("data-table")
|
||||
self.add_css_class("card")
|
||||
|
||||
def __property_column(self, xunit: str) -> None:
|
||||
return Gtk.ColumnViewColumn(title=xunit, expand=True,
|
||||
factory=row.PropertyFactory(xunit))
|
||||
|
||||
@GObject.Property(type=PropertyList)
|
||||
def model(self) -> PropertyList:
|
||||
"""Get the PropertyList shown by the View."""
|
||||
return self._filtermodel.props.model
|
||||
|
||||
@model.setter
|
||||
def model(self, new: PropertyList) -> None:
|
||||
for col in [col for col in self.props.child.get_columns()]:
|
||||
self.props.child.remove_column(col)
|
||||
|
||||
self._filtermodel.props.model = new
|
||||
|
||||
if new is not None:
|
||||
self.props.child.append_column(self._property)
|
||||
for xunit in new.get_xunits():
|
||||
self.props.child.append_column(self.__property_column(xunit))
|
||||
|
||||
|
||||
class FilterButtons(Gtk.Box):
|
||||
"""Buttons for controlling the TestCaseFilter."""
|
||||
|
||||
|
|
Loading…
Reference in New Issue