MCPcopy Create free account
hub / github.com/ModalityDance/Omni-R1 / keep_doc_examples_only

Function keep_doc_examples_only

src/transformers/utils/tests_fetcher.py:157–181  ·  view source on GitHub ↗

Remove everything from the code content except the doc examples (used to determined if a diff should trigger doc tests or not). Args: content (`str`): The code to clean Returns: `str`: The cleaned code.

(content: str)

Source from the content-addressed store, hash-verified

155
156
157def keep_doc_examples_only(content: str) -> str:
158 """
159 Remove everything from the code content except the doc examples (used to determined if a diff should trigger doc
160 tests or not).
161
162 Args:
163 content (`str`): The code to clean
164
165 Returns:
166 `str`: The cleaned code.
167 """
168 # Keep doc examples only by splitting on triple "`"
169 splits = content.split("```")
170 # Add leading and trailing "```" so the navigation is easier when compared to the original input `content`
171 content = "```" + "```".join(splits[1::2]) + "```"
172
173 # Remove empty lines and comments
174 lines_to_keep = []
175 for line in content.split("\n"):
176 # remove anything that is after a # sign.
177 line = re.sub("#.*$", "", line)
178 # remove white lines
179 if len(line) != 0 and not line.isspace():
180 lines_to_keep.append(line)
181 return "\n".join(lines_to_keep)
182
183
184def get_all_tests() -> List[str]:

Callers 1

Calls 1

splitMethod · 0.80

Tested by

no test coverage detected