Skip to content

Commit

Permalink
Made requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya-balachander committed Nov 9, 2023
1 parent 312ec82 commit 94c9dc8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
16 changes: 7 additions & 9 deletions cumulusci/utils/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
from cumulusci.core.exceptions import TaskOptionsError
from cumulusci.utils.yaml.model_parser import CCIDictModel

READONLYDICT_ERROR_MSG = (
"The 'options' dictionary is read-only. Please use 'parsed_options' instead."
)


def _describe_field(field):
"Convert a Pydantic field into a CCI task_option dict"
Expand All @@ -26,19 +30,13 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def __setitem__(self, key, value):
raise TaskOptionsError(
"The 'options' dictionary is read-only. Please use 'parsed_options' instead."
)
raise TaskOptionsError(READONLYDICT_ERROR_MSG)

def __delitem__(self, key):
raise TaskOptionsError(
"The 'options' dictionary is read-only. Please use 'parsed_options' instead."
)
raise TaskOptionsError(READONLYDICT_ERROR_MSG)

def pop(self, key, default=None):
raise TaskOptionsError(
"The 'options' dictionary is read-only. Please use 'parsed_options' instead."
)
raise TaskOptionsError(READONLYDICT_ERROR_MSG)


class CCIOptions(CCIDictModel):
Expand Down
15 changes: 6 additions & 9 deletions cumulusci/utils/tests/test_option_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from cumulusci.core.exceptions import TaskOptionsError
from cumulusci.core.tasks import BaseTask
from cumulusci.utils.options import (
READONLYDICT_ERROR_MSG,
CCIOptions,
Field,
ListOfStringsOption,
Expand Down Expand Up @@ -171,21 +172,17 @@ def test_options_read_only(self):
assert isinstance(task2.options, dict)

def test_init_options__options_read_only_error(self):
expected_error_message = "The 'options' dictionary is read-only. Please use 'parsed_options' instead."
expected_error_msg = READONLYDICT_ERROR_MSG
task = TaskToTestTypes(self.project_config, self.task_config, self.org_config)
# Add new option
with pytest.raises(TaskOptionsError) as exc_info:
with pytest.raises(TaskOptionsError, match=expected_error_msg):
task.options["new_option"] = "something"
assert expected_error_message == str(exc_info.value)
# Modify existing option
with pytest.raises(TaskOptionsError) as exc_info:
with pytest.raises(TaskOptionsError, match=expected_error_msg):
task.options["test_option"] = 456
assert expected_error_message == str(exc_info.value)
# Delete existing option
with pytest.raises(TaskOptionsError) as exc_info:
with pytest.raises(TaskOptionsError, match=expected_error_msg):
del task.options["test_option"]
assert expected_error_message == str(exc_info.value)
# Pop existing option
with pytest.raises(TaskOptionsError) as exc_info:
with pytest.raises(TaskOptionsError, match=expected_error_msg):
task.options.pop("test_option")
assert expected_error_message == str(exc_info.value)

0 comments on commit 94c9dc8

Please sign in to comment.