Skip to content

Commit f5de7c1

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

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

testing/test_junitxml.py

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,47 @@ def text(self) -> str:
145145
def tag(self) -> str:
146146
return self._node.tagName
147147

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

152190

153191
parametrize_families = pytest.mark.parametrize("xunit_family", ["xunit1", "xunit2"])

0 commit comments

Comments
 (0)