INNER CODE UNIT · Python
resources_elem
connectbot/connectbot · translations/test_translate.py:53
def resources_elem(inner: str) -> etree._Element:
"""Parses a <resources> element with comments preserved, without XML declaration."""
xml = f'<resources xmlns:tools="http://schemas.android.com/tools">\n{inner}\n</resources>'
return parse(xml)
# ---------------------------------------------------------------------------
# preceding_comment
# ---------------------------------------------------------------------------
class TestPrecedingComment:
def test_picks_up_comment_before_element(self):
root = resources_elem('<!-- Window title -->\n<string name="title">Hello</string>')
elem = root.find("string")
assert preceding_comment(elem) == "Window title"
def test_returns_empty_when_no_comment(self):
root = resources_elem('<string name="title">Hello</string>')