Skip to content

Commit a5699cd

Browse files
committed
Have proper test skipping
Also clear cache in sympy in tests. Only memory leak left is because of the cyclic reference in PySymbol
1 parent 05cc34e commit a5699cd

File tree

7 files changed

+133
-74
lines changed

7 files changed

+133
-74
lines changed

symengine/lib/symengine_wrapper.pyx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,15 @@ def _sympify(a, raise_error=True):
376376
return _sympify(a._sympy_(), raise_error)
377377
elif hasattr(a, 'pyobject'):
378378
return _sympify(a.pyobject(), raise_error)
379-
return sympy2symengine(a, raise_error)
379+
380+
try:
381+
import sympy
382+
return sympy2symengine(a, raise_error)
383+
except ImportError:
384+
pass
385+
386+
if raise_error:
387+
raise SympifyError("sympify: Cannot convert '%r' to a symengine type." % a)
380388

381389
funcs = {}
382390

symengine/tests/test_eval.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from symengine import (Symbol, sin, cos, Integer, Add, I, RealDouble, ComplexDouble, sqrt)
33

44
from symengine.lib.symengine_wrapper import eval_double
5-
5+
from unittest.case import SkipTest
66

77
def test_eval_double1():
88
x = Symbol("x")
@@ -34,6 +34,8 @@ def test_n():
3434
y = 1.0 + 2.0*I
3535
assert x.n() == y
3636

37+
38+
def test_n_mpfr():
3739
try:
3840
from symengine import RealMPFR
3941
x = sqrt(Integer(2))
@@ -42,7 +44,10 @@ def test_n():
4244
except ImportError:
4345
x = sqrt(Integer(2))
4446
raises(ValueError, lambda: (x.n(75, real=True)))
47+
raise SkipTest("No MPFR support")
48+
4549

50+
def test_n_mpc():
4651
try:
4752
from symengine import ComplexMPC
4853
x = sqrt(Integer(2)) + 3*I
@@ -51,6 +56,7 @@ def test_n():
5156
except ImportError:
5257
x = sqrt(Integer(2))
5358
raises(ValueError, lambda: (x.n(75)))
59+
raise SkipTest("No MPC support")
5460

5561

5662
def test_rel():

symengine/tests/test_functions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
from symengine import Symbol, sin, cos, sqrt, Add, Mul, function_symbol, Integer, log, E, symbols
22
from symengine.lib.symengine_wrapper import Subs, Derivative
3+
import unittest
34

5+
try:
6+
import sympy
7+
from sympy.core.cache import clear_cache
8+
import atexit
9+
atexit.register(clear_cache)
10+
have_sympy = True
11+
except ImportError:
12+
have_sympy = False
413

514
def test_sin():
615
x = Symbol("x")
@@ -105,6 +114,7 @@ def test_Subs():
105114
assert s.point == (2*x,)
106115

107116

117+
@unittest.skipUnless(have_sympy, "SymPy not installed")
108118
def test_FunctionWrapper():
109119
import sympy
110120
n, m, theta, phi = sympy.symbols("n, m, theta, phi")

0 commit comments

Comments
 (0)