Skip to content

Commit

Permalink
Improve wf test fixture
Browse files Browse the repository at this point in the history
- Remove unused "_base_url" key.
- Scope to individual test function.
- Adjust usage in test_workflow(): the "base" key now has a platform name, so
  can be truncated.
  • Loading branch information
khaeru committed Nov 2, 2023
1 parent 64a86d6 commit d63740c
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions message_ix_models/tests/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import ixmp
import pytest
from genno import KeyExistsError
from message_ix import make_df

from message_ix_models import Workflow, testing
Expand Down Expand Up @@ -54,7 +53,7 @@ def test_repr(self) -> None:
assert "<Step load>" == repr(WorkflowStep(None))


@pytest.fixture
@pytest.fixture(scope="function")
def wf(request, test_context) -> Workflow:
return _wf(test_context, request=request)

Check warning on line 58 in message_ix_models/tests/test_workflow.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/tests/test_workflow.py#L58

Added line #L58 was not covered by tests

Expand All @@ -70,7 +69,6 @@ def _wf(
base_scenario = testing.bare_res(request, context, solved=False)
base_platform = base_scenario.platform.name
base_url = f"ixmp://{base_platform}/{base_scenario.url}"

Check warning on line 71 in message_ix_models/tests/test_workflow.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/tests/test_workflow.py#L68-L71

Added lines #L68 - L71 were not covered by tests
del base_scenario

"""A function that generates a Workflow."""

Check warning on line 73 in message_ix_models/tests/test_workflow.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/tests/test_workflow.py#L73

Added line #L73 was not covered by tests
# Create the workflow
Expand All @@ -84,7 +82,7 @@ def _wf(
wf.add_step("B", "A", changes_b, value=100.0)

# Store extra info
wf.graph.update({"_base_url": base_url, "_base_platform": base_platform})
wf.graph.update({"_base_platform": base_platform})

Check warning on line 85 in message_ix_models/tests/test_workflow.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/tests/test_workflow.py#L85

Added line #L85 was not covered by tests

return wf

Check warning on line 87 in message_ix_models/tests/test_workflow.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/tests/test_workflow.py#L87

Added line #L87 was not covered by tests

Expand Down Expand Up @@ -126,8 +124,7 @@ def test_make_click_command(mix_models_cli) -> None:
@MARK
def test_workflow(caplog, request, test_context, wf) -> None:
# Retrieve some information from the fixture
base_url = wf.graph.pop("_base_url")
base_platform = wf.graph.pop("_base_platform")
mp = wf.graph.pop("_base_platform")

Check warning on line 127 in message_ix_models/tests/test_workflow.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/tests/test_workflow.py#L127

Added line #L127 was not covered by tests

caplog.clear()

Check warning on line 129 in message_ix_models/tests/test_workflow.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/tests/test_workflow.py#L129

Added line #L129 was not covered by tests

Expand All @@ -149,7 +146,6 @@ def test_workflow(caplog, request, test_context, wf) -> None:

# Log messages reflect workflow steps executed
start_index = 1 if caplog.messages[0].startswith("Cull") else 0
mp = base_platform
m = "MESSAGEix-GLOBIOM R14 YB"
messages = [
f"Loaded ixmp://{mp}/{m}/test_workflow#1",
Expand Down Expand Up @@ -183,14 +179,6 @@ def test_workflow(caplog, request, test_context, wf) -> None:
)

# Now truncate the workflow at "Model/A"
with pytest.raises(RuntimeError, match="Unable to locate platform info for"):
wf.truncate("A")

# Add a full URL including platform info
with pytest.raises(KeyExistsError):
wf.add_step("base", None, target=f"ixmp://{base_platform}/{base_url}")

wf.add_step("base", None, target=f"ixmp://{base_platform}/{base_url}", replace=True)
wf.truncate("A")

# Description reflects that changes_a() will no longer be called
Expand Down

0 comments on commit d63740c

Please sign in to comment.