Skip to content

Commit

Permalink
making ports depending on the mapdl fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
german committed Mar 20, 2024
1 parent 76b8d41 commit ccd3ea4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 34 deletions.
58 changes: 28 additions & 30 deletions tests/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
from ansys.mapdl.core.licensing import LICENSES
from conftest import ON_LOCAL, QUICK_LAUNCH_SWITCHES, NullContext, requires

PORT_TEST = 50053

try:
from ansys.tools.path import (
find_ansys,
Expand Down Expand Up @@ -183,21 +181,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=PORT_TEST,
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 @@ -211,45 +209,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=PORT_TEST,
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=PORT_TEST,
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 @@ -260,7 +258,7 @@ def test_license_type_dummy(mapdl):
dummy_license_type = "dummy"
with pytest.raises(LicenseServerConnectionError):
launch_mapdl(
port=PORT_TEST,
port=mapdl.port + 1,
additional_switches=f" -p {dummy_license_type}" + QUICK_LAUNCH_SWITCHES,
start_timeout=start_timeout,
)
Expand All @@ -270,16 +268,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(
port=PORT_TEST,
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 @@ -293,17 +291,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(
port=PORT_TEST,
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(tmpdir, mapdl):
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

0 comments on commit ccd3ea4

Please sign in to comment.