MCPcopy
hub / github.com/sphinx-doc/sphinx / add_code

Method add_code

sphinx/ext/doctest.py:207–226  ·  view source on GitHub ↗
(self, code: TestCode, prepend: bool = False)

Source from the content-addressed store, hash-verified

205 self.cleanup: list[TestCode] = []
206
207 def add_code(self, code: TestCode, prepend: bool = False) -> None:
208 if code.type == 'testsetup':
209 if prepend:
210 self.setup.insert(0, code)
211 else:
212 self.setup.append(code)
213 elif code.type == 'testcleanup':
214 self.cleanup.append(code)
215 elif code.type == 'doctest':
216 self.tests.append([code])
217 elif code.type == 'testcode':
218 # "testoutput" may replace the second element
219 self.tests.append((code, None))
220 elif code.type == 'testoutput':
221 if self.tests:
222 latest_test = self.tests[-1]
223 if len(latest_test) == 2:
224 self.tests[-1] = [latest_test[0], code]
225 else:
226 raise RuntimeError(__('invalid TestCode type'))
227
228 def __repr__(self) -> str:
229 return (

Callers 1

test_docMethod · 0.80

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected