Skip to content

Commit

Permalink
Create a copy of the unit dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
nanglo123 committed Oct 2, 2024
1 parent 7a9b2e4 commit a02c152
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
11 changes: 6 additions & 5 deletions mira/metamodel/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ class Unit(BaseModel):
def from_json(cls, data: Dict[str, Any]) -> "Unit":
# Use get_sympy from amr.petrinet, but avoid circular import
from mira.sources.amr.petrinet import get_sympy
data["expression"] = get_sympy(data, local_dict=UNIT_SYMBOLS)
assert data.get('expression') is None or not isinstance(
data['expression'], str
)
return cls(**data)
new_data = data.copy()
new_data["expression"] = get_sympy(data, local_dict=UNIT_SYMBOLS)
assert (new_data.get('expression') is None or
not isinstance(new_data.get('expression'), str))

return cls(**new_data)

@classmethod
def model_validate(cls, obj):
Expand Down
7 changes: 5 additions & 2 deletions tests/test_modeling/test_amr_ops.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import unittest
import requests
from copy import deepcopy as _d

from mira.modeling.amr.ops import *
from mira.metamodel.io import mathml_to_expression
from mira.metamodel import safe_parse_expr

try:
import sbmlmath
Expand Down Expand Up @@ -270,8 +272,9 @@ def test_replace_parameter_id(self):

self.assertEqual(old_param_dict[old_id]['value'], new_param_dict[new_id]['value'])
self.assertEqual(old_param_dict[old_id]['distribution'], new_param_dict[new_id]['distribution'])
self.assertEqual(str(old_param_dict[old_id]['units']['expression']),
new_param_dict[new_id]['units']['expression'])
self.assertEqual(safe_parse_expr(old_param_dict[old_id]['units']['expression']),
safe_parse_expr(new_param_dict[new_id]['units'][
'expression']))
self.assertEqual(mathml_to_expression(old_param_dict[old_id]['units']['expression_mathml']),
mathml_to_expression(new_param_dict[new_id]['units']['expression_mathml']))

Expand Down

0 comments on commit a02c152

Please sign in to comment.