Skip to content

Commit

Permalink
Don't convert input to string.
Browse files Browse the repository at this point in the history
Also, revert tests in case they're actually OK.
  • Loading branch information
luciansmith committed Jun 22, 2023
1 parent 006b72a commit 4deb90b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 0 additions & 3 deletions biosimulators_utils/sedml/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,6 @@ def compile_math(math):
model.allowed_functions.extend(MATHEMATICAL_FUNCTIONS.keys())

math_node = evalidate.Expr(math, model=model)
# math_node = evalidate.evalidate(math,
# addnodes=VALID_MATH_EXPRESSION_NODES,
# funcs=MATHEMATICAL_FUNCTIONS.keys())
compiled_math = compile(math_node.node, '<math>', 'eval')
return compiled_math

Expand Down
5 changes: 4 additions & 1 deletion biosimulators_utils/sedml/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1770,7 +1770,10 @@ def validate_calculation(calculation):
workspace[calculation.range.id] = 1

try:
compiled_math = compile_math(str(calculation.math))
compiled_math = compile_math(calculation.math)
except TypeError as exception:
errors.append(['The mathematical expression must be a `string`, not a `{}`:'.format(calculation.math.__class__), [[str(exception)]]])
return (errors, warnings)
except (SyntaxError, CompilationException) as exception:
errors.append(['The syntax of the mathematical expression `{}` is invalid.'.format(calculation.math), [[str(exception)]]])
return (errors, warnings)
Expand Down
4 changes: 4 additions & 0 deletions tests/sedml/test_sedml_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,10 @@ def test_validate_calculation(self):
calculation_2.math = None
self.assertIn('must have math', flatten_nested_list_of_strings(validation.validate_calculation(calculation_2)[0]))

calculation_2 = copy.copy(calculation)
calculation_2.math = 10.
self.assertIn('must be a `string`', flatten_nested_list_of_strings(validation.validate_calculation(calculation_2)[0]))

calculation_2 = copy.copy(calculation)
calculation_2.math = 'a * '
self.assertIn('The syntax', flatten_nested_list_of_strings(validation.validate_calculation(calculation_2)[0]))
Expand Down

0 comments on commit 4deb90b

Please sign in to comment.