From c502090ce85c37e6c03d2b945fa5ae456e148cc1 Mon Sep 17 00:00:00 2001 From: Alex Fikl Date: Thu, 14 Jun 2018 15:40:51 -0500 Subject: [PATCH] remove redundant importorskip on pexpect --- test/test_maxima.py | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/test/test_maxima.py b/test/test_maxima.py index 675759d..ddb5c76 100644 --- a/test/test_maxima.py +++ b/test/test_maxima.py @@ -26,28 +26,29 @@ import pytest from pymbolic.interop.maxima import MaximaKernel -# {{{ check for maxima executable +# {{{ check for maxima -def _find_maxima_executable(): - global FOUND_MAXIMA +def _check_maxima(): + global MAXIMA_UNAVAILABLE + + import os + executable = os.environ.get("PYMBOLIC_MAXIMA_EXECUTABLE", "maxima") try: - knl = MaximaKernel() - FOUND_MAXIMA = True + knl = MaximaKernel(executable=executable) + MAXIMA_UNAVAILABLE = False knl.shutdown() except (ImportError, RuntimeError): - FOUND_MAXIMA = False + MAXIMA_UNAVAILABLE = True -_find_maxima_executable() +_check_maxima() # }}} -@pytest.mark.skipif(not FOUND_MAXIMA, reason="cannot find maxima executable") +@pytest.mark.skipif(MAXIMA_UNAVAILABLE, reason="maxima cannot be launched") def test_kernel(): - pytest.importorskip("pexpect") - knl = MaximaKernel() knl.exec_str("k:1/(sqrt((x0-(a+t*b))^2+(y0-(c+t*d))^2+(z0-(e+t*f))^2))") knl.eval_str("sum(diff(k, t,deg)*t^deg,deg,0,6)") @@ -57,23 +58,19 @@ def test_kernel(): @pytest.fixture def knl(request): - pytest.importorskip("pexpect") - knl = MaximaKernel() request.addfinalizer(knl.shutdown) return knl -@pytest.mark.skipif(not FOUND_MAXIMA, reason="cannot find maxima executable") +@pytest.mark.skipif(MAXIMA_UNAVAILABLE, reason="maxima cannot be launched") def test_setup(knl): - pytest.importorskip("pexpect") - knl.clean_eval_str_with_setup( ["k:1/(sqrt((x0-(a+t*b))^2+(y0-(c+t*d))^2+(z0-(e+t*f))^2))"], "sum(diff(k, t,deg)*t^deg,deg,0,6)") -@pytest.mark.skipif(not FOUND_MAXIMA, reason="cannot find maxima executable") +@pytest.mark.skipif(MAXIMA_UNAVAILABLE, reason="maxima cannot be launched") def test_error(knl): from pymbolic.interop.maxima import MaximaError try: @@ -87,7 +84,7 @@ def test_error(knl): pass -@pytest.mark.skipif(not FOUND_MAXIMA, reason="cannot find maxima executable") +@pytest.mark.skipif(MAXIMA_UNAVAILABLE, reason="maxima cannot be launched") def test_strict_round_trip(knl): from pymbolic import parse from pymbolic.primitives import Quotient @@ -112,7 +109,7 @@ def test_strict_round_trip(knl): assert round_trips_correctly -@pytest.mark.skipif(not FOUND_MAXIMA, reason="cannot find maxima executable") +@pytest.mark.skipif(MAXIMA_UNAVAILABLE, reason="maxima cannot be launched") def test_lax_round_trip(knl): from pymbolic.interop.maxima import MaximaParser k_setup = [ @@ -127,7 +124,7 @@ def test_lax_round_trip(knl): "ratsimp(result-result2)") == 0 -@pytest.mark.skipif(not FOUND_MAXIMA, reason="cannot find maxima executable") +@pytest.mark.skipif(MAXIMA_UNAVAILABLE, reason="maxima cannot be launched") def test_parse_matrix(knl): z = knl.clean_eval_str_with_setup([ "A:matrix([1,2+0.3*dt], [3,4])", @@ -139,26 +136,22 @@ def test_parse_matrix(knl): print(MaximaParser()(z)) -@pytest.mark.skipif(not FOUND_MAXIMA, reason="cannot find maxima executable") +@pytest.mark.skipif(MAXIMA_UNAVAILABLE, reason="maxima cannot be launched") def test_diff(): - pytest.importorskip("pexpect") - from pymbolic.interop.maxima import diff from pymbolic import parse diff(parse("sqrt(x**2+y**2)"), parse("x")) -@pytest.mark.skipif(not FOUND_MAXIMA, reason="cannot find maxima executable") +@pytest.mark.skipif(MAXIMA_UNAVAILABLE, reason="maxima cannot be launched") def test_long_command(knl): from pymbolic.interop.maxima import set_debug set_debug(4) knl.eval_str("+".join(["1"]*16384)) -@pytest.mark.skipif(not FOUND_MAXIMA, reason="cannot find maxima executable") +@pytest.mark.skipif(MAXIMA_UNAVAILABLE, reason="maxima cannot be launched") def test_restart(knl): - pytest.importorskip("pexpect") - knl = MaximaKernel() knl.restart() knl.eval_str("1") -- GitLab