xfstestsdb/tests/gtk/test_view.py

374 lines
16 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 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."""
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.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.TestCaseList(self.xfstestsdb.sql, 1)
self.view = xfstestsdb.gtk.view.TestCaseView()
def test_init(self):
"""Test that we create the TestCaseView correctly."""
self.assertIsInstance(self.view, Gtk.ScrolledWindow)
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.get_vexpand())
def test_filter(self):
"""Test that we set up the Gtk.FilterModel and Buttons correctly."""
self.assertIsInstance(self.view._filtermodel, Gtk.FilterListModel)
self.assertIsInstance(self.view._testfilter,
xfstestsdb.gtk.model.TestCaseFilter)
self.assertIsInstance(self.view.filterbuttons,
xfstestsdb.gtk.view.FilterButtons)
self.assertEqual(self.view.props.child.get_model().get_model(),
self.view._filtermodel)
self.assertEqual(self.view._filtermodel.props.filter,
self.view._testfilter)
self.assertFalse(self.view._testfilter.passed)
self.view.filterbuttons.passed = True
self.assertTrue(self.view._testfilter.passed)
self.assertFalse(self.view._testfilter.skipped)
self.view.filterbuttons.skipped = True
self.assertTrue(self.view._testfilter.skipped)
self.assertTrue(self.view._testfilter.failure)
self.view.filterbuttons.failure = False
self.assertFalse(self.view._testfilter.failure)
def test_testcase_column(self):
"""Test that we set up the 'testcase' column correctly."""
self.assertIsInstance(self.view._testcase, Gtk.ColumnViewColumn)
self.assertIsInstance(self.view._testcase.props.factory,
xfstestsdb.gtk.row.LabelFactory)
self.assertEqual(self.view._testcase.props.factory.property, "name")
self.assertEqual(self.view._testcase.props.title, "testcase")
self.assertFalse(self.view._testcase.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._testcase)
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.ResultFactory)
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._testcase)
class TestSummaryView(unittest.TestCase):
"""Tests the SummaryView."""
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.SummaryList(self.xfstestsdb.sql, 1)
self.view = xfstestsdb.gtk.view.SummaryView()
def test_init(self):
"""Test that we created the SummaryView 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())
def test_summary_column(self):
"""Test that we set up the 'summary' column correctly."""
self.assertIsInstance(self.view._summary, Gtk.ColumnViewColumn)
self.assertIsInstance(self.view._summary.props.factory,
xfstestsdb.gtk.row.LabelFactory)
self.assertEqual(self.view._summary.props.factory.property, "name")
self.assertEqual(self.view._summary.props.title, "summary")
self.assertFalse(self.view._summary.props.expand)
def test_model(self):
"""Test setting the model property."""
self.view.model = self.model
self.assertEqual(self.view.props.child.get_model().get_model(),
self.model)
columns = self.view.props.child.get_columns()
self.assertEqual(len(columns), 3)
self.assertEqual(columns[0], self.view._summary)
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.SummaryFactory)
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._summary)
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_property_view(self):
"""Check that the XfstestsView sets up a PropertyView correctly."""
self.assertIsInstance(self.view._propertyview,
xfstestsdb.gtk.view.PropertyView)
self.assertEqual(self.view.get_first_child(), 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_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)