Skip to content

Commit 3d90759

Browse files
authored
Merge pull request #173 from isuruf/test
Have proper test skipping
2 parents 3541ffc + 20f5ad6 commit 3d90759

File tree

7 files changed

+155
-74
lines changed

7 files changed

+155
-74
lines changed

symengine/lib/symengine_wrapper.pyx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,15 @@ def _sympify(a, raise_error=True):
450450
return _sympify(a._sympy_(), raise_error)
451451
elif hasattr(a, 'pyobject'):
452452
return _sympify(a.pyobject(), raise_error)
453-
return sympy2symengine(a, raise_error)
453+
454+
try:
455+
import sympy
456+
return sympy2symengine(a, raise_error)
457+
except ImportError:
458+
pass
459+
460+
if raise_error:
461+
raise SympifyError("sympify: Cannot convert '%r' to a symengine type." % a)
454462

455463
funcs = {}
456464

@@ -604,6 +612,9 @@ cdef class Basic(object):
604612
def __dealloc__(self):
605613
self.thisptr.reset()
606614

615+
def _unsafe_reset(self):
616+
self.thisptr.reset()
617+
607618
def __add__(a, b):
608619
cdef Basic A = _sympify(a, False)
609620
B_ = _sympify(b, False)
@@ -2969,6 +2980,7 @@ false = c2py(symengine.boolFalse)
29692980

29702981
def module_cleanup():
29712982
global I, E, pi, oo, zoo, nan, true, false, GoldenRatio, Catalan, EulerGamma, sympy_module, sage_module
2983+
funcs.clear()
29722984
del I, E, pi, oo, zoo, nan, true, false, GoldenRatio, Catalan, EulerGamma, sympy_module, sage_module
29732985

29742986
import atexit

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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
polygamma, digamma, trigamma, EulerGamma, sign,
77
floor, ceiling, conjugate, nan, Float)
88

9+
import unittest
10+
11+
try:
12+
import sympy
13+
from sympy.core.cache import clear_cache
14+
import atexit
15+
atexit.register(clear_cache)
16+
have_sympy = True
17+
except ImportError:
18+
have_sympy = False
919

1020
def test_sin():
1121
x = Symbol("x")
@@ -110,6 +120,7 @@ def test_Subs():
110120
assert s.point == (2*x,)
111121

112122

123+
@unittest.skipUnless(have_sympy, "SymPy not installed")
113124
def test_FunctionWrapper():
114125
import sympy
115126
n, m, theta, phi = sympy.symbols("n, m, theta, phi")

0 commit comments

Comments
 (0)