xfstestsdb/tests/gtk/test_view.py

366 lines
15 KiB
Python

# Copyright 2023 (c) Anna Schumaker.
"""Tests our TestCaseView for displaying xfstests results."""
import unittest
import tests.xunit
import xfstestsdb.gtk.view
from gi.repository import Gtk
class TestXunitView(unittest.TestCase):
"""Tests the XunitView base class."""
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.XunitList(self.xfstestsdb.sql, 1)
self.view = xfstestsdb.gtk.view.XunitView("title")
def test_init(self):
"""Test that we created the XunitView correctly."""
self.assertIsInstance(self.view, Gtk.ScrolledWindow)
self.assertTrue(self.view.has_css_class("card"))
def test_columnview(self):
"""Test that we set up the ColumnView child 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())
def test_filtermodel(self):
"""Test that we set up the Gtk.FilterModel correctly."""
self.assertIsInstance(self.view.filtermodel, Gtk.FilterListModel)
self.assertIsNone(self.view.filtermodel.props.filter)
self.assertEqual(self.view.props.child.get_model().get_model(),
self.view.filtermodel)
def test_firstcol(self):
"""Test that we set up the first column correctly."""
self.assertIsInstance(self.view.firstcol, Gtk.ColumnViewColumn)
self.assertIsInstance(self.view.firstcol.props.factory,
xfstestsdb.gtk.row.LabelFactory)
self.assertEqual(self.view.firstcol.props.factory.property, "name")
self.assertEqual(self.view.firstcol.props.title, "title")
self.assertFalse(self.view.firstcol.props.expand)
def test_model(self):
"""Test the model property."""
columns = self.view.props.child.get_columns()
self.assertIsNone(self.view.model)
self.assertEqual(len(columns), 0)
self.view.model = self.model
self.assertEqual(self.view.filtermodel.props.model, self.model)
self.assertEqual(len(columns), 3)
self.assertEqual(columns[0], self.view.firstcol)
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.XunitFactory)
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(columns), 0)
class EnvironmentView(unittest.TestCase):
"""Tests the EnvironmentView."""
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.model = self.props.environment
self.view = xfstestsdb.gtk.view.EnvironmentView()
def test_init(self):
"""Test that we created the EnvironmentView correctly."""
self.assertIsInstance(self.view, xfstestsdb.gtk.view.XunitView)
self.assertIsNone(self.view.filtermodel.props.filter)
self.assertIsNone(self.view.firstcol)
self.assertIsNone(self.view.model)
self.assertTrue(self.view.props.child.has_css_class("data-table"))
def test_make_factory(self):
"""Test the do_make_factory() implementation."""
factory = self.view.do_make_factory("property")
self.assertIsInstance(factory, xfstestsdb.gtk.row.EnvironmentFactory)
self.assertEqual(factory.property, "property")
def test_model(self):
"""Test the model property."""
columns = self.view.props.child.get_columns()
self.assertIsNone(self.view.model)
self.assertEqual(len(columns), 0)
self.assertFalse(self.view.props.visible)
self.view.model = self.model
self.assertEqual(self.view.filtermodel.props.model, self.model)
self.assertEqual(len(columns), 7)
self.assertTrue(self.view.props.visible)
self.view.model = None
self.assertEqual(len(columns), 0)
self.assertFalse(self.view.props.visible)
class TestPropertyView(unittest.TestCase):
"""Tests the PropertyView."""
def setUp(self):
"""Set up common variables."""
self.view = xfstestsdb.gtk.view.PropertyView()
def test_init(self):
"""Test that we created the ProeprtyView correctly."""
self.assertIsInstance(self.view, xfstestsdb.gtk.view.XunitView)
self.assertIsInstance(self.view.filtermodel.props.filter,
xfstestsdb.gtk.model.PropertyFilter)
self.assertIsNone(self.view.model)
self.assertEqual(self.view.props.vscrollbar_policy,
Gtk.PolicyType.NEVER)
self.assertEqual(self.view.firstcol.props.title, "property")
self.assertTrue(self.view.props.child.has_css_class("data-table"))
def test_make_factory(self):
"""Test the do_make_factory() implementation."""
factory = self.view.do_make_factory("xunit-1")
self.assertIsInstance(factory, xfstestsdb.gtk.row.PropertyFactory)
self.assertEqual(factory.xunit, "xunit-1")
class TestFilterButtons(unittest.TestCase):
"""Test case for our TestCaseView FilterButtons."""
def setUp(self):
"""Set up common variables."""
self.buttons = xfstestsdb.gtk.view.FilterButtons()
def test_init(self):
"""Check that the buttons were created correctly."""
self.assertIsInstance(self.buttons, Gtk.Box)
self.assertTrue(self.buttons.has_css_class("linked"))
def test_passed_button(self):
"""Test the 'passed' button."""
self.assertIsInstance(self.buttons._passed,
xfstestsdb.gtk.button.StatusToggle)
self.assertEqual(self.buttons.get_first_child(), self.buttons._passed)
self.assertEqual(self.buttons._passed.props.icon_name, "test-pass")
self.assertTrue(self.buttons._passed.has_css_class("passed"))
self.assertFalse(self.buttons._passed.props.active)
self.assertFalse(self.buttons.passed)
self.buttons._passed.props.active = True
self.assertTrue(self.buttons.passed)
def test_skipped_button(self):
"""Test the 'skipped' button."""
self.assertIsInstance(self.buttons._skipped,
xfstestsdb.gtk.button.StatusToggle)
self.assertEqual(self.buttons._passed.get_next_sibling(),
self.buttons._skipped)
self.assertEqual(self.buttons._skipped.props.icon_name, "test-skip")
self.assertTrue(self.buttons._skipped.has_css_class("skipped"))
self.assertFalse(self.buttons._skipped.props.active)
self.assertFalse(self.buttons.skipped)
self.buttons._skipped.props.active = True
self.assertTrue(self.buttons.skipped)
def test_failure_button(self):
"""Test the 'failure' button."""
self.assertIsInstance(self.buttons._failure,
xfstestsdb.gtk.button.StatusToggle)
self.assertEqual(self.buttons._skipped.get_next_sibling(),
self.buttons._failure)
self.assertEqual(self.buttons._failure.props.icon_name, "test-fail")
self.assertTrue(self.buttons._failure.has_css_class("failure"))
self.assertTrue(self.buttons._failure.props.active)
self.assertTrue(self.buttons.failure)
self.buttons._failure.props.active = False
self.assertFalse(self.buttons.failure)
class TestTestCaseView(unittest.TestCase):
"""Tests the TestCaseView."""
def setUp(self):
"""Set up common variables."""
self.view = xfstestsdb.gtk.view.TestCaseView()
def test_init(self):
"""Test that we create the TestCaseView correctly."""
self.assertIsInstance(self.view, xfstestsdb.gtk.view.XunitView)
self.assertIsInstance(self.view.filtermodel.props.filter,
xfstestsdb.gtk.model.TestCaseFilter)
self.assertIsNone(self.view.model)
self.assertEqual(self.view.firstcol.props.title, "testcase")
self.assertTrue(self.view.props.child.get_vexpand())
def test_filter(self):
"""Test that we set up the Gtk.FilterModel and Buttons correctly."""
self.assertIsInstance(self.view.filterbuttons,
xfstestsdb.gtk.view.FilterButtons)
self.assertFalse(self.view.filtermodel.props.filter.passed)
self.view.filterbuttons.passed = True
self.assertTrue(self.view.filtermodel.props.filter.passed)
self.assertFalse(self.view.filtermodel.props.filter.skipped)
self.view.filterbuttons.skipped = True
self.assertTrue(self.view.filtermodel.props.filter.skipped)
self.assertTrue(self.view.filtermodel.props.filter.failure)
self.view.filterbuttons.failure = False
self.assertFalse(self.view.filtermodel.props.filter.failure)
def test_make_factory(self):
"""Test the do_make_factory() implementation."""
show_messages = unittest.mock.Mock()
self.view.connect("show-messages", show_messages)
factory = self.view.do_make_factory("xunit-1")
self.assertIsInstance(factory, xfstestsdb.gtk.row.ResultFactory)
self.assertEqual(factory.xunit, "xunit-1")
factory.emit("show-messages", "testcase", "xunit", "stdout", "stderr")
show_messages.assert_called_with(self.view, "testcase", "xunit",
"stdout", "stderr")
class TestSummaryView(unittest.TestCase):
"""Tests the SummaryView."""
def setUp(self):
"""Set up common variables."""
self.view = xfstestsdb.gtk.view.SummaryView()
def test_init(self):
"""Test that we created the SummaryView correctly."""
self.assertIsInstance(self.view, xfstestsdb.gtk.view.XunitView)
self.assertIsNone(self.view.filtermodel.props.filter)
self.assertIsNone(self.view.model)
self.assertEqual(self.view.props.vscrollbar_policy,
Gtk.PolicyType.NEVER)
self.assertEqual(self.view.firstcol.props.title, "summary")
self.assertTrue(self.view.props.child.has_css_class("data-table"))
def test_make_factory(self):
"""Test the do_make_factory() implementation."""
factory = self.view.do_make_factory("xunit-1")
self.assertIsInstance(factory, xfstestsdb.gtk.row.SummaryFactory)
self.assertEqual(factory.xunit, "xunit-1")
class TestXfstestsView(unittest.TestCase):
"""Test the XfstestsView."""
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.model = xfstestsdb.gtk.model.TestCaseList(self.xfstestsdb.sql, 1)
self.summary = xfstestsdb.gtk.model.SummaryList(self.xfstestsdb.sql, 1)
self.view = xfstestsdb.gtk.view.XfstestsView()
def test_init(self):
"""Check that the XfstestsView was set up correctly."""
self.assertIsInstance(self.view, Gtk.Box)
self.assertEqual(self.view.props.orientation, Gtk.Orientation.VERTICAL)
def test_environment_view(self):
"""Check that the XfstestsView sets up an EnvironmentView correctly."""
self.assertIsInstance(self.view._environview,
xfstestsdb.gtk.view.EnvironmentView)
self.assertEqual(self.view.get_first_child(), self.view._environview)
def test_property_view(self):
"""Check that the XfstestsView sets up a PropertyView correctly."""
sep = self.view._environview.get_next_sibling()
self.assertIsInstance(sep, Gtk.Separator)
self.assertIsInstance(self.view._propertyview,
xfstestsdb.gtk.view.PropertyView)
self.assertEqual(sep.get_next_sibling(), self.view._propertyview)
def test_testcase_view(self):
"""Check that the XfstestsView sets up a TestCaseView correctly."""
sep = self.view._propertyview.get_next_sibling()
self.assertIsInstance(sep, Gtk.Separator)
self.assertIsInstance(self.view._testcaseview,
xfstestsdb.gtk.view.TestCaseView)
self.assertEqual(sep.get_next_sibling(), self.view._testcaseview)
def test_summary_view(self):
"""Check that the XfstestsView sets up a SummaryView correctly."""
sep = self.view._testcaseview.get_next_sibling()
self.assertIsInstance(sep, Gtk.Separator)
self.assertIsInstance(self.view._summaryview,
xfstestsdb.gtk.view.SummaryView)
self.assertEqual(sep.get_next_sibling(), self.view._summaryview)
def test_environment(self):
"""Test the XfstestsView 'environment' property."""
self.assertIsNone(self.view.environment)
self.view.environment = self.props.environment
self.assertEqual(self.view._environview.model, self.props.environment)
def test_properties(self):
"""Test the XfstestsView 'properties' property."""
self.assertIsNone(self.view.properties)
self.view.properties = self.props
self.assertEqual(self.view._propertyview.model, self.props)
def test_model(self):
"""Test the XfstestsView 'model' property."""
self.assertIsNone(self.view.model)
self.view.model = self.model
self.assertEqual(self.view._testcaseview.model, self.model)
def test_summary(self):
"""Test the XfstestsView 'summary' property."""
self.assertIsNone(self.view.summary)
self.view.summary = self.summary
self.assertEqual(self.view._summaryview.model, self.summary)
def test_filterbuttons(self):
"""Test the XfstestsView 'filterbuttons' property."""
self.assertEqual(self.view.filterbuttons,
self.view._testcaseview.filterbuttons)