test_ast_parser.py 803 B

12345678910111213141516171819202122232425
  1. from sympy.core.singleton import S
  2. from sympy.core.symbol import symbols
  3. from sympy.parsing.ast_parser import parse_expr
  4. from sympy.testing.pytest import raises
  5. from sympy.core.sympify import SympifyError
  6. import warnings
  7. def test_parse_expr():
  8. a, b = symbols('a, b')
  9. # tests issue_16393
  10. assert parse_expr('a + b', {}) == a + b
  11. raises(SympifyError, lambda: parse_expr('a + ', {}))
  12. # tests Transform.visit_Constant
  13. assert parse_expr('1 + 2', {}) == S(3)
  14. assert parse_expr('1 + 2.0', {}) == S(3.0)
  15. # tests Transform.visit_Name
  16. assert parse_expr('Rational(1, 2)', {}) == S(1)/2
  17. assert parse_expr('a', {'a': a}) == a
  18. # tests issue_23092
  19. with warnings.catch_warnings():
  20. warnings.simplefilter('error')
  21. assert parse_expr('6 * 7', {}) == S(42)