model: Give the PropertyList "environment" detection
I define the envorionment as properties that are the same across each added xunit, as long as there are more than 1 added xunits. I add an 'environment' property to make it easy to get the current set of environment properties. Signed-off-by: Anna Schumaker <anna@nowheycreamery.com>
This commit is contained in:
parent
c861c49564
commit
7c7e279648
|
@ -45,6 +45,7 @@ class TestXunitRow(unittest.TestCase):
|
|||
|
||||
self.row.add_xunit("xunit-1")
|
||||
self.assertSetEqual(self.row.get_results(), {"xunit-1"})
|
||||
self.assertListEqual(self.row.get_xunits(), ["xunit-1"])
|
||||
|
||||
xunit = self.row["xunit-1"]
|
||||
self.assertIsInstance(xunit, xfstestsdb.gtk.model.XunitCell)
|
||||
|
@ -52,6 +53,7 @@ class TestXunitRow(unittest.TestCase):
|
|||
|
||||
self.row.add_xunit("xunit-2")
|
||||
self.assertSetEqual(self.row.get_results(), {"xunit-1", "xunit-2"})
|
||||
self.assertListEqual(self.row.get_xunits(), ["xunit-1", "xunit-2"])
|
||||
|
||||
xunit = self.row["xunit-2"]
|
||||
self.assertIsInstance(xunit, xfstestsdb.gtk.model.XunitCell)
|
||||
|
@ -130,6 +132,8 @@ class TestProperty(unittest.TestCase):
|
|||
def test_xunits(self):
|
||||
"""Test adding xunits to a Property."""
|
||||
self.assertIsNone(self.property["xunit-1"])
|
||||
self.assertIsNone(self.property.get_value())
|
||||
self.assertFalse(self.property.all_same_value())
|
||||
|
||||
self.property.add_xunit("xunit-1", "PLATFORM", "linux-123")
|
||||
property = self.property["xunit-1"]
|
||||
|
@ -137,7 +141,8 @@ class TestProperty(unittest.TestCase):
|
|||
self.assertEqual(property.name, "xunit-1")
|
||||
self.assertEqual(property.key, "PLATFORM")
|
||||
self.assertEqual(property.value, "linux-123")
|
||||
self.assertTrue(self.property.all_same_value())
|
||||
self.assertFalse(self.property.all_same_value())
|
||||
self.assertIsNone(self.property.get_value())
|
||||
|
||||
self.property.add_xunit("xunit-2", "PLATFORM", "linux-123")
|
||||
property = self.property["xunit-2"]
|
||||
|
@ -146,9 +151,11 @@ class TestProperty(unittest.TestCase):
|
|||
self.assertEqual(property.key, "PLATFORM")
|
||||
self.assertEqual(property.value, "linux-123")
|
||||
self.assertTrue(self.property.all_same_value())
|
||||
self.assertEqual(self.property.get_value(), "linux-123")
|
||||
|
||||
self.property.add_xunit("xunit-3", "PLATFORM", "linux-456")
|
||||
self.assertFalse(self.property.all_same_value())
|
||||
self.assertIsNone(self.property.get_value())
|
||||
|
||||
|
||||
class TestPropertyList(unittest.TestCase):
|
||||
|
@ -172,6 +179,16 @@ class TestPropertyList(unittest.TestCase):
|
|||
self.assertEqual(self.prlist.runid, 1)
|
||||
self.assertEqual(self.prlist.n_items, 15)
|
||||
|
||||
def test_environment(self):
|
||||
"""Test environment handling."""
|
||||
self.assertIsInstance(self.prlist.environment, Gio.ListStore)
|
||||
self.assertEqual(len(self.prlist.environment), 1)
|
||||
self.assertEqual(self.prlist.environment[0], self.prlist)
|
||||
|
||||
env = self.prlist.get_environment()
|
||||
self.assertDictEqual(env, {"FSTYP": "myfs",
|
||||
"CHECK_OPTIONS": "-r -R xunit -g quick"})
|
||||
|
||||
|
||||
class TestPropertyFilter(unittest.TestCase):
|
||||
"""Tests our Gtk.Filter customized for filtering Properties."""
|
||||
|
@ -185,14 +202,27 @@ class TestPropertyFilter(unittest.TestCase):
|
|||
self.assertIsInstance(self.filter, Gtk.Filter)
|
||||
self.assertEqual(self.filter.get_strictness(), Gtk.FilterMatch.SOME)
|
||||
|
||||
def test_hidden_properties(self):
|
||||
"""Test the hidden properties global variable."""
|
||||
self.assertSetEqual(xfstestsdb.gtk.model.HIDDEN_PROPERTIES,
|
||||
{"CPUS", "HOST_OPTIONS", "LOAD_FACTOR",
|
||||
"MEM_KB", "NUMA_NODES", "OVL_LOWER",
|
||||
"OVL_UPPER", "OVL_WORK", "PLATFORM",
|
||||
"SECTION", "SWAP_KB", "TIME_FACTOR"})
|
||||
|
||||
def test_match(self):
|
||||
"""Test matching Properties with the Filter."""
|
||||
property = xfstestsdb.gtk.model.Property("name")
|
||||
self.assertTrue(self.filter.match(property))
|
||||
|
||||
for prop in ["CPUS", "HOST_OPTIONS", "MEM_KB", "LOAD_FACTOR",
|
||||
"NUMA_NODES", "OVL_LOWER", "OVL_UPPER", "OVL_WORK",
|
||||
"PLATFORM", "SECTION", "SWAP_KB", "TIME_FACTOR"]:
|
||||
property.add_xunit("xunit-1", "name", "my name")
|
||||
self.assertTrue(self.filter.match(property))
|
||||
property.add_xunit("xunit-2", "name", "my name")
|
||||
self.assertFalse(self.filter.match(property))
|
||||
property.add_xunit("xunit-3", "name", "my other name")
|
||||
self.assertTrue(self.filter.match(property))
|
||||
|
||||
for prop in xfstestsdb.gtk.model.HIDDEN_PROPERTIES:
|
||||
with self.subTest(property=prop):
|
||||
property.name = prop
|
||||
self.assertFalse(self.filter.match(property))
|
||||
|
|
|
@ -48,6 +48,10 @@ class XunitRow(GObject.GObject):
|
|||
"""Get a set of results for each added xunit."""
|
||||
return {str(xunit) for xunit in self.__xunits.values()}
|
||||
|
||||
def get_xunits(self) -> set[str]:
|
||||
"""Get a set of xunits added to this row."""
|
||||
return list(sorted(self.__xunits.keys()))
|
||||
|
||||
|
||||
class XunitList(GObject.GObject, Gio.ListModel):
|
||||
"""A list of XunitRows for a specific Xfstests Run."""
|
||||
|
@ -93,6 +97,11 @@ class XunitList(GObject.GObject, Gio.ListModel):
|
|||
return sorted(self.__xunits)
|
||||
|
||||
|
||||
HIDDEN_PROPERTIES = {"CPUS", "HOST_OPTIONS", "LOAD_FACTOR", "MEM_KB",
|
||||
"NUMA_NODES", "OVL_LOWER", "OVL_UPPER", "OVL_WORK",
|
||||
"PLATFORM", "SECTION", "SWAP_KB", "TIME_FACTOR"}
|
||||
|
||||
|
||||
class PropertyValue(XunitCell):
|
||||
"""A single Property for a specific Xunit."""
|
||||
|
||||
|
@ -113,12 +122,25 @@ class Property(XunitRow):
|
|||
|
||||
def all_same_value(self) -> bool:
|
||||
"""Check if all the xunits have the same value."""
|
||||
return len(self.get_results()) == 1
|
||||
return len(self.get_results()) == 1 and len(self.get_xunits()) > 1
|
||||
|
||||
def get_value(self) -> str | None:
|
||||
"""Get the value of this row if all xunits have the same value."""
|
||||
if self.all_same_value():
|
||||
return self[self.get_xunits()[0]].value
|
||||
|
||||
|
||||
class PropertyList(XunitList):
|
||||
"""A list of Properties for a specific Xfstests Run."""
|
||||
|
||||
environment = GObject.Property(type=Gio.ListStore)
|
||||
|
||||
def __init__(self, sql: sqlite.Connection, runid: int) -> None:
|
||||
"""Initialize an XunitList."""
|
||||
super().__init__(sql=sql, runid=runid)
|
||||
self.environment = Gio.ListStore()
|
||||
self.environment.append(self)
|
||||
|
||||
def do_query(self, sql: sqlite.Connection) -> sqlite3.Cursor:
|
||||
"""Query the database for properties."""
|
||||
return sql("""SELECT xunit, key, value FROM xunit_properties_view
|
||||
|
@ -129,6 +151,11 @@ class PropertyList(XunitList):
|
|||
property = rows.setdefault(row["key"], Property(row["key"]))
|
||||
property.add_xunit(row["xunit"], row["key"], row["value"])
|
||||
|
||||
def get_environment(self) -> dict[str, str]:
|
||||
"""Get a dictionary of 'environment' properties."""
|
||||
return {row.name: row.get_value() for row in self
|
||||
if row.name not in HIDDEN_PROPERTIES and row.all_same_value()}
|
||||
|
||||
|
||||
class PropertyFilter(Gtk.Filter):
|
||||
"""A filter for Properties."""
|
||||
|
@ -139,10 +166,8 @@ class PropertyFilter(Gtk.Filter):
|
|||
|
||||
def do_match(self, property: Property) -> bool:
|
||||
"""Check if a property matches the filter."""
|
||||
hidden = {"CPUS", "HOST_OPTIONS", "LOAD_FACTOR", "MEM_KB",
|
||||
"NUMA_NODES", "OVL_LOWER", "OVL_UPPER", "OVL_WORK",
|
||||
"PLATFORM", "SECTION", "SWAP_KB", "TIME_FACTOR"}
|
||||
return property.name not in hidden
|
||||
return property.name not in HIDDEN_PROPERTIES \
|
||||
and not property.all_same_value()
|
||||
|
||||
|
||||
class TestResult(XunitCell):
|
||||
|
|
Loading…
Reference in New Issue