Skip to content

Commit

Permalink
fake infra defaults to test conversion in up
Browse files Browse the repository at this point in the history
  • Loading branch information
araghukas committed Feb 1, 2024
1 parent 52af8a6 commit 67b870c
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions tests/covalent_tests/cloud_resource_manager/core_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ def executor_module_path():
return "test_executor_module_path"


@pytest.fixture
def executor_infra_defaults():
from pydantic import BaseModel

class FakeExecutorInfraDefaults(BaseModel):
string_param: str = "fake_address_123"
number_param: int = 123
sequence_param: tuple = (1, 2, 3)

return FakeExecutorInfraDefaults


@pytest.fixture
def crm(mocker, executor_name, executor_module_path):
mocker.patch(
Expand Down Expand Up @@ -377,7 +389,9 @@ def test_get_tf_statefile_path(mocker, crm, executor_name):
(False, {"test_key": "test_value"}),
],
)
def test_up(mocker, dry_run, executor_options, executor_name, executor_module_path):
def test_up(
mocker, dry_run, executor_options, executor_name, executor_module_path, executor_infra_defaults
):
"""
Unit test for CloudResourceManager.up() method
"""
Expand Down Expand Up @@ -420,10 +434,6 @@ def test_up(mocker, dry_run, executor_options, executor_name, executor_module_pa
"covalent.cloud_resource_manager.core.CloudResourceManager._update_config",
)

mock_convert_to_tfvar = mocker.patch(
"covalent.cloud_resource_manager.core.CloudResourceManager._convert_to_tfvar",
)

if executor_options:
with pytest.raises(SystemExit):
CloudResourceManager(
Expand All @@ -438,6 +448,9 @@ def test_up(mocker, dry_run, executor_options, executor_name, executor_module_pa
options=executor_options,
)

# Override infra defaults with dummy values.
crm.ExecutorInfraDefaults = executor_infra_defaults

with mock.patch(
"covalent.cloud_resource_manager.core.open",
mock.mock_open(),
Expand Down Expand Up @@ -471,8 +484,6 @@ def test_up(mocker, dry_run, executor_options, executor_name, executor_module_pa
f"{crm.executor_tf_path}/{executor_name}.conf",
)

mock_convert_to_tfvar.assert_any_call()


def test_up_executor_options(mocker, executor_name, executor_module_path):
"""
Expand Down

0 comments on commit 67b870c

Please sign in to comment.