Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error messages for Modular Properties when config dict in not unpacked #1515

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ def build(self):
# Add Phase objects
if self.config.phases is None:
raise ConfigurationError(
"{} was not provided with a phases argument.".format(self.name)
f"{self.name} was not provided with a phases argument. "
"Did you forget to unpack the configurations dictionary?"
)

# Add a flag indicating whether this is an electrolyte system or not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ def build(self):
# and cannot be set until the config block is created by super.build
super(ReactionParameterBlock, self).build()

# Check to make sure a property block was assigned
if self.config.property_package is None:
raise ConfigurationError(
f"{self.name} was not assigned a property package. "
"Did you forget to unpack the configuration dictionary?"
)

# Set base units of measurement
self.get_metadata().add_default_units(self.config.base_units)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def test_no_components(self):

with pytest.raises(
ConfigurationError,
match="params was not provided with a components " "argument.",
match="params was not provided with a components argument.",
):
m.params = DummyParameterBlock(
phases={
Expand All @@ -215,12 +215,33 @@ def test_no_phases(self):

with pytest.raises(
ConfigurationError,
match="params was not provided with a phases " "argument.",
match="params was not provided with a phases argument. "
"Did you forget to unpack the configurations dictionary?",
):
m.params = DummyParameterBlock(
components={"a": {}, "b": {}, "c": {}}, base_units=base_units
)

@pytest.mark.unit
def test_packed_dict(self):
m = ConcreteModel()

dummy_dict = {
"phases": {
"p1": {"equation_of_state": "foo"},
"p2": {"equation_of_state": "bar"},
},
}

with pytest.raises(
ConfigurationError,
match=re.escape(
"params[phases] was not provided with a phases argument. "
"Did you forget to unpack the configurations dictionary?"
),
):
m.params = DummyParameterBlock(dummy_dict)

@pytest.mark.unit
def test_invalid_component_in_phase_component_list(self):
m = ConcreteModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ def test_rate_build_no_stoichiometry(self, m):
rate_reactions={"r1": {"heat_of_reaction": "foo", "rate_form": "foo"}},
)

@pytest.mark.unit
def test_packed_config_dict(self, m):
with pytest.raises(
ConfigurationError,
match=re.escape(
"rxn_params[property_package] was not assigned a property package. "
"Did you forget to unpack the configuration dictionary?"
),
):
m.rxn_params = GenericReactionParameterBlock({"property_package": m.params})

@pytest.mark.unit
def test_rate_build_invalid_phase_stoichiometry(self, m):
with pytest.raises(
Expand Down
Loading