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

test: faking-v150 #3509

Merged
merged 34 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b959054
fix: raising port busy when connecting
germa89 Oct 23, 2024
3d1d619
chore: adding changelog file 3507.fixed.md [dependabot-skip]
pyansys-ci-bot Oct 23, 2024
2ad60b5
refactor: tests
germa89 Oct 24, 2024
3c805d9
fix: check mode
germa89 Oct 24, 2024
6888b3a
fix: has_dependency
germa89 Oct 24, 2024
9c021f1
Merge branch 'fix/raising-busy-port' into tests/faking-v150
germa89 Oct 24, 2024
780c699
chore: adding changelog file 3509.added.md [dependabot-skip]
pyansys-ci-bot Oct 24, 2024
a061b5f
chore: update src/ansys/mapdl/core/launcher.py
germa89 Oct 25, 2024
4a01800
feat: removing memproof
germa89 Nov 21, 2024
db20658
chore: merge branch 'main' into tests/faking-v150
germa89 Nov 21, 2024
5873f26
docs: update src/ansys/mapdl/core/launcher.py
germa89 Nov 21, 2024
8b401a6
chore: merge branch 'tests/faking-v150' of https://github.com/ansys/p…
germa89 Nov 21, 2024
6d4f10c
fix: adding full directory
germa89 Nov 21, 2024
76edd83
test: testing lazy read
germa89 Nov 21, 2024
715c84a
chore: adding changelog file 3509.added.md [dependabot-skip]
pyansys-ci-bot Nov 21, 2024
77fc4e4
tests: not adding proc directory
germa89 Nov 25, 2024
5b43b45
chore: merge remote-tracking branch 'origin/main' into tests/faking-v150
germa89 Nov 25, 2024
0d9d4ff
chore: merge remote-tracking branch 'origin/main' into tests/faking-v150
germa89 Nov 25, 2024
3cb43fc
fix: test_old_version
germa89 Nov 25, 2024
dd56731
ci: add pyfakefs to minimal
germa89 Nov 25, 2024
fa46254
fix: test_invalid_mode
germa89 Nov 25, 2024
ce45e18
fix: patching psutil
germa89 Nov 25, 2024
5bcf3c7
fix: redundancy
germa89 Nov 25, 2024
66ac674
fix: tests
germa89 Nov 25, 2024
4d77bc2
fix: early exit
germa89 Nov 25, 2024
3dd0f1a
fix: tests
germa89 Nov 25, 2024
a8dec55
chore: merge remote-tracking branch 'origin/main' into tests/faking-v150
germa89 Nov 25, 2024
e1f4cdd
chore: merge remote-tracking branch 'origin/main' into tests/faking-v150
germa89 Nov 25, 2024
195b1b3
refactor: delegating to pypim first
germa89 Nov 25, 2024
816758a
fix: remove some warnings from pytest output
germa89 Nov 25, 2024
648e45a
feat: running MPI fix only if on windows
germa89 Nov 25, 2024
00a86ed
Merge branch 'main' into tests/faking-v150
germa89 Nov 26, 2024
ba3fa6b
Merge branch 'tests/faking-v150' of https://github.com/ansys/pymapdl …
germa89 Nov 26, 2024
97afffb
Merge branch 'main' into tests/faking-v150
germa89 Dec 10, 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
1 change: 1 addition & 0 deletions doc/changelog.d/3507.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: raising port busy when connecting
3 changes: 1 addition & 2 deletions src/ansys/mapdl/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
def is_installed(package_name: str) -> bool:
"""Check if a package is installed"""

if os.name == "nt":
package_name = package_name.replace("-", ".")
package_name = package_name.replace("-", ".")

