diff --git a/checkbox-ng/checkbox_ng/launcher/check_config.py b/checkbox-ng/checkbox_ng/launcher/check_config.py index b0be4d9e18..25149e90af 100644 --- a/checkbox-ng/checkbox_ng/launcher/check_config.py +++ b/checkbox-ng/checkbox_ng/launcher/check_config.py @@ -24,9 +24,9 @@ class CheckConfig: """Implementation of the `check-config` sub-command.""" @staticmethod - def invoked(_): + def invoked(context): """Function that's run with `check-config` invocation.""" - config = load_configs() + config = load_configs(context.args.launcher) print("Configuration files:") for source in config.sources: print(" - {}".format(source)) @@ -50,4 +50,6 @@ def invoked(_): return 1 def register_arguments(self, parser): - """Register extra args for this subcmd. No extra args ATM.""" + parser.add_argument( + "launcher", nargs="?", help="launcher definition file to use" + ) diff --git a/checkbox-ng/checkbox_ng/launcher/test_check_config.py b/checkbox-ng/checkbox_ng/launcher/test_check_config.py index 009b09064b..c8f05df2db 100644 --- a/checkbox-ng/checkbox_ng/launcher/test_check_config.py +++ b/checkbox-ng/checkbox_ng/launcher/test_check_config.py @@ -17,6 +17,7 @@ # along with Checkbox. If not, see . from unittest import TestCase, mock +from unittest.mock import MagicMock from checkbox_ng.launcher.check_config import CheckConfig from plainbox.impl.config import Configuration @@ -26,10 +27,12 @@ class CheckConfigTests(TestCase): @mock.patch("builtins.print") @mock.patch("checkbox_ng.launcher.check_config.load_configs") def test_invoked_ok(self, mock_load_configs, mock_print): + args_mock = MagicMock() + args_mock.args.launcher = None # this is the default configuration mock_load_configs.return_value = Configuration() - ret_val = CheckConfig.invoked(...) + ret_val = CheckConfig.invoked(args_mock) mock_print.assert_any_call("Configuration files:") mock_print.assert_any_call("No problems with config(s) found!") @@ -38,14 +41,23 @@ def test_invoked_ok(self, mock_load_configs, mock_print): @mock.patch("builtins.print") @mock.patch("checkbox_ng.launcher.check_config.load_configs") def test_invoked_has_problems(self, mock_load_configs, mock_print): + args_mock = MagicMock() + args_mock.args.launcher = None # this is the default configuration conf = Configuration() conf.notice_problem("Test problem") mock_load_configs.return_value = conf - ret_val = CheckConfig.invoked(...) + ret_val = CheckConfig.invoked(args_mock) mock_print.assert_any_call("Configuration files:") mock_print.assert_any_call("Problems:") mock_print.assert_any_call("- ", "Test problem") self.assertEqual(ret_val, 1) + + def test_register_arguments(self): + self_mock = MagicMock() + parser_mock = MagicMock() + CheckConfig.register_arguments(self_mock, parser_mock) + + self.assertTrue(parser_mock.add_argument.called) diff --git a/docs/tutorial/using-checkbox/launcher.rst b/docs/tutorial/using-checkbox/launcher.rst index fab0e1feb6..8910e6dd56 100644 --- a/docs/tutorial/using-checkbox/launcher.rst +++ b/docs/tutorial/using-checkbox/launcher.rst @@ -244,8 +244,8 @@ and where it comes from. Run the following command: .. code-block:: none - $ checkbox.checkbox-cli check-config - Configuration files: + $ checkbox.checkbox-cli check-config + Configuration files: - /var/snap/checkbox/2799/checkbox.conf - /home/user/.config/checkbox.conf [config] @@ -286,6 +286,43 @@ environment variable is set to ``120`` because it is specified in a Checkbox configuration that comes with the snap version I'm using (``/var/snap/checkbox/2799/checkbox.conf``). +If you want to debug a Checkbox run that involves a ``launcher``, fear not. +The ``check-config`` command works with launchers as well. Try the previous +command with the ``launcher`` we created before: + +.. code-block:: none + :emphasize-lines: 8,14,17-18,21,28 + + $ checkbox.checkbox-cli check-config mylauncher + Configuration files: + - /var/snap/checkbox/2799/checkbox.conf + - /home/user/.config/checkbox.conf + [config] + config_filename=checkbox.conf (Default) + [launcher] + app_id=com.canonical.certification:tutorial From config file: /home/user/mylauncher + app_version= (Default) + launcher_version=1 From config file: /home/user/.config/checkbox.conf + local_submission=True (Default) + session_desc= (Default) + session_title=session title (Default) + stock_reports=text, submission_files From config file: /home/user/mylauncher + [test plan] + filter=* (Default) + forced=True From config file: /home/user/mylauncher + unit=com.canonical.certification::tutorial-base From config file: /home/user/mylauncher + [test selection] + exclude= (Default) + forced=True From config file: /home/user/mylauncher + (...) + [environment] + STRESS_S3_WAIT_DELAY=120 From config file: /var/snap/checkbox/2799/checkbox.conf + (...) + TUTO=tutorial From config file: /home/user/.config/checkbox.conf + (...) + TUTORIAL=Value from my launcher! From config file: /home/user/mylauncher + No problems with config(s) found! + Create an executable launcher =============================