Skip to content

Commit

Permalink
YAML var files: Convert dicts inside lists to DotDicts
Browse files Browse the repository at this point in the history
Fixes #4418.
  • Loading branch information
pekkaklarck committed Aug 9, 2022
1 parent e9b1aee commit 794ba5d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions atest/robot/variables/yaml_variable_file.robot
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ Non-ASCII strings
Dictionary is dot-accessible
Check Test Case ${TESTNAME}

Nested dictionary is dot-accessible
Check Test Case ${TESTNAME}

Dictionary inside list is dot-accessible
Check Test Case ${TESTNAME}

YAML file in PYTHONPATH
Check Test Case ${TESTNAME}

Expand Down
6 changes: 6 additions & 0 deletions atest/testdata/variables/valid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ dict:
key with spaces: value with spaces
nested dict:
dict: *alias
list with dict:
- scalar
- key: value
- dict: *alias
nested:
- leaf: value
9 changes: 8 additions & 1 deletion atest/testdata/variables/yaml_variable_file.robot
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,17 @@ Non-ASCII strings
Dictionary is dot-accessible
${DICT.a} 1
${DICT.b} ${2}
${NESTED DICT.dict} ${DICT}

Nested dictionary is dot-accessible
${NESTED DICT.dict} ${EXPECTED DICT}
${NESTED DICT.dict.a} 1
${NESTED DICT.dict.b} ${2}

Dictionary inside list is dot-accessible
${LIST WITH DICT[1].key} value
${LIST WITH DICT[2].dict} ${EXPECTED DICT}
${LIST WITH DICT[2].nested[0].leaf} value

YAML file in PYTHONPATH
${YAML FILE IN PYTHONPATH} ${TRUE}

Expand Down
4 changes: 3 additions & 1 deletion src/robot/variables/filesetter.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ def _load_yaml(self, stream):

def _dot_dict(self, value):
if is_dict_like(value):
value = DotDict((n, self._dot_dict(v)) for n, v in value.items())
return DotDict((k, self._dot_dict(v)) for k, v in value.items())
if is_list_like(value):
return [self._dot_dict(v) for v in value]
return value


Expand Down

0 comments on commit 794ba5d

Please sign in to comment.