def mapdl(request): """This fixture will only be called if ``ansys.mapdl.core`` is installed.""" from ansys.mapdl.core import launch_mapdl from ansys.mapdl.core.misc import get_ansys_bin from ansys.mapdl.core.launcher import get_start_instance # check if the user wants to permit pytest to start MAPDL # and don't allow mapdl to exit upon collection unless mapdl is local cleanup = get_start_instance() # check for a valid MAPDL install with gRPC valid_rver = ['211'] # checks in this order EXEC_FILE = None for rver in valid_rver: if os.path.isfile(get_ansys_bin(rver)): EXEC_FILE = get_ansys_bin(rver) break return launch_mapdl(EXEC_FILE, override=True, cleanup_on_exit=cleanup)
"201", # 2020R1 "202", # 2020R2 "211", # 2021R1 "212", # 2021R2 ] valid_versions = [] for version in versions: exec_file = get_ansys_bin(version) if os.path.isfile(get_ansys_bin(version)): valid_versions.append(version) V150_EXEC = get_ansys_bin("150") # skip entire module when using static server if not get_start_instance(): pytest.skip("Skip when start instance is disabled", allow_module_level=True) if not valid_versions: pytestmark = pytest.mark.skip("Requires MAPDL") paths = [ ("/usr/dir_v2019.1/slv/ansys_inc/v211/ansys/bin/ansys211", 211), ("C:/Program Files/ANSYS Inc/v202/ansys/bin/win64/ANSYS202.exe", 202), ("/usr/ansys_inc/v211/ansys/bin/mapdl", 211), ] @pytest.mark.skipif(os.name != "nt", reason="Requires Windows") def test_validate_sw():
from ansys.mapdl.core.misc import get_ansys_bin from ansys.mapdl.core import LocalMapdlPool, examples from ansys.mapdl.core.launcher import get_start_instance # check for a valid MAPDL install with gRPC valid_rver = ['211'] EXEC_FILE = None for rver in valid_rver: if os.path.isfile(get_ansys_bin(rver)): EXEC_FILE = get_ansys_bin(rver) break IGNORE_POOL = os.environ.get('IGNORE_POOL', '').upper() == 'TRUE' skip_launch_mapdl = pytest.mark.skipif( get_start_instance() is False or IGNORE_POOL, reason="Must be able to launch MAPDL locally") TWAIT = 90 @pytest.fixture(scope="module") def pool(): mapdl_pool = LocalMapdlPool(4, exec_file=EXEC_FILE) yield mapdl_pool ########################################################################## # test exit mapdl_pool.exit() timeout = time.time() + TWAIT
EXEC_FILE = get_ansys_bin(rver) break # Cache if gRPC MAPDL is installed. # # minimum version on linux. Windows is v202, but using v211 for consistency # Override this if running on CI/CD and PYMAPDL_PORT has been specified ON_CI = "PYMAPDL_START_INSTANCE" in os.environ and "PYMAPDL_PORT" in os.environ HAS_GRPC = int(rver) >= 211 or ON_CI # determine if we can launch an instance of MAPDL locally # start with ``False`` and always assume the remote case local = [False] # check if the user wants to permit pytest to start MAPDL START_INSTANCE = get_start_instance() if os.name == "nt": os_msg = """SET PYMAPDL_START_INSTANCE=False SET PYMAPDL_PORT=<MAPDL Port> (default 50052) SET PYMAPDL_IP=<MAPDL IP> (default 127.0.0.1)""" else: os_msg = """export PYMAPDL_START_INSTANCE=False export PYMAPDL_PORT=<MAPDL Port> (default 50052) export PYMAPDL_IP=<MAPDL IP> (default 127.0.0.1)""" ERRMSG = f"""Unable to run unit tests without MAPDL installed or accessible. Either install Ansys 2021R1 or newer or specify the remote server with: {os_msg}
import numpy as np import pytest from ansys.mapdl import core as pymapdl from ansys.mapdl.core.errors import MapdlRuntimeError from ansys.mapdl.core.misc import random_string from ansys.mapdl.reader import examples from pyvista import PolyData from pyvista.plotting import system_supports_plotting from pyvista.plotting.renderer import CameraPosition from ansys.mapdl.core.launcher import get_start_instance skip_no_xserver = pytest.mark.skipif(not system_supports_plotting(), reason="Requires active X Server") skip_in_cloud = pytest.mark.skipif(not get_start_instance(), reason=""" Must be able to launch MAPDL locally. Remote execution does not allow for directory creation. """) CMD_BLOCK = """/prep7 ! Mat MP,EX,1,200000 MP,NUXY,1,0.3 MP,DENS,1,7.85e-09 ! Elements et,1,186 et,2,154 ! Geometry BLC4,0,0,1000,100,10
"""Test PyMAPDL license.py module.""" import time import types import os import pytest from ansys.mapdl.core import licensing, errors, launch_mapdl from ansys.mapdl.core.misc import threaded from ansys.mapdl.core.launcher import get_start_instance, check_valid_ansys skip_launch_mapdl = pytest.mark.skipif( not get_start_instance() and check_valid_ansys(), reason="Must be able to launch MAPDL locally") FAKE_CHECKOUT_SUCCESS = """ 2021/09/17 14:08:19 INFO Starting Licensing Client Proxy server. 2021/09/17 14:08:19 INFO /usr/ansys_inc/v212/licensingclient/linx64/ansyscl -acl 3423788.77064 -nodaemon -log /home/USER/.ansys/ansyscl.HOST.3423788.77064.log 2021/09/17 14:08:19 INFO Started ANSYSLI server. 2021/09/17 14:08:21 CLIENT_CONNECT 1/1/1/1 3423788:FEAT_ANSYS:USER@HOST:linx64 25:127.0.1.1 2021/09/17 14:08:21 NEW_CONNECTION Connected to Licensing Client Proxy server: [email protected]. 2021/09/17 14:08:21 CHECKOUT ansys 21.2 (2021.0512) 1/1/1/30 1/1/1/1 3423788:FEAT_ANSYS:USER@HOST:linx64 25:127.0.1.1 2021/09/17 14:08:21 CHECKOUT FEAT_ANSYS 21.2 (2021.0512) 1/1/1/1 1/1/1/1 3423788:FEAT_ANSYS:USER@HOST:linx64 25:127.0.1.1 2021/09/17 14:08:21 SPLIT_CHECKOUT HPC_PARALLEL 21.2 (2021.0512) 2/2/2/4 1/1/1/1 3423788:FEAT_ANSYS:USER@HOST:linx64 25:127.0.1.1 2021/09/17 14:08:21 CHECKOUT HPC_PARALLEL 21.2 (2021.0512) 2/2/2/4 1/1/1/1 3423788:FEAT_ANSYS:USER@HOST:linx64 25:127.0.1.1 """ # TEST-NET-3 (not quite a black hole, but set aside by RFC 5737) test_net_3 = "203.0.113.0" PATH = os.path.dirname(os.path.abspath(__file__))