try:
importlib.import_module(package_name)
Expand Down
22 changes: 17 additions & 5 deletions src/ansys/mapdl/core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,8 @@ def launch_mapdl(

if _HAS_ATP and not args["_debug_no_launch"]:
version = version_from_path("mapdl", args["exec_file"])
args["mode"] = check_mode(args["mode"], version)

args["mode"] = check_mode(args["mode"], args["version"])

if not args["mode"]:
args["mode"] = "grpc"
Expand Down Expand Up @@ -1544,10 +1545,19 @@ def launch_mapdl(
def check_mode(mode: ALLOWABLE_MODES, version: ALLOWABLE_VERSION_INT):
"""Check if the MAPDL server mode matches the allowable version

If ``None``, the newest mode will be selected.
If :class:`None`, the newest mode will be selected.

Returns a value from ``ALLOWABLE_MODES``.
"""
if not mode and not version:
return "grpc"
elif not version:
warnings.warn(
"PyMAPDL couldn't not detect MAPDL version, hence it could not "
germa89 marked this conversation as resolved.
Show resolved Hide resolved
f"verify that the connection mode {mode} is compatible with MAPDL."
)
return mode

if isinstance(mode, str):
mode = mode.lower()
if mode == "grpc":
Expand Down Expand Up @@ -2069,7 +2079,7 @@ def get_port(port: Optional[int] = None, start_instance: Optional[bool] = None)
LOG.debug(f"Port in use. Incrementing port number. port={port}")

else:
if port_in_use(port):
if start_instance and port_in_use(port):
proc = get_process_at_port(port)
if proc:
if is_ansys_process(proc):
Expand Down Expand Up @@ -2109,8 +2119,10 @@ def get_version(
if not version:
version = os.getenv("PYMAPDL_MAPDL_VERSION")

if not version:
# Early exit
if not version and exec_file and _HAS_ATP:
version = version_from_path("mapdl", exec_file)

elif not version:
germa89 marked this conversation as resolved.
Show resolved Hide resolved
return

if isinstance(version, float):
Expand Down
68 changes: 42 additions & 26 deletions tests/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,12 @@
from ansys.mapdl.core.launcher import get_default_ansys

installed_mapdl_versions = list(get_available_ansys_installations().keys())
try:
V150_EXEC = find_ansys("150")[0]
except ValueError:
V150_EXEC = ""

except:
from conftest import MAPDL_VERSION

installed_mapdl_versions = [MAPDL_VERSION]
V150_EXEC = ""


from ansys.mapdl.core._version import SUPPORTED_ANSYS_VERSIONS as versions

Expand All @@ -104,8 +101,7 @@ def fake_local_mapdl(mapdl):
mapdl._local = False


@requires("local")
@requires("windows")
@patch("os.name", "nt")
def test_validate_sw():
# ensure that windows adds msmpi
# fake windows path
Expand All @@ -121,49 +117,70 @@ def test_validate_sw():


@requires("ansys-tools-path")
@requires("local")
@pytest.mark.parametrize("path_data", paths)
def test_version_from_path(path_data):
exec_file, version = path_data
assert version_from_path("mapdl", exec_file) == version


@requires("ansys-tools-path")
@requires("local")
def test_catch_version_from_path():
with pytest.raises(RuntimeError):
version_from_path("mapdl", "abc")


from pyfakefs.fake_filesystem import OSType


@pytest.mark.parametrize(
"path,version,raises",
[
["/ansys_inc/v221/ansys/bin/ansys221", 22.1, None],
["/ansys_inc/v222/ansys/bin/mapdl", 22.2, None],
["/usr/ansys_inc/v231/ansys/bin/mapdl", 23.1, None],
["/usr/ansys_inc/v232/ansys/bin/mapdl", 23.2, None],
["/usr/ansys_inc/v241/ansys/bin/mapdl", 24.1, None],
["/ansysinc/v242/ansys/bin/ansys2", 24.2, ValueError],
["/ansysinc/v242/ansys/bin/mapdl", 24.2, ValueError],
],
)
@requires("ansys-tools-path")
@requires("local")
@requires("linux")
def test_find_ansys_linux():
# assuming ansys is installed, should be able to find it on linux
# without env var
def test_find_ansys_linux(fs, path, version, raises):
fs.os = OSType.LINUX
fs.create_file(path)
# fs.add_real_file("/proc/meminfo")

bin_file, ver = pymapdl.launcher.find_ansys()
assert os.path.isfile(bin_file)
assert isinstance(ver, float)

if raises:
assert not bin_file
assert not ver

else:
assert bin_file.startswith(path.replace("mapdl", ""))
assert isinstance(ver, float)
assert ver == version


@requires("ansys-tools-path")
@requires("local")
def test_invalid_mode(mapdl):
def test_invalid_mode(mapdl, fs):
fs.create_file("/ansys_inc/v241/ansys/bin/ansys241")
with pytest.raises(ValueError):
exec_file = find_ansys(installed_mapdl_versions[0])[0]
exec_file = find_ansys(241)[0]
pymapdl.launch_mapdl(
exec_file, port=mapdl.port + 1, mode="notamode", start_timeout=start_timeout
)


@requires("ansys-tools-path")
@requires("local")
@pytest.mark.skipif(not os.path.isfile(V150_EXEC), reason="Requires v150")
def test_old_version(mapdl):
exec_file = find_ansys("150")[0]
with pytest.raises(ValueError):
def test_old_version(mapdl, fs):
exec_file_v150 = "/ansys_inc/v150/ansys/bin/ansys150"
fs.create_file(exec_file_v150)
exec_file = find_ansys(150)[0]
assert exec_file == exec_file_v150
with pytest.raises(ValueError, match="MAPDL version must be one of the following:"):
pymapdl.launch_mapdl(
exec_file, port=mapdl.port + 1, mode="console", start_timeout=start_timeout
exec_file, port=mapdl.port + 1, mode="grpc", start_timeout=start_timeout
)


Expand Down Expand Up @@ -200,7 +217,6 @@ def test_license_type_keyword_names(mapdl, monkeypatch, license_name):
assert f"-p {license_name}" in args["additional_switches"]


# @requires("local")
@pytest.mark.parametrize("license_name", LICENSES)
def test_license_type_additional_switch(mapdl, license_name):
args = launch_mapdl(
Expand Down
Loading