Skip to content

Commit

Permalink
Merge branch 'main' into cons_mag_diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlee94 committed Oct 29, 2024
2 parents 93ef9d8 + 53f756b commit 3284d3e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
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

0 comments on commit 3284d3e

Please sign in to comment.