Skip to content

Commit

Permalink
fix: avoiding long names in test arguments (#3583)
Browse files Browse the repository at this point in the history
* fix: avoiding long names in test arguments

* chore: adding changelog file 3583.fixed.md [dependabot-skip]

* feat: check command length also in mapdl.run

* tests: adding tests

---------

Co-authored-by: pyansys-ci-bot <[email protected]>
  • Loading branch information
germa89 and pyansys-ci-bot authored Dec 13, 2024
1 parent 3c81f2d commit 43ed236
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 21 deletions.
1 change: 1 addition & 0 deletions doc/changelog.d/3583.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: avoiding long names in test arguments
5 changes: 5 additions & 0 deletions src/ansys/mapdl/core/mapdl_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2179,6 +2179,11 @@ def run(
if "\n" in command or "\r" in command:
raise ValueError("Use ``input_strings`` for multi-line commands")

if len(command) > 639: # CMD_MAX_LENGTH
# If using mapdl_grpc, this check is redundant on purpose.
# Console probably do not have this limitation, but I'm not certain.
raise ValueError("Maximum command length must be less than 640 characters")

# Check kwargs
verbose = kwargs.pop("verbose", False)
save_fig = kwargs.pop("savefig", False)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2576,3 +2576,19 @@ def func(*args, **kwargs):
reload(pymapdl)

pymapdl.helpers.run_first_time()


def test_max_cmd_len(mapdl):
with pytest.raises(
ValueError, match="Maximum command length must be less than 640 characters"
):
cmd = "a" * 640
mapdl.run(cmd)


def test_max_cmd_len_mapdlgrpc(mapdl):
with pytest.raises(
ValueError, match="Maximum command length must be less than 640 characters"
):
cmd = "a" * 640
mapdl._run(cmd)
41 changes: 20 additions & 21 deletions tests/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,21 @@
from ansys.mapdl.core.errors import MapdlRuntimeError
from ansys.mapdl.core.parameters import interp_star_status

parm_status = """PARAMETER STATUS- PORT ( 12 PARAMETERS DEFINED)
GOLDEN_TESTS = {
"parameter status": """PARAMETER STATUS- PORT ( 12 PARAMETERS DEFINED)
(INCLUDING 3 INTERNAL PARAMETERS)
NAME VALUE TYPE DIMENSIONS
PORT 50054.0000 SCALAR"""

arr_status = """PARAMETER STATUS- ASDF ( 5 PARAMETERS DEFINED)
PORT 50054.0000 SCALAR""",
"array status": """PARAMETER STATUS- ASDF ( 5 PARAMETERS DEFINED)
(INCLUDING 3 INTERNAL PARAMETERS)
LOCATION VALUE
1 1 1 1.00000000
2 1 1 2.00000000
3 1 1 3.00000000
4 1 1 4.00000000"""

arr3d_status = """
4 1 1 4.00000000""",
"array 3d status": """
PARAMETER STATUS- MYARR ( 6 PARAMETERS DEFINED)
(INCLUDING 3 INTERNAL PARAMETERS)
Expand Down Expand Up @@ -76,17 +75,15 @@
3 2 3 3.00000000
1 3 3 0.00000000
2 3 3 0.00000000
3 3 3 0.00000000"""

strarr_status = """PARAMETER STATUS- MYSTR3 ( 12 PARAMETERS DEFINED)
3 3 3 0.00000000""",
"string array status": """PARAMETER STATUS- MYSTR3 ( 12 PARAMETERS DEFINED)
(INCLUDING 3 INTERNAL PARAMETERS)
96 1 1 aqzzzxcv zx zxcv zxcv
96 2 1 qwer wer qwer
96 3 1 zxcv"""

gen_status = """ABBREVIATION STATUS-
96 3 1 zxcv""",
"general status": """ABBREVIATION STATUS-
ABBREV STRING
SAVE_DB SAVE
Expand All @@ -106,7 +103,8 @@
PGFZJK_DIM 20.0000000 SCALAR
PGFZJK_ROWDIM 20.0000000 SCALAR
PORT 50054.0000 SCALAR
STRARRAY STRING ARRAY 96 1 1"""
STRARRAY STRING ARRAY 96 1 1""",
}


@pytest.mark.parametrize(
Expand Down Expand Up @@ -341,12 +339,12 @@ def test_parameter_delete_raise(mapdl, cleared):


@pytest.mark.parametrize(
"status,check",
"status_key,check",
[
(parm_status, 50054),
(arr_status, np.array([1, 2, 3, 4])),
("parameter status", 50054),
("array status", np.array([1, 2, 3, 4])),
(
arr3d_status,
"array 3d status",
np.array(
[
[[1.0, 1.0, 1.0], [0.0, 0.0, 1.0], [0.0, 0.0, 0.0]],
Expand All @@ -355,11 +353,12 @@ def test_parameter_delete_raise(mapdl, cleared):
]
),
),
(strarr_status, ["aqzzzxcv zx zxcv zxcv", "qwer wer qwer", "zxcv"]),
(gen_status, None),
("string array status", ["aqzzzxcv zx zxcv zxcv", "qwer wer qwer", "zxcv"]),
("general status", None),
],
)
def test_interp_star_status(status, check):
def test_interp_star_status(status_key, check):
status = GOLDEN_TESTS[status_key]
output = interp_star_status(status)
if len(output) == 1:
name = list(output.keys())[0]
Expand Down

0 comments on commit 43ed236

Please sign in to comment.