Skip to content

Commit

Permalink
not sure
Browse files Browse the repository at this point in the history
  • Loading branch information
amandarichardsonn committed Mar 13, 2024
1 parent 111da4f commit b052201
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
19 changes: 8 additions & 11 deletions smartsim/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,13 +455,17 @@ def add_exe_args(self, args: t.Union[str, t.List[str]]) -> None:
:type args: str | list[str]
:raises TypeError: if exe args are not strings
"""

if not isinstance(args, (list, str)):
raise TypeError("All elements in the list should be of type str")

if isinstance(args, str):
args = args.split()

for arg in args:
if not isinstance(arg, str):
raise TypeError("Executable arguments should be a list of str")

if isinstance(args, list):
if not all(isinstance(arg, str) for arg in args):
raise TypeError("All elements in the list should be of type str")
self._exe_args.extend(args)

def set(
Expand Down Expand Up @@ -545,13 +549,6 @@ def _build_exe_args(exe_args: t.Optional[t.Union[str, t.List[str]]]) -> t.List[s
if isinstance(exe_args, str):
return exe_args.split()
if isinstance(exe_args, list):
exe_args = copy.deepcopy(exe_args)
nested_type = all(
all(isinstance(arg, (str)) for arg in exe_args_list)
for exe_args_list in exe_args
)
if not nested_type:
raise TypeError("Executable arguments were not list of str or str")
return exe_args
return []

Expand Down
6 changes: 3 additions & 3 deletions tests/test_run_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ def test_add_exe_args_list_of_mixed_lists_init():
"""Ensure that any non-string exe arg fails validation for all"""
exe_args = [["1", "2", 3], ["4", "5", 6]]

with pytest.raises(TypeError) as type_error:
settings = RunSettings("python", exe_args=exe_args)
with pytest.raises(TypeError) as type_error:
_ = RunSettings("python", exe_args=exe_args)

assert "Executable arguments should be a list of str" in type_error.value.args
assert "Executable arguments were not list of str or str." in type_error.value.args


def test_add_exe_args_list_of_str_lists_init():
Expand Down

0 comments on commit b052201

Please sign in to comment.