Skip to content

Commit

Permalink
Attempting to address
Browse files Browse the repository at this point in the history
  • Loading branch information
John Joyce authored and John Joyce committed Jan 24, 2025
1 parent 97eb106 commit b8804f5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion datahub-actions/src/datahub_actions/cli/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def run(ctx: Any, config: List[str], debug: bool) -> None:
pipeline_config_dict = load_config_file(pipeline_config_file)
pipelines.append(pipeline_config_to_pipeline(pipeline_config_dict))
except UnboundVariable as e:
if len(config) == 1:
if len(valid_configs) == 1:
raise Exception(
"Failed to load action configuration. Unbound variable(s) provided in config YAML."
) from e
Expand Down
37 changes: 30 additions & 7 deletions datahub-actions/tests/unit/cli/test_actions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import os
import tempfile
from contextlib import contextmanager
from typing import Generator
from unittest.mock import Mock

Expand All @@ -10,7 +11,7 @@
from datahub_actions.cli.actions import actions, pipeline_config_to_pipeline
from datahub_actions.pipeline.pipeline import Pipeline
from datahub_actions.pipeline.pipeline_manager import PipelineManager
from contextlib import contextmanager


@contextmanager
def local_monkeypatch(monkeypatch, target, replacement):
Expand All @@ -21,6 +22,7 @@ def local_monkeypatch(monkeypatch, target, replacement):
finally:
monkeypatch.undo()


@pytest.fixture
def capture_logger(
caplog: pytest.LogCaptureFixture,
Expand Down Expand Up @@ -159,6 +161,22 @@ def test_all_configs_invalid_or_disabled(
actions, ["run", "-c", invalid_config_file, "-c", disabled_config_file]
)
assert result.exit_code == 1
assert (
"Failed to load action configuration. Unbound variable(s) provided in config YAML."
in str(result.exception)
)


def test_all_configs_multiple_disabled(
disabled_config_file: str,
capture_logger: pytest.LogCaptureFixture,
) -> None:
"""Test that program exits when all configs are invalid or disabled."""
runner = CliRunner()
result = runner.invoke(
actions, ["run", "-c", disabled_config_file, "-c", disabled_config_file]
)
assert result.exit_code == 1
assert any(
"No valid pipelines were started from 2 config(s). Check that at least one pipeline is enabled and all required environment variables are set."
in record.message
Expand Down Expand Up @@ -191,13 +209,14 @@ def mock_sleep(seconds: int) -> None:
runner = CliRunner()

# Use local_monkeypatch for tighter control

with local_monkeypatch(
monkeypatch, "datahub_actions.pipeline.pipeline.Pipeline.create", mock_create_pipeline
monkeypatch,
"datahub_actions.pipeline.pipeline.Pipeline.create",
mock_create_pipeline,
), local_monkeypatch(monkeypatch, "time.sleep", mock_sleep):
result = runner.invoke(
actions,
["run", "-c", temp_config_file, "-c", disabled_config_file]
actions, ["run", "-c", temp_config_file, "-c", disabled_config_file]
)

assert result.exit_code == 1
Expand Down Expand Up @@ -237,9 +256,13 @@ def mock_sleep(seconds: int) -> None:

# Use local_monkeypatch for tighter control
with local_monkeypatch(
monkeypatch, "datahub_actions.pipeline.pipeline.Pipeline.create", mock_create_pipeline
monkeypatch,
"datahub_actions.pipeline.pipeline.Pipeline.create",
mock_create_pipeline,
), local_monkeypatch(monkeypatch, "time.sleep", mock_sleep), local_monkeypatch(
monkeypatch, "datahub_actions.cli.actions.pipeline_manager", mock_pipeline_manager
monkeypatch,
"datahub_actions.cli.actions.pipeline_manager",
mock_pipeline_manager,
):
result = runner.invoke(
actions,
Expand Down

0 comments on commit b8804f5

Please sign in to comment.