diff --git a/tests/test_gtk.py b/tests/test_gtk.py index d7ba0d6..82be6b0 100644 --- a/tests/test_gtk.py +++ b/tests/test_gtk.py @@ -44,11 +44,21 @@ class TestApplication(unittest.TestCase): mock_cmd.get_arguments.assert_called() mock_activate.assert_called() self.assertEqual(self.application.runid, 0) + self.assertFalse(self.application.show_sidebar) self.assertIsNone(self.application.environment) self.assertIsNone(self.application.properties) self.assertIsNone(self.application.model) 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_activate.reset_mock() mock_cmd.reset_mock() @@ -68,6 +78,7 @@ class TestApplication(unittest.TestCase): self.assertEqual(self.application.environment, self.application.properties.environment) self.assertEqual(self.application.model.runid, 42) + self.assertFalse(self.application.show_sidebar) @unittest.mock.patch("xfstestsdb.gtk.gsetup.add_style") @unittest.mock.patch("gi.repository.Adw.Application.add_window") @@ -93,6 +104,9 @@ class TestApplication(unittest.TestCase): self.application.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) self.application.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, mock_stderr: unittest.mock.Mock): """Check that running `xfstestsdb gtk` without a runid.""" - with self.assertRaises(SystemExit): - self.xfstestsdb.run(["gtk"]) - - self.assertRegex(mock_stderr.getvalue(), - "error: the following arguments are required: runid") + self.xfstestsdb.run(["gtk"]) + mock_app.assert_called_with(self.xfstestsdb.sql) + mock_app.return_value.run.assert_called_with(["show-sidebar"]) @unittest.mock.patch("sys.stdout", new_callable=io.StringIO) @unittest.mock.patch("xfstestsdb.gtk.Application") diff --git a/xfstestsdb/gtk/__init__.py b/xfstestsdb/gtk/__init__.py index afc09c8..4261a17 100644 --- a/xfstestsdb/gtk/__init__.py +++ b/xfstestsdb/gtk/__init__.py @@ -18,6 +18,7 @@ class Application(Adw.Application): """Our Adw.Application for displaying xfstests results.""" runid = GObject.Property(type=int) + show_sidebar = GObject.Property(type=bool, default=False) environment = GObject.Property(type=Gio.ListStore) properties = GObject.Property(type=model.PropertyList) summary = GObject.Property(type=model.SummaryList) @@ -46,6 +47,8 @@ class Application(Adw.Application): self.environment = self.properties.environment self.model = model.TestCaseList(self.sql, self.runid) self.summary = model.SummaryList(self.sql, self.runid) + case "show-sidebar": + self.show_sidebar = True self.activate() return 0 @@ -60,6 +63,7 @@ class Application(Adw.Application): self.win.headerbar.pack_end(self.view.filterbuttons) 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("properties", self.view, "properties") self.bind_property("model", self.view, "model") @@ -83,19 +87,22 @@ class Command(commands.Command): sql: sqlite.Connection) -> None: """Set up the gtk command.""" 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") def do_command(self, args: argparse.Namespace) -> None: """Run the Gtk UI.""" app_args = [] - if self.sql("SELECT 1 FROM xfstests_runs WHERE runid=?", - args.runid[0]).fetchone(): - app_args.append(f"runid={args.runid[0]}") + if args.runid is not None: + if self.sql("SELECT 1 FROM xfstests_runs WHERE runid=?", + 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: - print(f"error: run #{args.runid[0]} does not exist", - file=sys.stderr) - sys.exit(errno.ENOENT) + app_args.append("show-sidebar") Application(self.sql).run(app_args)