Skip to content

Commit

Permalink
test: Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisjared committed Jan 7, 2025
1 parent 036a961 commit 9f7a917
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
9 changes: 9 additions & 0 deletions packages/ref-core/tests/unit/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ def test_run_metric(self, metric_definition, mock_metric):
assert result.successful
assert result.bundle_filename == metric_definition.output_fragment / "output.json"

def test_raises_exception(self, metric_definition, mock_metric):
executor = LocalExecutor()

mock_metric.run = lambda definition: 1 / 0

result = executor.run_metric(mock_metric, metric_definition)
assert result.successful is False
assert result.bundle_filename is None


@pytest.mark.parametrize("executor_name", ["local", None])
def test_run_metric_local(monkeypatch, executor_name, mock_metric, provider, metric_definition):
Expand Down
18 changes: 14 additions & 4 deletions packages/ref-core/tests/unit/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@


class TestMetricResult:
def test_build(self, tmp_path):
config = MetricExecutionDefinition(
def test_build_from_output_bundle(self, tmp_path):
definition = MetricExecutionDefinition(
output_fragment=tmp_path, key="mocked-metric-slug", metric_dataset=None
)
# Setting the output directory generally happens as a side effect of the executor
config = evolve(config, output_directory=tmp_path)
definition = evolve(definition, output_directory=tmp_path)

result = MetricResult.build_from_output_bundle(config, {"data": "value"})
result = MetricResult.build_from_output_bundle(definition, {"data": "value"})

assert result.successful

Expand All @@ -29,6 +29,16 @@ def test_build(self, tmp_path):

assert output_filename.is_relative_to(tmp_path)

def test_build_from_failure(self):
definition = MetricExecutionDefinition(
output_fragment="output", key="mocked-metric-slug", metric_dataset=None
)
result = MetricResult.build_from_failure(definition)

assert not result.successful
assert result.bundle_filename is None
assert result.definition == definition


@pytest.fixture
def apply_data_catalog():
Expand Down

0 comments on commit 9f7a917

Please sign in to comment.