MCPcopy
hub / github.com/pytest-dev/pytest / DomDocument

Class DomDocument

testing/test_junitxml.py:87–128  ·  testing/test_junitxml.py::DomDocument

Source from the content-addressed store, hash-verified

85
86
87class DomDocument:
88 _node: minidom.Document | minidom.Element
89
90 def __init__(self, dom: minidom.Document) -> None:
91 self._node = dom
92
93 def find_first_by_tag(self, tag: str) -> DomNode | None:
94 return self.find_nth_by_tag(tag, 0)
95
96 def get_first_by_tag(self, tag: str) -> DomNode:
97 maybe = self.find_first_by_tag(tag)
98 if maybe is None:
99 raise LookupError(tag)
100 else:
101 return maybe
102
103 def find_nth_by_tag(self, tag: str, n: int) -> DomNode | None:
104 items = self._node.getElementsByTagName(tag)
105 try:
106 nth = items[n]
107 except IndexError:
108 return None
109 else:
110 return DomNode(nth)
111
112 def find_by_tag(self, tag: str) -> list[DomNode]:
113 return [DomNode(x) for x in self._node.getElementsByTagName(tag)]
114
115 @property
116 def children(self) -> list[DomNode]:
117 return [
118 DomNode(x) for x in self._node.childNodes if isinstance(x, minidom.Element)
119 ]
120
121 @property
122 def get_unique_child(self) -> DomNode:
123 children = self.children
124 assert len(children) == 1
125 return children[0]
126
127 def toxml(self) -> str:
128 return self._node.toxml()
129
130
131class DomNode(DomDocument):

Callers 2

__call__Method · 0.85
documentMethod · 0.85

Calls

no outgoing calls

Tested by 2

__call__Method · 0.68
documentMethod · 0.68