Skip to content

Commit

Permalink
Using quicker configuration to launch mapdl in unit tests (#2343)
Browse files Browse the repository at this point in the history
Using quicker configuration to launch mapdl
  • Loading branch information
germa89 authored Sep 18, 2023
1 parent 0022f4e commit 3e949de
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 27 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
SUPPORT_PLOTTING = pyvista.system_supports_plotting()
IS_SMP = is_smp()

QUICK_LAUNCH_SWITCHES = "-smp -m 100 -db 100"

# check if the user wants to permit pytest to start MAPDL
START_INSTANCE = get_start_instance()
Expand Down Expand Up @@ -347,7 +348,6 @@ def mapdl(request, tmpdir_factory):
run_location=run_path,
cleanup_on_exit=cleanup,
license_server_check=False,
# additional_switches="-smp",
start_timeout=50,
)
mapdl._show_matplotlib_figures = False # CI: don't show matplotlib figures
Expand Down
58 changes: 47 additions & 11 deletions tests/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
version_from_path,
)
from ansys.mapdl.core.licensing import LICENSES
from conftest import skip_if_not_local, skip_on_linux, skip_on_windows
from conftest import (
QUICK_LAUNCH_SWITCHES,
skip_if_not_local,
skip_on_linux,
skip_on_windows,
)

try:
import ansys_corba # noqa: F401
Expand Down Expand Up @@ -154,7 +159,11 @@ def test_launch_corba(version):
def test_license_type_keyword():
checks = []
for license_name, license_description in LICENSES.items():
mapdl = launch_mapdl(license_type=license_name, start_timeout=start_timeout)
mapdl = launch_mapdl(
license_type=license_name,
start_timeout=start_timeout,
additional_switches=QUICK_LAUNCH_SWITCHES,
)

# Using first line to ensure not picking up other stuff.
checks.append(license_description in mapdl.__str__().split("\n")[0])
Expand All @@ -170,7 +179,11 @@ def test_license_type_keyword_names():

successful_check = False
for license_name, license_description in LICENSES.items():
mapdl = launch_mapdl(license_type=license_name, start_timeout=start_timeout)
mapdl = launch_mapdl(
license_type=license_name,
start_timeout=start_timeout,
additional_switches=QUICK_LAUNCH_SWITCHES,
)

