Skip to content

Commit ca0f125

Browse files
committed
add final test
1 parent 51bc953 commit ca0f125

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/idom/utils.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,13 @@ def _etree_to_vdom(
190190
return vdom
191191

192192

193-
def _add_vdom_to_etree(parent: etree._Element, vdom: VdomDict) -> None:
193+
def _add_vdom_to_etree(parent: etree._Element, vdom: VdomDict | dict[str, Any]) -> None:
194194
try:
195195
tag = vdom["tagName"]
196-
except TypeError as e:
197-
raise TypeError(f"Expected a VdomDict, not {vdom}") from e
198196
except KeyError as e:
199-
raise TypeError(f"Expected a VdomDict, not {vdom}") from e
197+
raise TypeError(f"Expected a VDOM dict, not {vdom}") from e
198+
else:
199+
vdom = cast(VdomDict, vdom)
200200

201201
if tag:
202202
element = etree.SubElement(parent, tag)
@@ -208,7 +208,7 @@ def _add_vdom_to_etree(parent: etree._Element, vdom: VdomDict) -> None:
208208

209209
for c in vdom.get("children", []):
210210
if isinstance(c, dict):
211-
_add_vdom_to_etree(element, cast(VdomDict, c))
211+
_add_vdom_to_etree(element, c)
212212
elif len(element):
213213
last_child = element[-1]
214214
last_child.tail = f"{last_child.tail or ''}{c}"

tests/test_utils.py

+5
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,8 @@ def test_html_to_vdom_with_no_parent_node():
225225
)
226226
def test_vdom_to_html(vdom_in, html_out):
227227
assert vdom_to_html(vdom_in) == html_out
228+
229+
230+
def test_vdom_to_html_error():
231+
with pytest.raises(TypeError, match="Expected a VDOM dict"):
232+
vdom_to_html({"notVdom": True})

0 commit comments

Comments
 (0)