Skip to content

Commit

Permalink
Avoid changing source dir directly in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
glatterf42 committed Sep 13, 2024
1 parent 9f0b149 commit 23b4520
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions message_ix/tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import re
import shutil
from pathlib import Path

import pytest
Expand All @@ -8,7 +7,9 @@
from message_ix import config


def test_copy_model(monkeypatch, message_ix_cli, tmp_path, tmp_env, request):
def test_copy_model(
monkeypatch, message_ix_cli, tmp_path, tmp_env, request, tmp_model_dir
):
# Use Pytest monkeypatch fixture; this ensures the original value is restored at the
# end of the test
monkeypatch.setattr(
Expand Down Expand Up @@ -37,18 +38,13 @@ def test_copy_model(monkeypatch, message_ix_cli, tmp_path, tmp_env, request):
# Check if specific directory will be skipped

# Create a GAMS runtime directory; these have names like "225a", etc.
model_path = Path(message_ix.__file__).parent.joinpath(
"model", request.node.name, "225c"
)
model_path.mkdir(parents=True)
model_path = tmp_model_dir.joinpath("225c")
model_path.mkdir()

message_ix_cli("copy-model", str(tmp_path))
message_ix_cli("copy-model", "--source-dir", tmp_model_dir, f"{tmp_path}-dest")

# Directory is ignored
assert not Path(tmp_path / f"{request.node.name}/225c").exists()

# Clean up
shutil.rmtree(model_path.parent)
assert not Path(f"{tmp_path}-dest/225c").exists()


@pytest.mark.parametrize(
Expand Down

0 comments on commit 23b4520

Please sign in to comment.