Skip to content

Commit

Permalink
test: add test for missing comment
Browse files Browse the repository at this point in the history
  • Loading branch information
makkus committed Apr 2, 2024
1 parent 5dde2af commit c640df9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/kiara/utils/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions tests/resources/kiara.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
runtime_config:
runtime_profile: dharpa
26 changes: 24 additions & 2 deletions tests/test_cli/test_run_subcommand.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
import os

from click.testing import CliRunner

from kiara.interfaces.cli import cli
Expand All @@ -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():

Expand Down Expand Up @@ -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

Expand All @@ -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

0 comments on commit c640df9

Please sign in to comment.