1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""The README's own code blocks, executed.
`python/README.md` is what PyPI serves as this package's description, and it was a **verbatim copy
of the Rust README** -- `cargo add ferrotherm` and Rust code, shown to people who ran `pip install`.
It also still carried the uncompilable `joules` snippet that the Rust README had already been fixed
for, because the fix was applied in one place and the copy was forgotten.
A README nothing executes is a README that drifts. This runs every ```python block in it, so the
quickstart is checked the way `#[cfg(doctest)]` checks the Rust one.
Writing it caught two more: `magnetization` is a property and the draft called it as a method, and
`ledger()` does not exist -- the accessors are `node_updates` and `joules`.
"""
=
return
# A floor. If the fences are renamed or the file is replaced, the test below would silently
# iterate over nothing and pass -- which is the shape this repository keeps finding.
=
assert >= 3, f
"""Each block executes standalone, and any value it claims in a comment is a value it prints.
Running the blocks is only half of it. A block that runs while printing something other than the
number written beside it is still a lie, and the first version of this test could not see that:
it checked the Onsager figures against HARDCODED constants rather than against the README, so
editing the README could not fail it. Verified by reverting the README to the 16x16/500-sweep
parameters and watching it stay green.
So the claims are read out of the file. A trailing `# 0.9736` on a print line is a promise about
that line's output, and this holds the file to it.
"""
=
: =
=
=
# Matched PER LINE, not against the whole buffer.
#
# Searching all of stdout for the claimed token is not the same question, and it hid the exact
# defect this test exists for: block 3 prints |M| then Onsager, and when |M| drifted to 0.8984
# the claim `# 0.9736` on its line was still "found" -- in the NEXT line's output. A check that
# any line printed the number is not a check that the right line did.
#
# The nth print in the source produces the nth line of output, so they pair by position.
=
= 0
continue
=
+= 1
continue
=
assert in ,
"""A floor: if no block claims a number, the check above passes over nothing."""
= 0
+=
assert >= 2, f