Skip to content

Commit

Permalink
allow for data anchor to be found in list (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
dberenbaum committed May 17, 2023
1 parent dc5fb16 commit 635eaff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/dvc_render/vega_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def dict_find_value(d: dict, value: str) -> bool:
if isinstance(v, str):
if v == value:
return True
if isinstance(v, list):
return any(dict_find_value(e, value) for e in v)
return False


Expand Down
13 changes: 13 additions & 0 deletions tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Template,
TemplateContentDoesNotMatch,
TemplateNotFoundError,
dict_find_value,
dump_templates,
get_template,
)
Expand Down Expand Up @@ -101,3 +102,15 @@ def test_raise_on_init_modified(tmp_dir):
def test_escape_special_characters():
value = "foo.bar[2]"
assert Template.escape_special_characters(value) == "foo\\.bar\\[2\\]"


@pytest.mark.parametrize(
"content_dict, value_name",
[
({"key": "value"}, "value"),
({"key": {"subkey": "value"}}, "value"),
({"key": [{"subkey": "value"}]}, "value"),
],
)
def test_dict_find_value(content_dict, value_name):
assert dict_find_value(content_dict, value_name)

0 comments on commit 635eaff

Please sign in to comment.