Skip to content

Commit

Permalink
add final test
Browse files Browse the repository at this point in the history
  • Loading branch information
rmorshea committed Nov 22, 2022
1 parent 51bc953 commit ca0f125
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/idom/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,13 @@ def _etree_to_vdom(
return vdom


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

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

for c in vdom.get("children", []):
if isinstance(c, dict):
_add_vdom_to_etree(element, cast(VdomDict, c))
_add_vdom_to_etree(element, c)
elif len(element):
last_child = element[-1]
last_child.tail = f"{last_child.tail or ''}{c}"
Expand Down
5 changes: 5 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,8 @@ def test_html_to_vdom_with_no_parent_node():
)
def test_vdom_to_html(vdom_in, html_out):
assert vdom_to_html(vdom_in) == html_out


def test_vdom_to_html_error():
with pytest.raises(TypeError, match="Expected a VDOM dict"):
vdom_to_html({"notVdom": True})

0 comments on commit ca0f125

Please sign in to comment.