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)
| 136 | |
| 137 | |
| 138 | def keep_doc_examples_only(content: str) -> str: |
| 139 | """ |
| 140 | Remove everything from the code content except the doc examples (used to determined if a diff should trigger doc |
| 141 | tests or not). |
| 142 | |
| 143 | Args: |
| 144 | content (`str`): The code to clean |
| 145 | |
| 146 | Returns: |
| 147 | `str`: The cleaned code. |
| 148 | """ |
| 149 | # Keep doc examples only by splitting on triple "`" |
| 150 | splits = content.split("```") |
| 151 | # Add leading and trailing "```" so the navigation is easier when compared to the original input `content` |
| 152 | content = "```" + "```".join(splits[1::2]) + "```" |
| 153 | |
| 154 | # Remove empty lines and comments |
| 155 | lines_to_keep = [] |
| 156 | for line in content.split("\n"): |
| 157 | # remove anything that is after a # sign. |
| 158 | line = re.sub("#.*$", "", line) |
| 159 | # remove white lines |
| 160 | if len(line) != 0 and not line.isspace(): |
| 161 | lines_to_keep.append(line) |
| 162 | return "\n".join(lines_to_keep) |
| 163 | |
| 164 | |
| 165 | def get_all_tests() -> List[str]: |
no test coverage detected
searching dependent graphs…