Skip to content

Commit 15ba6e8

Browse files
committed
add more tests and raise exception if double quotes in args
1 parent ed1b169 commit 15ba6e8

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/ansys/mechanical/core/run.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ def _cli_impl(
115115
if not input_script and script_args:
116116
raise Exception("Cannot add script arguments without an input script.")
117117

118+
if script_args:
119+
if '"' in script_args:
120+
raise Exception("Cannot have double quotes in the arguments.")
121+
118122
# If the input_script and port are missing in batch mode, raise an exception
119123
if (not graphical) and (input_script is None) and (not port):
120124
raise Exception("An input script, -i, or port, --port, are required in batch mode.")
@@ -148,10 +152,7 @@ def _cli_impl(
148152

149153
if script_args:
150154
args.append("-ScriptArgs")
151-
if '"' in script_args:
152-
args.append(f"'{script_args}'")
153-
else:
154-
args.append(f'"{script_args}"')
155+
args.append(f'"{script_args}"')
155156

156157
if (not graphical) and input_script:
157158
exit = True

tests/test_cli.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,33 @@ def test_cli_scriptargs(disable_cli):
127127
assert "foo.py" in args
128128

129129

130+
@pytest.mark.cli
131+
def test_cli_scriptargs_singlequote(disable_cli):
132+
args, _ = _cli_impl(
133+
exe="AnsysWBU.exe",
134+
version=241,
135+
input_script="foo.py",
136+
script_args="arg1,arg2,'arg3'",
137+
graphical=True,
138+
)
139+
assert "-ScriptArgs" in args
140+
assert "\"arg1,arg2,'arg3'\"" in args
141+
assert "-script" in args
142+
assert "foo.py" in args
143+
144+
145+
@pytest.mark.cli
146+
def test_cli_scriptargs_doublequote(disable_cli):
147+
with pytest.raises(Exception):
148+
_cli_impl(
149+
exe="AnsysWBU.exe",
150+
version=241,
151+
input_script="foo.py",
152+
script_args='arg1,"arg2",arg3',
153+
graphical=True,
154+
)
155+
156+
130157
@pytest.mark.cli
131158
def test_cli_features(disable_cli):
132159
with pytest.warns(UserWarning):

0 commit comments

Comments
 (0)