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)
| 155 | |
| 156 | |
| 157 | def 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 | |
| 184 | def get_all_tests() -> List[str]: |
no test coverage detected