Skip to content

Commit

Permalink
parser: more tests for Symbols not being callable
Browse files Browse the repository at this point in the history
Add tests to improve coverage for the parser changes [1] for Symbols
not being callable.  Minor docstring change.

[1] diofant#201

// edited by skirpichev

Closes diofant#675
  • Loading branch information
cbm755 authored and skirpichev committed Aug 15, 2018
1 parent f4e2a1a commit e62e503
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion diofant/parsing/sympy_parser.py
Expand Up @@ -466,7 +466,7 @@ def implicit_multiplication_application(result, local_dict, global_dict):


def auto_symbol(tokens, local_dict, global_dict):
"""Inserts calls to ``Symbol`` for undefined variables."""
"""Inserts calls to ``Symbol``/``Function`` for undefined variables."""
result = []
prevTok = (None, None)

Expand Down
29 changes: 26 additions & 3 deletions diofant/parsing/tests/test_sympy_parser.py
Expand Up @@ -4,9 +4,10 @@
Symbol)
from diofant.functions import exp, sin
from diofant.logic import And
from diofant.parsing.sympy_parser import (TokenError, implicit_multiplication,
parse_expr, rationalize,
split_symbols,
from diofant.parsing.sympy_parser import (TokenError, convert_xor,
function_exponentiation,
implicit_multiplication, parse_expr,
rationalize, split_symbols,
standard_transformations)
from diofant.series import Limit

Expand Down Expand Up @@ -57,6 +58,15 @@ def test_local_dict():
assert parse_expr(text, local_dict=local_dict) == result


def test_local_dict_symbol_to_fcn():
x = Symbol('x')
d = {'foo': Function('bar')}
assert parse_expr('foo(x)', local_dict=d) == d['foo'](x)
# XXX: bit odd, but would be error if parser left the Symbol
d = {'foo': Symbol('baz')}
assert parse_expr('foo(x)', local_dict=d) == Function('baz')(x)


def test_global_dict():
global_dict = {
'Symbol': Symbol
Expand Down Expand Up @@ -102,6 +112,19 @@ def test_split_symbols_function():
local_dict={'f': f}) == a*f(x + 1)


def test_functional_exponent():
t = standard_transformations + (convert_xor, function_exponentiation)
x = Symbol('x')
y = Symbol('y')
a = Symbol('a')
yfcn = Function('y')
assert parse_expr("sin^2(x)", transformations=t) == (sin(x))**2
assert parse_expr("sin^y(x)", transformations=t) == (sin(x))**y
assert parse_expr("exp^y(x)", transformations=t) == (exp(x))**y
assert parse_expr("E^y(x)", transformations=t) == exp(yfcn(x))
assert parse_expr("a^y(x)", transformations=t) == a**(yfcn(x))


def test_match_parentheses_implicit_multiplication():
transformations = standard_transformations + \
(implicit_multiplication,)
Expand Down

0 comments on commit e62e503

Please sign in to comment.