|
a |
|
b/docs/utilities/tests/blocs.md |
|
|
1 |
# Testing Code Blocs |
|
|
2 |
|
|
|
3 |
We created a utility that scans through the documentation, extracts code blocs and executes them to check that everything is indeed functional. |
|
|
4 |
|
|
|
5 |
There is more! Whenever the utility comes across an example (denoted by `# Out: `, see example below), an `assert` statement is dynamically added to the snippet to check that the output matches. |
|
|
6 |
|
|
|
7 |
For instance: |
|
|
8 |
|
|
|
9 |
```python |
|
|
10 |
a = 1 |
|
|
11 |
|
|
|
12 |
a |
|
|
13 |
# Out: 1 |
|
|
14 |
``` |
|
|
15 |
|
|
|
16 |
Is transformed into: |
|
|
17 |
|
|
|
18 |
```python |
|
|
19 |
a = 1 |
|
|
20 |
|
|
|
21 |
v = a |
|
|
22 |
assert repr(v) == "1" |
|
|
23 |
``` |
|
|
24 |
|
|
|
25 |
We can disable code checking for a specific code bloc by adding a `.no-check` class to the code bloc: |
|
|
26 |
|
|
|
27 |
````md |
|
|
28 |
```python { .no-check } |
|
|
29 |
test = undeclared_function(42) |
|
|
30 |
``` |
|
|
31 |
```` |
|
|
32 |
|
|
|
33 |
Visit the source code of [test_docs.py](https://github.com/aphp/edsnlp/blob/master/tests/test_docs.py) for more information. |