Skip to content

Commit

Permalink
improving data type handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jonrkarr committed Feb 12, 2021
1 parent f47cfcf commit c1e1173
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion biosimulators_utils/sedml/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,10 @@ def apply_changes_to_xml_model(model, model_etree, sed_doc, working_dir,

# calculate new value
new_value = calc_compute_model_change_new_value(change, variable_values=iter_variable_values, range_values=range_values)
if new_value == int(new_value):
new_value = str(int(new_value))
else:
new_value = str(new_value)

# get object to change
obj_xpath, sep, attr = change.target.rpartition('/@')
Expand All @@ -424,7 +428,7 @@ def apply_changes_to_xml_model(model, model_etree, sed_doc, working_dir,

# change value
for obj in objs:
obj.set(attr, str(new_value))
obj.set(attr, new_value)

else:
raise NotImplementedError('Change{} of type {} is not supported'.format(
Expand Down
7 changes: 7 additions & 0 deletions tests/sedml/test_sedml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ def test_apply_compute_model_change_new_value(self):
parameters=[
data_model.Parameter(id='a', value=1.5),
data_model.Parameter(id='b', value=2.25),
data_model.Parameter(id='c', value=2.),
],
variables=[
data_model.Variable(id='x', model=data_model.Model(id='model_1'), target="/model/parameter[@id='x']/@value"),
Expand Down Expand Up @@ -800,6 +801,12 @@ def test_apply_compute_model_change_new_value(self):
obj = et.xpath("/model/parameter[@id='p1']")[0]
self.assertEqual(float(obj.get('value')), expected_value)

change.math = 'c'
utils.apply_changes_to_xml_model(data_model.Model(changes=[change]), et, None, None, variable_values=variable_values)
obj = et.xpath("/model/parameter[@id='p1']")[0]
self.assertEqual(float(obj.get('value')), 2)
change.math = 'a * x + b * y'

change.target = "/model/parameter[@type='parameter']/@value"
et = etree.parse(in_file)
with self.assertRaisesRegex(ValueError, 'must match a single object'):
Expand Down

0 comments on commit c1e1173

Please sign in to comment.