gtk: Make the runid argument optional
And set things up so we show the sidebar when the user doesn't specify a runid, but have it hidden when they do. Signed-off-by: Anna Schumaker <anna@nowheycreamery.com>
This commit is contained in:
parent
64abc86fee
commit
bf668fc936
|
@ -44,11 +44,21 @@ class TestApplication(unittest.TestCase):
|
||||||
mock_cmd.get_arguments.assert_called()
|
mock_cmd.get_arguments.assert_called()
|
||||||
mock_activate.assert_called()
|
mock_activate.assert_called()
|
||||||
self.assertEqual(self.application.runid, 0)
|
self.assertEqual(self.application.runid, 0)
|
||||||
|
self.assertFalse(self.application.show_sidebar)
|
||||||
self.assertIsNone(self.application.environment)
|
self.assertIsNone(self.application.environment)
|
||||||
self.assertIsNone(self.application.properties)
|
self.assertIsNone(self.application.properties)
|
||||||
self.assertIsNone(self.application.model)
|
self.assertIsNone(self.application.model)
|
||||||
self.assertIsNone(self.application.summary)
|
self.assertIsNone(self.application.summary)
|
||||||
|
|
||||||
|
mock_command_line.reset_mock()
|
||||||
|
mock_activate.reset_mock()
|
||||||
|
mock_cmd.reset_mock()
|
||||||
|
mock_cmd.get_arguments.return_value = ["show-sidebar"]
|
||||||
|
|
||||||
|
self.application.do_command_line(mock_cmd)
|
||||||
|
self.assertTrue(self.application.show_sidebar)
|
||||||
|
|
||||||
|
self.application.show_sidebar = False
|
||||||
mock_command_line.reset_mock()
|
mock_command_line.reset_mock()
|
||||||
mock_activate.reset_mock()
|
mock_activate.reset_mock()
|
||||||
mock_cmd.reset_mock()
|
mock_cmd.reset_mock()
|
||||||
|
@ -68,6 +78,7 @@ class TestApplication(unittest.TestCase):
|
||||||
self.assertEqual(self.application.environment,
|
self.assertEqual(self.application.environment,
|
||||||
self.application.properties.environment)
|
self.application.properties.environment)
|
||||||
self.assertEqual(self.application.model.runid, 42)
|
self.assertEqual(self.application.model.runid, 42)
|
||||||
|
self.assertFalse(self.application.show_sidebar)
|
||||||
|
|
||||||
@unittest.mock.patch("xfstestsdb.gtk.gsetup.add_style")
|
@unittest.mock.patch("xfstestsdb.gtk.gsetup.add_style")
|
||||||
@unittest.mock.patch("gi.repository.Adw.Application.add_window")
|
@unittest.mock.patch("gi.repository.Adw.Application.add_window")
|
||||||
|
@ -93,6 +104,9 @@ class TestApplication(unittest.TestCase):
|
||||||
self.application.runid = 42
|
self.application.runid = 42
|
||||||
self.assertEqual(self.application.win.runid, 42)
|
self.assertEqual(self.application.win.runid, 42)
|
||||||
|
|
||||||
|
self.application.show_sidebar = True
|
||||||
|
self.assertTrue(self.application.win.show_sidebar)
|
||||||
|
|
||||||
properties = xfstestsdb.gtk.model.PropertyList(self.xfstestsdb.sql, 42)
|
properties = xfstestsdb.gtk.model.PropertyList(self.xfstestsdb.sql, 42)
|
||||||
self.application.properties = properties
|
self.application.properties = properties
|
||||||
self.assertEqual(self.application.view.properties, properties)
|
self.assertEqual(self.application.view.properties, properties)
|
||||||
|
@ -150,11 +164,9 @@ class TestGtk(unittest.TestCase):
|
||||||
def test_gtk_empty(self, mock_app: unittest.mock.Mock,
|
def test_gtk_empty(self, mock_app: unittest.mock.Mock,
|
||||||
mock_stderr: unittest.mock.Mock):
|
mock_stderr: unittest.mock.Mock):
|
||||||
"""Check that running `xfstestsdb gtk` without a runid."""
|
"""Check that running `xfstestsdb gtk` without a runid."""
|
||||||
with self.assertRaises(SystemExit):
|
self.xfstestsdb.run(["gtk"])
|
||||||
self.xfstestsdb.run(["gtk"])
|
mock_app.assert_called_with(self.xfstestsdb.sql)
|
||||||
|
mock_app.return_value.run.assert_called_with(["show-sidebar"])
|
||||||
self.assertRegex(mock_stderr.getvalue(),
|
|
||||||
"error: the following arguments are required: runid")
|
|
||||||
|
|
||||||
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
|
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
|
||||||
@unittest.mock.patch("xfstestsdb.gtk.Application")
|
@unittest.mock.patch("xfstestsdb.gtk.Application")
|
||||||
|
|
|
@ -18,6 +18,7 @@ class Application(Adw.Application):
|
||||||
"""Our Adw.Application for displaying xfstests results."""
|
"""Our Adw.Application for displaying xfstests results."""
|
||||||
|
|
||||||
runid = GObject.Property(type=int)
|
runid = GObject.Property(type=int)
|
||||||
|
show_sidebar = GObject.Property(type=bool, default=False)
|
||||||
environment = GObject.Property(type=Gio.ListStore)
|
environment = GObject.Property(type=Gio.ListStore)
|
||||||
properties = GObject.Property(type=model.PropertyList)
|
properties = GObject.Property(type=model.PropertyList)
|
||||||
summary = GObject.Property(type=model.SummaryList)
|
summary = GObject.Property(type=model.SummaryList)
|
||||||
|
@ -46,6 +47,8 @@ class Application(Adw.Application):
|
||||||
self.environment = self.properties.environment
|
self.environment = self.properties.environment
|
||||||
self.model = model.TestCaseList(self.sql, self.runid)
|
self.model = model.TestCaseList(self.sql, self.runid)
|
||||||
self.summary = model.SummaryList(self.sql, self.runid)
|
self.summary = model.SummaryList(self.sql, self.runid)
|
||||||
|
case "show-sidebar":
|
||||||
|
self.show_sidebar = True
|
||||||
|
|
||||||
self.activate()
|
self.activate()
|
||||||
return 0
|
return 0
|
||||||
|
@ -60,6 +63,7 @@ class Application(Adw.Application):
|
||||||
self.win.headerbar.pack_end(self.view.filterbuttons)
|
self.win.headerbar.pack_end(self.view.filterbuttons)
|
||||||
|
|
||||||
self.bind_property("runid", self.win, "runid")
|
self.bind_property("runid", self.win, "runid")
|
||||||
|
self.bind_property("show-sidebar", self.win, "show-sidebar")
|
||||||
self.bind_property("environment", self.view, "environment")
|
self.bind_property("environment", self.view, "environment")
|
||||||
self.bind_property("properties", self.view, "properties")
|
self.bind_property("properties", self.view, "properties")
|
||||||
self.bind_property("model", self.view, "model")
|
self.bind_property("model", self.view, "model")
|
||||||
|
@ -83,19 +87,22 @@ class Command(commands.Command):
|
||||||
sql: sqlite.Connection) -> None:
|
sql: sqlite.Connection) -> None:
|
||||||
"""Set up the gtk command."""
|
"""Set up the gtk command."""
|
||||||
super().__init__(subparser, sql, "gtk", help="show a gtk-based ui")
|
super().__init__(subparser, sql, "gtk", help="show a gtk-based ui")
|
||||||
self.parser.add_argument("runid", metavar="runid", nargs=1, type=int,
|
self.parser.add_argument("runid", metavar="runid", nargs='?', type=int,
|
||||||
help="show a specific xfstests run")
|
help="show a specific xfstests run")
|
||||||
|
|
||||||
def do_command(self, args: argparse.Namespace) -> None:
|
def do_command(self, args: argparse.Namespace) -> None:
|
||||||
"""Run the Gtk UI."""
|
"""Run the Gtk UI."""
|
||||||
app_args = []
|
app_args = []
|
||||||
|
|
||||||
if self.sql("SELECT 1 FROM xfstests_runs WHERE runid=?",
|
if args.runid is not None:
|
||||||
args.runid[0]).fetchone():
|
if self.sql("SELECT 1 FROM xfstests_runs WHERE runid=?",
|
||||||
app_args.append(f"runid={args.runid[0]}")
|
args.runid).fetchone():
|
||||||
|
app_args.append(f"runid={args.runid}")
|
||||||
|
else:
|
||||||
|
print(f"error: run #{args.runid} does not exist",
|
||||||
|
file=sys.stderr)
|
||||||
|
sys.exit(errno.ENOENT)
|
||||||
else:
|
else:
|
||||||
print(f"error: run #{args.runid[0]} does not exist",
|
app_args.append("show-sidebar")
|
||||||
file=sys.stderr)
|
|
||||||
sys.exit(errno.ENOENT)
|
|
||||||
|
|
||||||
Application(self.sql).run(app_args)
|
Application(self.sql).run(app_args)
|
||||||
|
|
Loading…
Reference in New Issue