From c640df9e866366d630967245fbcb88b0c6382b06 Mon Sep 17 00:00:00 2001 From: Markus Binsteiner Date: Tue, 2 Apr 2024 10:45:06 +0200 Subject: [PATCH] test: add test for missing comment --- src/kiara/utils/cli/run.py | 12 +++++++++--- tests/resources/kiara.config | 2 ++ tests/test_cli/test_run_subcommand.py | 26 ++++++++++++++++++++++++-- 3 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 tests/resources/kiara.config diff --git a/src/kiara/utils/cli/run.py b/src/kiara/utils/cli/run.py index 3b9ae4e1f..b1481633e 100644 --- a/src/kiara/utils/cli/run.py +++ b/src/kiara/utils/cli/run.py @@ -342,9 +342,15 @@ def execute_job( if comment is not None: job_metadata["comment"] = comment - job_id = api.queue_job( - operation=operation, inputs=inputs, operation_config=None, **job_metadata - ) + try: + job_id = api.queue_job( + operation=operation, inputs=inputs, operation_config=None, **job_metadata + ) + except Exception as e: + log_exception(e) + terminal_print() + terminal_print(e) + sys.exit(1) try: outputs = api.get_job_result(job_id=job_id) diff --git a/tests/resources/kiara.config b/tests/resources/kiara.config new file mode 100644 index 000000000..47bd71d87 --- /dev/null +++ b/tests/resources/kiara.config @@ -0,0 +1,2 @@ +runtime_config: + runtime_profile: dharpa diff --git a/tests/test_cli/test_run_subcommand.py b/tests/test_cli/test_run_subcommand.py index 5be50dfb1..d9235fe57 100644 --- a/tests/test_cli/test_run_subcommand.py +++ b/tests/test_cli/test_run_subcommand.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +import os + from click.testing import CliRunner from kiara.interfaces.cli import cli @@ -8,6 +10,12 @@ # # Mozilla Public License, version 2.0 (see LICENSE or https://www.mozilla.org/en-US/MPL/2.0/) +ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) + +DATA_FOLDER = os.path.join(ROOT_DIR, "examples", "data") +TEST_RESOURCES_FOLDER = os.path.join(ROOT_DIR, "tests", "resources") +KIARA_CONFIG_FILE = os.path.join(TEST_RESOURCES_FOLDER, "kiara.config") + def test_run_without_module(): @@ -39,7 +47,10 @@ def test_run_with_missing_arg(): def test_run_with_valid_inputs(): runner = CliRunner() - result = runner.invoke(cli, "run logic.and a=true b=true") + result = runner.invoke( + cli, + f"-cnf {KIARA_CONFIG_FILE} run logic.and a=true b=true --comment 'A comment.'", + ) assert result.exit_code == 0 assert "True" in result.stdout @@ -48,9 +59,20 @@ def test_run_with_save(): runner = CliRunner(env={"KIARA_CONTEXT": "_unit_tests_run"}) runner.invoke(cli, "context delete -f") - result = runner.invoke(cli, "run logic.and a=true b=true --save test_save") + result = runner.invoke( + cli, + f"-cnf {KIARA_CONFIG_FILE} run logic.and a=true b=true --save test_save --comment 'A comment.'", + ) assert result.exit_code == 0 assert "True" in result.stdout result_data = runner.invoke(cli, "data list") assert "test_save.y" in result_data.stdout + + +def test_run_with_missing_comment(): + + runner = CliRunner() + result = runner.invoke(cli, f"-cnf {KIARA_CONFIG_FILE} run logic.and a=true b=true") + assert result.exit_code == 1 + assert "No job metadata provided." in result.stdout