Skip to content

Commit

Permalink
Create custom parameter equality method for test case, only generate …
Browse files Browse the repository at this point in the history
…description for stratified params with description
  • Loading branch information
nanglo123 committed Aug 19, 2024
1 parent aca8184 commit a13f95f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion mira/metamodel/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ def stratify(
stratum = stratified_param_tuple[0]
stratified_param = stratified_param_tuple[1]
d.name = stratified_param
d.description = f"{d.description} stratified by {key}"
if d.description:
d.description = f"{d.description} stratified by {key}"
d.with_context(inplace=True,**{key:stratum})
parameters[stratified_param] = d

Expand Down
20 changes: 19 additions & 1 deletion tests/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,25 @@ def test_stratify_full(self):
},
{k: i.expression for k, i in actual.initials.items()}
)
self.assertEqual(tm_stratified.parameters, actual.parameters)
def compare_parameters_no_context(tm0_params, tm1_params):
if tm0_params.keys() != tm1_params.keys():
return False

for param_id in tm0_params:
param_obj_0 = tm0_params[param_id]
param_obj_1 = tm1_params[param_id]

for param_attr in dict(param_obj_0):
if param_attr == "context" or param_attr == "description":
continue
if getattr(param_obj_0, param_attr) != getattr(param_obj_1, param_attr):
return False
return True

compare_parameters_no_context(tm_stratified.parameters,
actual.parameters)
self.assertTrue(compare_parameters_no_context(
tm_stratified.parameters, actual.parameters))
self.assertTrue(actual.initials['infected_population_vaccinated'].expression.equals(
tm_stratified.initials['infected_population_vaccinated'].expression))
self.assertEqual(
Expand Down

0 comments on commit a13f95f

Please sign in to comment.