(readme)
| 121 | # Extract any ``` blocks from the README |
| 122 | # NOTE: This parsing logic is not smart enough to handle multiple separate commands in a single block. |
| 123 | def load_command_blocks_from_readme(readme) -> List[CommandBlock]: |
| 124 | with open(readme, "r") as f: |
| 125 | contents = f.read() |
| 126 | # Check that the README has all the expected sections. |
| 127 | assert "## Introduction" in contents, "All example READMEs should have an 'Introduction' section!" |
| 128 | assert "## Running The Example" in contents, "All example READMEs should have a 'Running The Example' section!" |
| 129 | |
| 130 | cmd_blocks = [] |
| 131 | with MarkerTracker(readme) as tracker: |
| 132 | for line in tracker: |
| 133 | if tracker.is_in(VALID_MARKERS["ignore"]): |
| 134 | continue |
| 135 | |
| 136 | if tracker.entering(VALID_MARKERS["command"]): |
| 137 | current_block = CommandBlock(xfail=tracker.is_in(VALID_MARKERS["xfail"])) |
| 138 | elif tracker.exiting(VALID_MARKERS["command"]): |
| 139 | cmd_blocks.append(copy.copy(current_block)) |
| 140 | elif tracker.is_in(VALID_MARKERS["command"]): |
| 141 | current_block.add(line) |
| 142 | |
| 143 | return cmd_blocks |
| 144 | |
| 145 | |
| 146 | class Example: |
no test coverage detected