168 lines
7.3 KiB
Python
168 lines
7.3 KiB
Python
# Copyright 2023 (c) Anna Schumaker.
|
|
"""Tests our row widgets and factories."""
|
|
import unittest
|
|
import xfstestsdb.gtk.row
|
|
from gi.repository import Gtk
|
|
from gi.repository import Adw
|
|
|
|
|
|
class TestLabelFactory(unittest.TestCase):
|
|
"""Tests our Gtk.Factory to make Gtk.Labels."""
|
|
|
|
def setUp(self):
|
|
"""Set up common variables."""
|
|
self.testcase = xfstestsdb.gtk.model.TestCase("test/case")
|
|
self.listitem = Gtk.ListItem()
|
|
self.listitem.get_item = unittest.mock.Mock(return_value=self.testcase)
|
|
|
|
self.factory = xfstestsdb.gtk.row.LabelFactory("name")
|
|
self.group = xfstestsdb.gtk.row.LabelFactory.group
|
|
|
|
def test_init(self):
|
|
"""Test that the factory was initialized correctly."""
|
|
self.assertIsInstance(self.factory, Gtk.SignalListItemFactory)
|
|
self.assertEqual(self.factory.property, "name")
|
|
|
|
def test_size_group(self):
|
|
"""Test the label factory global size group."""
|
|
self.assertIsInstance(xfstestsdb.gtk.row.LabelFactory.group,
|
|
Gtk.SizeGroup)
|
|
self.assertEqual(xfstestsdb.gtk.row.LabelFactory.group.props.mode,
|
|
Gtk.SizeGroupMode.HORIZONTAL)
|
|
|
|
def test_setup(self):
|
|
"""Test that the factory implements the 'setup' signal."""
|
|
self.factory.emit("setup", self.listitem)
|
|
self.assertIsInstance(self.listitem.get_child(), Gtk.Label)
|
|
self.assertTrue(self.listitem.get_child().has_css_class("numeric"))
|
|
self.assertIn(self.listitem.get_child(), self.group.get_widgets())
|
|
|
|
def test_bind(self):
|
|
"""Test that the factory implements the 'bind' signal."""
|
|
self.factory.emit("setup", self.listitem)
|
|
self.factory.emit("bind", self.listitem)
|
|
self.assertEqual(self.listitem.get_child().get_text(), "test/case")
|
|
for style in xfstestsdb.gtk.row.STYLES.keys():
|
|
self.assertFalse(self.listitem.get_child().has_css_class(style))
|
|
|
|
def test_unbind(self):
|
|
"""Test that the factory implements the 'unbind' signal."""
|
|
self.factory.emit("setup", self.listitem)
|
|
self.factory.emit("bind", self.listitem)
|
|
self.factory.emit("unbind", self.listitem)
|
|
self.assertEqual(self.listitem.get_child().get_text(), "")
|
|
|
|
def test_teardown(self):
|
|
"""Test that the factory implements the 'teardown' signal."""
|
|
self.factory.emit("setup", self.listitem)
|
|
child = self.listitem.get_child()
|
|
self.factory.emit("teardown", self.listitem)
|
|
self.assertIsNone(self.listitem.get_child())
|
|
self.assertNotIn(child, self.group.get_widgets())
|
|
|
|
def test_styles(self):
|
|
"""Test the column text styles."""
|
|
self.assertDictEqual(xfstestsdb.gtk.row.STYLES,
|
|
{"passed": "success", "failed": "error",
|
|
"skipped": "warning", "time": "accent"})
|
|
for style in ["passed", "failed", "skipped", "time"]:
|
|
with self.subTest(style=style):
|
|
self.testcase.name = style
|
|
self.factory.emit("setup", self.listitem)
|
|
self.factory.emit("bind", self.listitem)
|
|
|
|
child = self.listitem.get_child()
|
|
expected = xfstestsdb.gtk.row.STYLES[style]
|
|
self.assertTrue(child.has_css_class(expected))
|
|
|
|
self.factory.emit("unbind", self.listitem)
|
|
self.assertFalse(child.has_css_class(expected))
|
|
|
|
|
|
class TestResultFactory(unittest.TestCase):
|
|
"""Tests our Gtk.Factory to show test results."""
|
|
|
|
def setup_parent(self, factory: xfstestsdb.gtk.row.ResultFactory,
|
|
listitem: Gtk.ListItem) -> None:
|
|
"""Set the child widget's parent for custom styling."""
|
|
self.parent.set_child(listitem.get_child())
|
|
|
|
def setUp(self):
|
|
"""Set up common variables."""
|
|
self.testcase = xfstestsdb.gtk.model.TestCase("test/case")
|
|
self.parent = Adw.Bin()
|
|
self.listitem = Gtk.ListItem()
|
|
self.listitem.get_item = unittest.mock.Mock(return_value=self.testcase)
|
|
|
|
self.factory = xfstestsdb.gtk.row.ResultFactory("xunit-1")
|
|
self.factory.connect("setup", self.setup_parent)
|
|
|
|
def test_init(self):
|
|
"""Test that the factory was initialized correctly."""
|
|
self.assertIsInstance(self.factory, Gtk.SignalListItemFactory)
|
|
self.assertEqual(self.factory.xunit, "xunit-1")
|
|
|
|
def test_setup(self):
|
|
"""Test that the factory implements the 'setup' signal."""
|
|
self.factory.emit("setup", self.listitem)
|
|
self.assertIsInstance(self.listitem.get_child(), Gtk.Label)
|
|
self.assertTrue(self.listitem.get_child().has_css_class("numeric"))
|
|
self.assertEqual(self.parent.get_child(), self.listitem.get_child())
|
|
|
|
def test_bind_passed(self):
|
|
"""Test binding to a passing test."""
|
|
self.testcase.add_xunit("xunit-1", "passed", 3, "", None, None)
|
|
self.factory.emit("setup", self.listitem)
|
|
self.factory.emit("bind", self.listitem)
|
|
self.assertEqual(self.listitem.get_child().get_text(), "3 seconds")
|
|
self.assertIsNone(self.listitem.get_child().get_tooltip_text())
|
|
self.assertTrue(self.parent.has_css_class("passed"))
|
|
|
|
self.factory.emit("unbind", self.listitem)
|
|
self.assertEqual(self.listitem.get_child().get_text(), "")
|
|
self.assertFalse(self.parent.has_css_class("passed"))
|
|
|
|
def test_bind_skipped(self):
|
|
"""Test binding to a skipped test."""
|
|
self.testcase.add_xunit("xunit-1", "skipped", 0,
|
|
"test skipped for ... reasons", None, None)
|
|
self.factory.emit("setup", self.listitem)
|
|
self.factory.emit("bind", self.listitem)
|
|
self.assertEqual(self.listitem.get_child().get_text(), "skipped")
|
|
self.assertEqual(self.listitem.get_child().get_tooltip_text(),
|
|
"test skipped for ... reasons")
|
|
self.assertTrue(self.parent.has_css_class("skipped"))
|
|
|
|
self.factory.emit("unbind", self.listitem)
|
|
self.assertEqual(self.listitem.get_child().get_text(), "")
|
|
self.assertFalse(self.parent.has_css_class("skipped"))
|
|
|
|
def test_bind_failed(self):
|
|
"""Test binding to a failed test."""
|
|
self.testcase.add_xunit("xunit-1", "failure", 8,
|
|
"- failed. see output", None, None)
|
|
self.factory.emit("setup", self.listitem)
|
|
self.factory.emit("bind", self.listitem)
|
|
self.assertEqual(self.listitem.get_child().get_text(), "failure")
|
|
self.assertEqual(self.listitem.get_child().get_tooltip_text(),
|
|
"failed. see output")
|
|
self.assertTrue(self.parent.has_css_class("failure"))
|
|
|
|
self.factory.emit("unbind", self.listitem)
|
|
self.assertEqual(self.listitem.get_child().get_text(), "")
|
|
self.assertFalse(self.parent.has_css_class("failure"))
|
|
|
|
def test_bind_missing(self):
|
|
"""Test binding to a missing test."""
|
|
self.factory.emit("setup", self.listitem)
|
|
self.factory.emit("bind", self.listitem)
|
|
self.assertEqual(self.listitem.get_child().get_text(), "")
|
|
|
|
self.factory.emit("unbind", self.listitem)
|
|
|
|
def test_teardown(self):
|
|
"""Test that the factory implements the 'teardown' signal."""
|
|
self.factory.emit("setup", self.listitem)
|
|
self.factory.emit("teardown", self.listitem)
|
|
self.assertIsNone(self.listitem.get_child())
|