Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Windows tests #2918

Merged
merged 34 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7167507
fix inquire default test
germa89 Mar 19, 2024
6aa8682
fixing the test_detach_examples_submodule
germa89 Mar 19, 2024
39446ec
Fixing test on linux
germa89 Mar 19, 2024
b4df209
Fixing test_get_file_path
germa89 Mar 19, 2024
adf9276
adding gopr
germa89 Mar 19, 2024
bff1c4c
Update tests/conftest.py
germa89 Mar 20, 2024
79e4e24
fixing tbft test
Mar 20, 2024
3141256
fixing launch cli
Mar 20, 2024
e4d808c
Fixing test_launch_mapdl_cli test
germa89 Mar 20, 2024
d0e2299
fixing cli list test on cluster
Mar 20, 2024
76b8d41
fixing licensing tests
Mar 20, 2024
ccd3ea4
making ports depending on the mapdl fixture
Mar 20, 2024
ae1ce22
fixing missing licensing tests
germa89 Mar 20, 2024
bf10d17
Merge branch 'fix/windows-tests' of https://github.com/ansys/pymapdl …
germa89 Mar 20, 2024
4466200
Avoinding raising exception about exec_file
germa89 Mar 20, 2024
0f64af9
Fixing test_cache_pids
germa89 Mar 20, 2024
7251bcc
Fix test_file_command_local
germa89 Mar 20, 2024
6737405
Fix test_inquire
germa89 Mar 20, 2024
68d9961
fixing recovering MAPDL instance between tests
germa89 Mar 20, 2024
336d313
Merge branch 'main' into fix/windows-tests
germa89 Mar 20, 2024
b890323
Merge branch 'main' into fix/windows-tests
germa89 Mar 21, 2024
1e4e31c
attemp to fix reconnect to MAPDL.
germa89 Mar 21, 2024
18682db
fixing cli test
Mar 21, 2024
29e1a28
fixing not raising wanring
Mar 21, 2024
c666df8
fix test readin
Mar 21, 2024
b9de139
trying catching the warn
Mar 21, 2024
0943195
Merge branch 'main' into fix/windows-tests
germa89 Mar 21, 2024
6d18700
Reseting full mapdl object
germa89 Mar 21, 2024
576c574
avoiding test
germa89 Mar 21, 2024
b03a4b4
improving test reliability
germa89 Mar 21, 2024
50fbc5b
skipping check on v241
Mar 21, 2024
543abaf
return empty string if on debug
Mar 21, 2024
d528bd8
Rising the raise exception
Mar 21, 2024
7941b77
Fixing error type
Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/ansys/mapdl/core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,11 @@ def launch_mapdl(

LOG.debug("Using default executable.")
# Load cached path
exec_file = get_ansys_path(version=version) if not _debug_no_launch else ""
if _debug_no_launch:
exec_file = ""
else:
exec_file = get_ansys_path(version=version)

if exec_file is None:
raise FileNotFoundError(
"Invalid exec_file path or cannot load cached "
Expand Down
19 changes: 15 additions & 4 deletions src/ansys/mapdl/core/mapdl_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import tempfile
import time
from typing import TYPE_CHECKING, Any, Dict, List, Literal, Optional, Tuple, Union
import warnings
from warnings import warn
import weakref

Expand All @@ -57,6 +56,7 @@
from ansys.mapdl.core.errors import (
ComponentNoData,
MapdlCommandIgnoredError,
MapdlFileNotFoundError,
MapdlInvalidRoutineError,
MapdlRuntimeError,
)
Expand Down Expand Up @@ -1977,7 +1977,7 @@ def run_multiline(self, commands) -> str:

"""

warnings.warn(
warn(
"'run_multiline()' is being deprecated in future versions.\n Please use 'input_strings'.",
DeprecationWarning,
)
Expand Down Expand Up @@ -2678,7 +2678,13 @@ def _perform_entity_list_selection(
def _raise_errors(self, text):
# to make sure the following error messages are caught even if a breakline is in between.
flat_text = " ".join([each.strip() for each in text.splitlines()])
base_error_msg = "\n\nIgnore these messages by setting 'ignore_errors'=True"
base_error_msg = "\n\nIgnore these messages by setting 'ignore_errors'=True.\n"

if "unable to open file" in flat_text or (
"unable to open" in flat_text and "file" in flat_text
):
text += base_error_msg
raise MapdlFileNotFoundError(text)

if "is not a recognized" in flat_text:
text = text.replace("This command will be ignored.", "")
Expand Down Expand Up @@ -2706,10 +2712,15 @@ def _raise_errors(self, text):

if "For element type = " in flat_text and "is invalid." in flat_text:
if "is normal behavior when a CDB file is used." in flat_text:
warn(text)
warn(text, UserWarning)
else:
text += base_error_msg
raise MapdlCommandIgnoredError(text)

if "Cannot create another with the same name" in flat_text:
# When overriding constitutive models. See 'test_tbft'
warn(text, UserWarning)

# flag errors
if "*** ERROR ***" in flat_text:
self._raise_output_errors(text)
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/mapdl/core/mapdl_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ def inquire(self, strarray="", func="", arg1="", arg2=""):
"RSTFILE",
"RSTEXT",
"OUTPUT",
"ENVNAME",
"ENV",
"TITLE",
"EXIST",
"DATE",
Expand Down
41 changes: 26 additions & 15 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,12 @@ def requires_dependency(dependency: str):

pymapdl.RUNNING_TESTS = True

from ansys.mapdl.core.errors import MapdlExitedError, MapdlRuntimeError
from ansys.mapdl.core import Mapdl
from ansys.mapdl.core.errors import (
MapdlConnectionError,
MapdlExitedError,
MapdlRuntimeError,
)
from ansys.mapdl.core.examples import vmfiles
from ansys.mapdl.core.launcher import get_start_instance, launch_mapdl

Expand Down Expand Up @@ -406,26 +411,32 @@ def is_exited(mapdl):
except MapdlExitedError:
return True

if START_INSTANCE and is_exited(mapdl):
if START_INSTANCE and (is_exited(mapdl) or mapdl._exited):
# Backing up the current local configuration
local_ = mapdl._local

# Relaunching MAPDL
mapdl_ = launch_mapdl(
port=mapdl._port,
override=True,
run_location=mapdl._path,
cleanup_on_exit=mapdl._cleanup,
)

# Cloning the new mapdl instance channel into the old one.
mapdl._channel = mapdl_._channel
mapdl._multi_connect(timeout=mapdl._timeout)
channel = mapdl._channel
ip = mapdl.ip
port = mapdl.port
try:
# to connect
mapdl = Mapdl(port=port, ip=ip)

except MapdlConnectionError as err:
# we cannot connect.
# Kill the instance
mapdl.exit()

# Relaunching MAPDL
mapdl = launch_mapdl(
port=mapdl._port,
override=True,
run_location=mapdl._path,
cleanup_on_exit=mapdl._cleanup,
)

# Restoring the local configuration
mapdl._local = local_

mapdl.gopr()
yield # this is where the testing happens

# Teardown : fill with any logic you want
Expand Down
17 changes: 9 additions & 8 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ def test_launch_mapdl_cli(monkeypatch, run_cli, start_instance):
if start_instance is not None:
monkeypatch.setenv("PYMAPDL_START_INSTANCE", str(start_instance))
else:
monkeypatch.unset("PYMAPDL_START_INSTANCE")
monkeypatch.delenv("PYMAPDL_START_INSTANCE", raising=False)

output = run_cli()
# Setting a port so it does not collide with the already running instance for testing
output = run_cli("start --port 50053")

# In local
assert "Success: Launched an MAPDL instance " in output
assert "50053" in output

# grab ips and port
pid = int(re.search(r"\(PID=(\d+)\)", output).groups()[0])
Expand Down Expand Up @@ -133,34 +134,34 @@ def test_launch_mapdl_cli_config(run_cli):
@requires("nostudent")
def test_launch_mapdl_cli_list(run_cli):
output = run_cli("list")
assert "running" in output
assert "running" in output or "sleeping" in output
assert "Is Instance" in output
assert len(output.splitlines()) > 2
assert "ansys" in output.lower() or "mapdl" in output.lower()

output = run_cli("list -i")
assert "running" in output
assert "running" in output or "sleeping" in output
assert "Is Instance" not in output
assert len(output.splitlines()) > 2
assert "ansys" in output.lower() or "mapdl" in output.lower()

output = run_cli("list -c")
assert "running" in output
assert "running" in output or "sleeping" in output
assert "Command line" in output
assert "Is Instance" in output
assert len(output.splitlines()) > 2
assert "ansys" in output.lower() or "mapdl" in output.lower()

output = run_cli("list -cwd")
assert "running" in output
assert "running" in output or "sleeping" in output
assert "Command line" not in output
assert "Working directory" in output
assert "Is Instance" in output
assert len(output.splitlines()) > 2
assert "ansys" in output.lower() or "mapdl" in output.lower()

output = run_cli("list -l")
assert "running" in output
assert "running" in output or "sleeping" in output
assert "Is Instance" in output
assert "Command line" in output
assert len(output.splitlines()) > 2
Expand Down
29 changes: 17 additions & 12 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,28 +164,33 @@ def test_download_tech_demo_data(running_test):

@requires("requests")
def test_detach_examples_submodule():
cmd = """
cmd = (
"""
import sys

assert "ansys.mapdl.core" not in sys.modules
assert "requests" not in sys.modules
assert "ansys.mapdl.core.examples" not in sys.modules
assert 'ansys.mapdl.core' not in sys.modules
assert 'requests' not in sys.modules
assert 'ansys.mapdl.core.examples' not in sys.modules

from ansys.mapdl import core as pymapdl

assert "ansys.mapdl.core" in sys.modules
assert "ansys.mapdl.core.examples" not in sys.modules
assert "requests" not in sys.modules
assert 'ansys.mapdl.core' in sys.modules
assert 'ansys.mapdl.core.examples' not in sys.modules
assert 'requests' not in sys.modules

from ansys.mapdl.core.examples import vmfiles

assert "ansys.mapdl.core.examples" in sys.modules
assert "requests" in sys.modules
assert 'ansys.mapdl.core.examples' in sys.modules
assert 'requests' in sys.modules

print("Everything went well")
"""
print('Everything went well')
""".strip()
.replace("\n", ";")
.replace(";;", ";")
)

cmd_line = f"""python -c "{cmd}" """

cmd_line = f"""python -c '{cmd}' """
p = Popen(cmd_line, shell=True, stdout=PIPE, stderr=STDOUT)
out = p.communicate()[0].decode()

Expand Down
47 changes: 25 additions & 22 deletions tests/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,21 @@ def test_launch_console(version):

@requires("local")
@requires("nostudent")
def test_license_type_keyword():
def test_license_type_keyword(mapdl):
checks = []
for license_name, license_description in LICENSES.items():
try:
mapdl = launch_mapdl(
mapdl_ = launch_mapdl(
license_type=license_name,
start_timeout=start_timeout,
port=mapdl.port + 1,
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])
mapdl.exit()
del mapdl
checks.append(license_description in mapdl_.__str__().split("\n")[0])
mapdl_.exit()
del mapdl_
sleep(2)

except MapdlDidNotStart as e:
Expand All @@ -210,43 +211,45 @@ def test_license_type_keyword():

@requires("local")
@requires("nostudent")
def test_license_type_keyword_names():
def test_license_type_keyword_names(mapdl):
# This test might became a way to check available licenses, which is not the purpose.

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

# Using first line to ensure not picking up other stuff.
successful_check = (
license_description in mapdl.__str__().split("\n")[0] or successful_check
license_description in mapdl_.__str__().split("\n")[0] or successful_check
)
assert license_description in mapdl.__str__().split("\n")[0]
mapdl.exit()
assert license_description in mapdl_.__str__().split("\n")[0]
mapdl_.exit()

assert successful_check # if at least one license is ok, this should be true.


@requires("local")
@requires("nostudent")
def test_license_type_additional_switch():
def test_license_type_additional_switch(mapdl):
# This test might became a way to check available licenses, which is not the purpose.
successful_check = False
for license_name, license_description in LICENSES.items():
mapdl = launch_mapdl(
mapdl_ = launch_mapdl(
additional_switches=QUICK_LAUNCH_SWITCHES + " -p " + license_name,
start_timeout=start_timeout,
port=mapdl.port + 1,
)

# Using first line to ensure not picking up other stuff.
successful_check = (
license_description in mapdl.__str__().split("\n")[0] or successful_check
license_description in mapdl_.__str__().split("\n")[0] or successful_check
)
mapdl.exit()
mapdl_.exit()

assert successful_check # if at least one license is ok, this should be true.

Expand All @@ -267,16 +270,16 @@ def test_license_type_dummy(mapdl):
@requires("nostudent")
def test_remove_temp_files(mapdl):
"""Ensure the working directory is removed when run_location is not set."""
mapdl = launch_mapdl(
mapdl_ = launch_mapdl(
port=mapdl.port + 1,
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
mapdl.exit()
path = mapdl_.directory
mapdl_.exit()

tmp_dir = tempfile.gettempdir()
ans_temp_dir = os.path.join(tmp_dir, "ansys_")
Expand All @@ -290,17 +293,17 @@ def test_remove_temp_files(mapdl):
@requires("nostudent")
def test_remove_temp_files_fail(tmpdir, mapdl):
"""Ensure the working directory is not removed when the cwd is changed."""
mapdl = launch_mapdl(
mapdl_ = launch_mapdl(
port=mapdl.port + 1,
remove_temp_files=True,
start_timeout=start_timeout,
additional_switches=QUICK_LAUNCH_SWITCHES,
)
old_path = mapdl.directory
old_path = mapdl_.directory
assert os.path.isdir(str(tmpdir))
mapdl.cwd(str(tmpdir))
path = mapdl.directory
mapdl.exit()
mapdl_.cwd(str(tmpdir))
path = mapdl_.directory
mapdl_.exit()
assert os.path.isdir(path)

# Checking no changes in the old path
Expand Down
9 changes: 5 additions & 4 deletions tests/test_licensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,21 @@ def test_license_checker(tmpdir, license_checker):

@requires("local")
@skip_no_lic_bin
def test_check_license_file(tmpdir):
def test_check_license_file(mapdl, tmpdir):
timeout = 15
checker = licensing.LicenseChecker(timeout=timeout)
# start the license check in the background
checker.start(checkout_license=False)

try:
mapdl = launch_mapdl(
mapdl_ = launch_mapdl(
license_server_check=False,
start_timeout=timeout,
additional_switches=QUICK_LAUNCH_SWITCHES,
port=mapdl.port + 1,
)
assert mapdl._local
mapdl.exit()
assert mapdl_._local
mapdl_.exit()
except IOError: # MAPDL never started
assert not checker._license_file_success
else:
Expand Down
Loading
Loading