# Using first line to ensure not picking up other stuff.
successful_check = (
Expand All @@ -188,7 +201,8 @@ def test_license_type_additional_switch():
successful_check = False
for license_name, license_description in LICENSES.items():
mapdl = launch_mapdl(
additional_switches=" -p " + license_name, start_timeout=start_timeout
additional_switches=QUICK_LAUNCH_SWITCHES + " -p " + license_name,
start_timeout=start_timeout,
)

# Using first line to ensure not picking up other stuff.
Expand All @@ -205,14 +219,19 @@ def test_license_type_dummy():
dummy_license_type = "dummy"
with pytest.raises(LicenseServerConnectionError):
launch_mapdl(
additional_switches=f" -p {dummy_license_type}", start_timeout=start_timeout
additional_switches=f" -p {dummy_license_type}" + QUICK_LAUNCH_SWITCHES,
start_timeout=start_timeout,
)


@skip_if_not_local
def test_remove_temp_files():
"""Ensure the working directory is removed when run_location is not set."""
mapdl = launch_mapdl(remove_temp_files=True, start_timeout=start_timeout)
mapdl = launch_mapdl(
remove_temp_files=True,
start_timeout=start_timeout,
additional_switches=QUICK_LAUNCH_SWITCHES,
)

# possible MAPDL is installed but running in "remote" mode
path = mapdl.directory
Expand All @@ -229,7 +248,11 @@ def test_remove_temp_files():
@skip_if_not_local
def test_remove_temp_files_fail(tmpdir):
"""Ensure the working directory is not removed when the cwd is changed."""
mapdl = launch_mapdl(remove_temp_files=True, start_timeout=start_timeout)
mapdl = launch_mapdl(
remove_temp_files=True,
start_timeout=start_timeout,
additional_switches=QUICK_LAUNCH_SWITCHES,
)
old_path = mapdl.directory
assert os.path.isdir(str(tmpdir))
mapdl.cwd(str(tmpdir))
Expand Down Expand Up @@ -382,14 +405,23 @@ def test_find_ansys(mapdl):
@skip_if_not_local
def test_version(mapdl):
version = int(10 * mapdl.version)
mapdl_ = launch_mapdl(version=version, start_timeout=start_timeout)
mapdl_ = launch_mapdl(
version=version,
start_timeout=start_timeout,
additional_switches=QUICK_LAUNCH_SWITCHES,
)
mapdl_.exit()


@skip_if_not_local
def test_raise_exec_path_and_version_launcher():
with pytest.raises(ValueError):
launch_mapdl(exec_file="asdf", version="asdf", start_timeout=start_timeout)
launch_mapdl(
exec_file="asdf",
version="asdf",
start_timeout=start_timeout,
additional_switches=QUICK_LAUNCH_SWITCHES,
)


@skip_on_windows
Expand All @@ -405,12 +437,16 @@ def test_get_default_ansys():

def test_launch_mapdl_non_recognaised_arguments():
with pytest.raises(ValueError, match="my_fake_argument"):
launch_mapdl(my_fake_argument="my_fake_value")
launch_mapdl(
my_fake_argument="my_fake_value", additional_switches=QUICK_LAUNCH_SWITCHES
)


def test_mapdl_non_recognaised_arguments():
with pytest.raises(ValueError, match="my_fake_argument"):
pymapdl.Mapdl(my_fake_argument="my_fake_value")
pymapdl.Mapdl(
my_fake_argument="my_fake_value", additional_switches=QUICK_LAUNCH_SWITCHES
)


def test__parse_ip_route():
Expand Down
5 changes: 4 additions & 1 deletion tests/test_launcher_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from ansys.mapdl.core.launcher import launch_mapdl
from ansys.mapdl.core.mapdl_grpc import MAX_MESSAGE_LENGTH
from conftest import QUICK_LAUNCH_SWITCHES


def test_launch_remote_instance(monkeypatch, mapdl):
Expand Down Expand Up @@ -42,7 +43,9 @@ def test_launch_remote_instance(monkeypatch, mapdl):
# Start MAPDL with launch_mapdl
# Note: This is mocking to start MAPDL, but actually reusing the common one
# Thus cleanup_on_exit is set to false
mapdl = launch_mapdl(cleanup_on_exit=False)
mapdl = launch_mapdl(
cleanup_on_exit=False, additional_switches=QUICK_LAUNCH_SWITCHES
)

# Assert: pymapdl went through the pypim workflow
assert mock_is_configured.called
Expand Down
8 changes: 6 additions & 2 deletions tests/test_licensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ansys.mapdl.core import errors, launch_mapdl, licensing
from ansys.mapdl.core.misc import threaded
from conftest import ON_LOCAL as IS_LOCAL
from conftest import skip_if_not_local
from conftest import QUICK_LAUNCH_SWITCHES, skip_if_not_local

try:
LIC_INSTALLED = os.path.isfile(licensing.get_ansys_license_utility_path())
Expand Down Expand Up @@ -167,7 +167,11 @@ def test_check_license_file(tmpdir):
checker.start(checkout_license=False)

try:
mapdl = launch_mapdl(license_server_check=False, start_timeout=timeout)
mapdl = launch_mapdl(
license_server_check=False,
start_timeout=timeout,
additional_switches=QUICK_LAUNCH_SWITCHES,
)
assert mapdl._local
mapdl.exit()
except IOError: # MAPDL never started
Expand Down
20 changes: 14 additions & 6 deletions tests/test_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from conftest import (
IS_SMP,
ON_LOCAL,
QUICK_LAUNCH_SWITCHES,
skip_if_not_local,
skip_if_on_cicd,
skip_no_xserver,
Expand Down Expand Up @@ -465,7 +466,9 @@ def test_lplot(cleared, mapdl, tmpdir, vtk):
def test_apdl_logging_start(tmpdir):
filename = str(tmpdir.mkdir("tmpdir").join("tmp.inp"))

mapdl = launch_mapdl(start_timeout=30, log_apdl=filename)
mapdl = launch_mapdl(
start_timeout=30, log_apdl=filename, additional_switches=QUICK_LAUNCH_SWITCHES
)

mapdl.prep7()
mapdl.run("!comment test")
Expand All @@ -491,8 +494,7 @@ def test_apdl_logging_start(tmpdir):
def test_corba_apdl_logging_start(tmpdir):
filename = str(tmpdir.mkdir("tmpdir").join("tmp.inp"))

mapdl = pymapdl.launch_mapdl(mode="CORBA")
mapdl = launch_mapdl(log_apdl=filename)
mapdl = pymapdl.launch_mapdl(mode="CORBA", log_apdl=filename)

mapdl.prep7()
mapdl.run("!comment test")
Expand Down Expand Up @@ -1944,7 +1946,9 @@ def test_cuadratic_beam(mapdl, cuadratic_beam_problem):

@skip_if_not_local
def test_save_on_exit(mapdl, cleared):
mapdl2 = launch_mapdl(license_server_check=False)
mapdl2 = launch_mapdl(
license_server_check=False, additional_switches=QUICK_LAUNCH_SWITCHES
)
mapdl2.parameters["my_par"] = "asdf"
db_name = mapdl2.jobname + ".db"
db_dir = mapdl2.directory
Expand All @@ -1956,7 +1960,9 @@ def test_save_on_exit(mapdl, cleared):
mapdl2.parameters["my_par"] = "qwerty"
mapdl2.exit()

mapdl2 = launch_mapdl(license_server_check=False)
mapdl2 = launch_mapdl(
license_server_check=False, additional_switches=QUICK_LAUNCH_SWITCHES
)
mapdl2.resume(db_path)
assert mapdl2.parameters["my_par"] == "qwerty"

Expand All @@ -1966,7 +1972,9 @@ def test_save_on_exit(mapdl, cleared):
db_path = os.path.join(db_dir, db_name)
mapdl2.exit(save=True)

mapdl2 = launch_mapdl(license_server_check=False)
mapdl2 = launch_mapdl(
license_server_check=False, additional_switches=QUICK_LAUNCH_SWITCHES
)
mapdl2.resume(db_path)
assert mapdl2.parameters["my_par"] == "zxcv"
mapdl2.exit()
Expand Down
11 changes: 5 additions & 6 deletions tests/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from ansys.mapdl.core import LocalMapdlPool, examples
from ansys.mapdl.core.errors import VersionError
from conftest import skip_if_not_local
from conftest import QUICK_LAUNCH_SWITCHES, skip_if_not_local

# skip entire module unless HAS_GRPC
pytestmark = pytest.mark.skip_grpc
Expand All @@ -26,7 +26,6 @@
)

TWAIT = 90
LAUNCH_SWITCHES = "-smp -m 100 -db 100"
NPROC = 1


Expand All @@ -42,7 +41,7 @@ def pool(tmpdir_factory):
port=50056,
start_timeout=30,
exec_file=EXEC_FILE,
additional_switches=LAUNCH_SWITCHES,
additional_switches=QUICK_LAUNCH_SWITCHES,
nproc=NPROC,
)
yield mapdl_pool
Expand Down Expand Up @@ -74,7 +73,7 @@ def test_invalid_exec():
4,
nproc=NPROC,
exec_file="/usr/ansys_inc/v194/ansys/bin/mapdl",
additional_switches=LAUNCH_SWITCHES,
additional_switches=QUICK_LAUNCH_SWITCHES,
)


Expand Down Expand Up @@ -227,7 +226,7 @@ def test_directory_names_custom_string(tmpdir):
nproc=NPROC,
names="my_instance",
port=50056,
additional_switches=LAUNCH_SWITCHES,
additional_switches=QUICK_LAUNCH_SWITCHES,
)

dirs_path_pool = os.listdir(pool._root_dir)
Expand All @@ -253,7 +252,7 @@ def myfun(i):
nproc=NPROC,
names=myfun,
run_location=tmpdir,
additional_switches=LAUNCH_SWITCHES,
additional_switches=QUICK_LAUNCH_SWITCHES,
)

dirs_path_pool = os.listdir(pool._root_dir)
Expand Down

0 comments on commit 3e949de

Please sign in to comment.