Skip to content

Commit 635eaff

Browse files
authoredMay 17, 2023
allow for data anchor to be found in list (#133)
1 parent dc5fb16 commit 635eaff

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
 

‎src/dvc_render/vega_templates.py

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ def dict_find_value(d: dict, value: str) -> bool:
6969
if isinstance(v, str):
7070
if v == value:
7171
return True
72+
if isinstance(v, list):
73+
return any(dict_find_value(e, value) for e in v)
7274
return False
7375

7476

‎tests/test_templates.py

+13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
Template,
1111
TemplateContentDoesNotMatch,
1212
TemplateNotFoundError,
13+
dict_find_value,
1314
dump_templates,
1415
get_template,
1516
)
@@ -101,3 +102,15 @@ def test_raise_on_init_modified(tmp_dir):
101102
def test_escape_special_characters():
102103
value = "foo.bar[2]"
103104
assert Template.escape_special_characters(value) == "foo\\.bar\\[2\\]"
105+
106+
107+
@pytest.mark.parametrize(
108+
"content_dict, value_name",
109+
[
110+
({"key": "value"}, "value"),
111+
({"key": {"subkey": "value"}}, "value"),
112+
({"key": [{"subkey": "value"}]}, "value"),
113+
],
114+
)
115+
def test_dict_find_value(content_dict, value_name):
116+
assert dict_find_value(content_dict, value_name)

0 commit comments

Comments
 (0)