gtk: Create a XunitCell object and rename the XunitResult object
I use the XunitCell as a base class for the (renamed) TestResult and SettingsValue objects. This lets us combine common values and functionality in one reusable place. Signed-off-by: Anna Schumaker <anna@nowheycreamery.com>
This commit is contained in:
parent
4d3425bb57
commit
ad08357121
|
@ -9,23 +9,35 @@ from gi.repository import Gio
|
|||
from gi.repository import Gtk
|
||||
|
||||
|
||||
class TestXunitResult(unittest.TestCase):
|
||||
class TestXunitCell(unittest.TestCase):
|
||||
"""Test case for our base XunitCell object."""
|
||||
|
||||
def test_cell(self):
|
||||
"""Test creating a Cell instance."""
|
||||
cell = xfstestsdb.gtk.model.XunitCell(name="my xunit name")
|
||||
self.assertIsInstance(cell, GObject.GObject)
|
||||
self.assertEqual(cell.name, "my xunit name")
|
||||
self.assertEqual(str(cell), "my xunit name")
|
||||
|
||||
|
||||
class TestTestResult(unittest.TestCase):
|
||||
"""Tests a single TestCase Xunit instance."""
|
||||
|
||||
def test_xunit_result(self):
|
||||
"""Test creating an xunit instance."""
|
||||
xunit = xfstestsdb.gtk.model.XunitResult(name="my xunit name",
|
||||
xunit = xfstestsdb.gtk.model.TestResult(name="my xunit name",
|
||||
status="passed", time=123,
|
||||
message="my message",
|
||||
stdout="my stdout",
|
||||
stderr="my stderr")
|
||||
self.assertIsInstance(xunit, GObject.GObject)
|
||||
self.assertIsInstance(xunit, xfstestsdb.gtk.model.XunitCell)
|
||||
self.assertEqual(xunit.name, "my xunit name")
|
||||
self.assertEqual(xunit.status, "passed")
|
||||
self.assertEqual(xunit.time, 123)
|
||||
self.assertEqual(xunit.message, "my message")
|
||||
self.assertEqual(xunit.stdout, "my stdout")
|
||||
self.assertEqual(xunit.stderr, "my stderr")
|
||||
self.assertEqual(str(xunit), "passed")
|
||||
|
||||
|
||||
class TestTestCase(unittest.TestCase):
|
||||
|
@ -54,7 +66,7 @@ class TestTestCase(unittest.TestCase):
|
|||
self.testcase.add_xunit("xunit-1", "passed", 123, "message",
|
||||
"stdout", "stderr")
|
||||
xunit = self.testcase["xunit-1"]
|
||||
self.assertIsInstance(xunit, xfstestsdb.gtk.model.XunitResult)
|
||||
self.assertIsInstance(xunit, xfstestsdb.gtk.model.TestResult)
|
||||
self.assertEqual(xunit.name, "xunit-1")
|
||||
self.assertEqual(xunit.status, "passed")
|
||||
self.assertEqual(xunit.time, 123)
|
||||
|
@ -64,7 +76,7 @@ class TestTestCase(unittest.TestCase):
|
|||
|
||||
self.testcase.add_xunit("xunit-2", "failed", 456, None, None, None)
|
||||
xunit = self.testcase["xunit-2"]
|
||||
self.assertIsInstance(xunit, xfstestsdb.gtk.model.XunitResult)
|
||||
self.assertIsInstance(xunit, xfstestsdb.gtk.model.TestResult)
|
||||
self.assertEqual(xunit.name, "xunit-2")
|
||||
self.assertEqual(xunit.status, "failed")
|
||||
self.assertEqual(xunit.time, 456)
|
||||
|
@ -214,7 +226,7 @@ class TestSummaryValue(unittest.TestCase):
|
|||
value = xfstestsdb.gtk.model.SummaryValue(name="my xunit name",
|
||||
value=12345,
|
||||
unit="testcase")
|
||||
self.assertIsInstance(value, GObject.GObject)
|
||||
self.assertIsInstance(value, xfstestsdb.gtk.model.XunitCell)
|
||||
self.assertEqual(value.name, "my xunit name")
|
||||
self.assertEqual(value.unit, "testcase")
|
||||
self.assertEqual(value.value, 12345)
|
||||
|
|
|
@ -7,16 +7,29 @@ from gi.repository import Gtk
|
|||
from .. import sqlite
|
||||
|
||||
|
||||
class XunitResult(GObject.GObject):
|
||||
"""The results for a single TestCase with a specific Xunit."""
|
||||
class XunitCell(GObject.GObject):
|
||||
"""Holds a single value for a single Xunit."""
|
||||
|
||||
name = GObject.Property(type=str)
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""Get a string representation of this XunitCell."""
|
||||
return self.name
|
||||
|
||||
|
||||
class TestResult(XunitCell):
|
||||
"""The results for a single TestCase with a specific Xunit."""
|
||||
|
||||
status = GObject.Property(type=str)
|
||||
time = GObject.Property(type=int)
|
||||
message = GObject.Property(type=str)
|
||||
stdout = GObject.Property(type=str)
|
||||
stderr = GObject.Property(type=str)
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""Get a string representation of this TestResult."""
|
||||
return self.status
|
||||
|
||||
|
||||
class TestCase(GObject.GObject):
|
||||
"""Collects results for a single TestCase with multiple Xunits."""
|
||||
|
@ -28,7 +41,7 @@ class TestCase(GObject.GObject):
|
|||
super().__init__(name=name)
|
||||
self.__xunits = {}
|
||||
|
||||
def __getitem__(self, xunit: str) -> XunitResult | None:
|
||||
def __getitem__(self, xunit: str) -> TestResult | None:
|
||||
"""Get the results for a specific Xunit."""
|
||||
return self.__xunits.get(xunit)
|
||||
|
||||
|
@ -43,7 +56,7 @@ class TestCase(GObject.GObject):
|
|||
message = "" if message is None else message
|
||||
stdout = "" if stdout is None else stdout
|
||||
stderr = "" if stderr is None else stderr
|
||||
self.__xunits[name] = XunitResult(name=name, status=status, time=time,
|
||||
self.__xunits[name] = TestResult(name=name, status=status, time=time,
|
||||
message=message, stdout=stdout,
|
||||
stderr=stderr)
|
||||
|
||||
|
@ -134,7 +147,7 @@ class TestCaseFilter(Gtk.Filter):
|
|||
return False
|
||||
|
||||
|
||||
class SummaryValue(GObject.GObject):
|
||||
class SummaryValue(XunitCell):
|
||||
"""The summary of a single Xfstests xunit field."""
|
||||
|
||||
name = GObject.Property(type=str)
|
||||
|
|
Loading…
Reference in New Issue
Block a user