Skip to content

Commit

Permalink
Merge 80b7fba into fa449cb
Browse files Browse the repository at this point in the history
  • Loading branch information
schymans committed Sep 20, 2017
2 parents fa449cb + 80b7fba commit dc9d833
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions essm/variables/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ def extract_variables(expr):


def replace_variables(expr, variables=None):
"""Replace all base variables in expression."""
"""Replace all base variables in expression by ``variables``."""
if not isinstance(expr, Expr): # stop recursion
return expr

variables = {
key._name: replace_variables(value)
getattr(key, '_name', key): replace_variables(value)
for key, value in (variables or {}).items()}

return expr.replace(
Expand Down
3 changes: 2 additions & 1 deletion tests/test_equations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""Test equations."""

import pytest
from sympy import S
from sympy import S, Symbol

from essm import Eq
from essm._generator import EquationWriter
Expand Down Expand Up @@ -68,6 +68,7 @@ def test_variable_replacement():
"""Test replace variables by values and symbols in expression."""
expr = demo_fall.rhs
vdict = Variable.__defaults__.copy()
vdict[Symbol('x')] = 1
assert replace_variables(expr, vdict) == \
4.9 * demo_fall.definition.t._name ** 2

Expand Down

0 comments on commit dc9d833

Please sign in to comment.