"""
Tests stringify functions used in xmodule html
"""
from lxml import etree
from xmodule.stringify import stringify_children
def test_stringify():
"""Test that `stringify_children` correctly concatenates text and child elements."""
text = 'Hi
there Bruce!
'
html = f"""{text}"""
xml = etree.fromstring(html)
out = stringify_children(xml)
assert out == text
def test_stringify_again():
"""Test that `stringify_children` handles complex HTML without duplicating content."""
html = r"""A voltage source is non-linear!

\(V=V_C\)
But it is affine,
which means linear except for an offset.
"""
html = """A voltage source is non-linear!
But it is affine,
which means linear except for an offset.
"""
xml = etree.fromstring(html)
out = stringify_children(xml)
print("output:")
print(out)
# Tracking strange content repeating bug
# Should appear once
assert out.count("But it is ") == 1