Skip to content

Commit dc875f8

Browse files
add extra coverage for junit test helpers
1 parent 9cad2d7 commit dc875f8

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

testing/test_junitxml.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,48 @@ def next_sibling(self) -> DomNode:
150150
return DomNode(self._node.nextSibling)
151151

152152

153+
class TestJunitHelpers:
154+
"""minimal test to increase coverage for methods that are used in debugging"""
155+
156+
@pytest.fixture
157+
def document(self) -> DomDocument:
158+
doc = minidom.parseString("""
159+
<root>
160+
<item name="a"></item>
161+
<item name="b"></item>
162+
</root>
163+
""")
164+
return DomDocument(doc)
165+
166+
def test_uc_root(self, document: DomDocument) -> None:
167+
assert document.get_unique_child.tag == "root"
168+
169+
def test_node_assert_attr(self, document: DomDocument) -> None:
170+
item = document.get_first_by_tag("item")
171+
172+
item.assert_attr(name="a")
173+
174+
with pytest.raises(AssertionError):
175+
item.assert_attr(missing="foo")
176+
177+
def test_node_getitem(self, document: DomDocument) -> None:
178+
item = document.get_first_by_tag("item")
179+
assert item["name"] == "a"
180+
181+
with pytest.raises(KeyError, match="missing"):
182+
item["missing"]
183+
184+
def test_node_get_first_lookup(self, document: DomDocument) -> None:
185+
with pytest.raises(LookupError, match="missing"):
186+
document.get_first_by_tag("missing")
187+
188+
def test_node_repr(self, document: DomDocument) -> None:
189+
item = document.get_first_by_tag("item")
190+
191+
assert repr(item) == item.toxml()
192+
assert item.toxml() == '<item name="a"/>'
193+
194+
153195
parametrize_families = pytest.mark.parametrize("xunit_family", ["xunit1", "xunit2"])
154196

155197

0 commit comments

Comments
 (0)