Whole file
nschloe/pytest-codeblocks
The author described this change as “fix for indented blocks”. It counts as a record because the check below fails on the code as it stood at c476f3090 and passes on db2835e4c, with nothing else changed between the two runs.
Projectnschloe/pytest-codeblocks
Fix saved2020-10-10
Sharing licenceMIT · LICENSE.txt
Change size+8 −3
What the code was meant to do, written into the code itself as a save note
fix for indented blocks
The change
| 15 | 15 | # EOF | |
| 16 | 16 | break | |
| 17 | 17 | ||
| 18 | - | if line.strip()[:3] == "```": | |
| 19 | - | syntax = line.strip()[3:] | |
| 18 | + | if line.lstrip()[:3] == "```": | |
| 19 | + | syntax = line.lstrip()[3:] | |
| 20 | + | num_leading_spaces = len(line) - len(line.lstrip()) | |
| 20 | 21 | lineno = k - 1 | |
| 21 | 22 | # read the block | |
| 22 | 23 | code_block = [] | |
| ⋯ | |||
| 29 | 30 | raise RuntimeError( | |
| 30 | 31 | f"File too large (> {max_num_lines} lines). Set max_num_lines." | |
| 31 | 32 | ) | |
| 32 | - | if line.strip()[:3] == "```": | |
| 33 | + | # check if end of block | |
| 34 | + | if line.lstrip()[:3] == "```": | |
| 33 | 35 | break | |
| 36 | + | # Cut (at most) num_leading_spaces leading spaces | |
| 37 | + | nls = min(num_leading_spaces, len(line) - len(line.lstrip())) | |
| 38 | + | line = line[nls:] | |
| 34 | 39 | code_block.append(line) | |
| 35 | 40 | ||
| 36 | 41 | if syntax_filter and syntax_filter.strip() != syntax.strip(): | |
The check that tells the two apart
fail→pass·test/test_exdown.py::test_reference
Check file test/test_exdown.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before itc476f3090b33ed642cc1aaf320148170f377cdfd
Broken version dated2020-10-10
Moduleexdown.main
Units changedfrom_buffer
Fingerprint01c1bdbda3a59a1a
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in nschloe/pytest-codeblocks
- 2021-05-10fix for expected code block
- 2021-02-17fix for markdown starting with code block