Skip to content

Commit 0a85e3d

Browse files
committed
fix(config): correct handling of string expression at building the command line in config model
1 parent 40f0460 commit 0a85e3d

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

packages/core/src/robotcode/core/utils/dataclasses.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def __from_dict_handle_basic_types(value: Any, t: Type[Any], strict: bool) -> Tu
314314

315315

316316
def __from_dict_handle_sequence(value: Any, t: Type[Any], strict: bool) -> Tuple[Any, bool]:
317-
if isinstance(value, Sequence):
317+
if isinstance(value, Sequence) and not isinstance(value, str):
318318
args = _get_args_cached(t)
319319
return (_get_origin_cached(t) or t)(from_dict(v, args, strict=strict) for v in value), True
320320
return None, False
@@ -471,7 +471,7 @@ def from_dict(
471471
try:
472472
return match_(**params)
473473
except TypeError as ex:
474-
raise TypeError(f"Can't initialize class {match_!r} with parameters {params!r}: {ex}") from ex
474+
raise TypeError(f"Can't initialize {match_!r} with parameters {params!r}: {ex}") from ex
475475

476476
raise TypeError(
477477
"Value must be of type `"

packages/robot/src/robotcode/robot/config/model.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,9 @@ def append_name(field: "dataclasses.Field[Any]", add_flag: Optional[str] = None)
291291
for key, item in value.items():
292292
append_name(field)
293293
if isinstance(item, list):
294-
separator = ";" if any(True for s in item if ":" in s) else ":"
295-
result.append(f"{key}{separator if item else ''}{separator.join(item)}")
294+
str_item = [str(i) for i in item]
295+
separator = ";" if any(True for s in str_item if ":" in s) else ":"
296+
result.append(f"{key}{separator if item else ''}{separator.join(str_item)}")
296297
else:
297298
result.append(f"{key}:{item}")
298299
else:

tests/robotcode/robot/config/test_profile.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,29 @@ def test_set_and_evaluates_environment_var_correctly_with_vars_overridden_in_pro
349349
assert evaluated.variables
350350
assert evaluated.variables["TEST_VAR"] == "test overridden"
351351
assert evaluated.variables["TEST_VAR_CALCULATED"] == "9"
352+
353+
354+
def test_str_expression_works_correctly_in_lists_in_build_command_line() -> None:
355+
data = """\
356+
[listeners]
357+
dummy_listener = [
358+
{ expr = "'dummy' + '/output'" },
359+
]
360+
listener_with_colon = ["dummy:output"]
361+
"""
362+
config = load_robot_config_from_robot_toml_str(data)
363+
evaluated = config.combine_profiles().evaluated_with_env()
364+
cmd_line = evaluated.build_command_line()
365+
366+
assert cmd_line
367+
assert cmd_line == ["--listener", "dummy_listener:dummy/output", "--listener", "listener_with_colon;dummy:output"]
368+
369+
370+
def test_type_that_wants_alist_should_throw_an_error() -> None:
371+
372+
data = """\
373+
[listeners]
374+
listener_with_colon = "dummy:output"
375+
"""
376+
with pytest.raises(TypeError, match=".*Value must be of type.*"):
377+
load_robot_config_from_robot_toml_str(data)

0 commit comments

Comments
 (0)