MCPcopy Create free account
hub / github.com/CoolProp/CoolProp / _parse_block

Function _parse_block

wrappers/Python/pytest/test_doc_examples.py:70–97  ·  view source on GitHub ↗

Pull the Python out of one block's body: keep only prompt lines, strip the ``In [n]:``/``...:`` prefix (preserving the code's own indentation), and drop ``@verbatim`` sub-blocks.

(body)

Source from the content-addressed store, hash-verified

68
69
70def _parse_block(body):
71 """Pull the Python out of one block's body: keep only prompt lines, strip
72 the ``In [n]:``/``...:`` prefix (preserving the code's own indentation),
73 and drop ``@verbatim`` sub-blocks."""
74 out = []
75 skip = False
76 for ln in body:
77 s = ln.strip()
78 if s.startswith("@verbatim"):
79 skip = True
80 continue
81 if s.startswith("@"): # @suppress/@doctest/@savefig markers -> drop the marker
82 continue
83 m = _PROMPT.match(ln)
84 if m is None:
85 # blank line ends a verbatim run; non-prompt text is output/comment
86 if s == "":
87 skip = False
88 continue
89 if skip:
90 continue
91 code = m.group(1)
92 # Drop IPython magics / shell escapes (e.g. ``%run``, ``%timeit``, ``!cmd``);
93 # they are not Python and are not part of the API surface under test.
94 if code.lstrip().startswith(("%", "!")):
95 continue
96 out.append(code)
97 return "\n".join(out)
98
99
100def _doc_pages():

Callers 1

_extract_ipython_codeFunction · 0.85

Calls 2

matchMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected