|
76 | 76 | " fm = nb_frontmatter(nb)\n", |
77 | 77 | " if str2bool(fm.get('skip_exec', False)) or nb_lang(nb) != 'python': return True, 0\n", |
78 | 78 | "\n", |
| 79 | + " dflt = fm_default_eval(fm)\n", |
79 | 80 | " def _no_eval(cell):\n", |
80 | 81 | " if cell.cell_type != 'code': return True\n", |
81 | | - " if 'nbdev_export'+'(' in cell.source: return True\n", |
82 | | - " direc = getattr(cell, 'directives_', {}) or {}\n", |
83 | | - " if direc.get('eval', '').lower() == 'false': return True\n", |
84 | | - " return flags & direc.keys()\n", |
| 82 | + " if not does_cell_eval(cell, dflt): return True\n", |
| 83 | + " return flags & (getattr(cell, 'directives_', {}) or {}).keys()\n", |
85 | 84 | "\n", |
86 | 85 | " start = time.time()\n", |
87 | 86 | " if profile is None: profile = bool(get_config(fn.parent).exec_profile)\n", |
|
314 | 313 | "id": "8ee3f4db", |
315 | 314 | "metadata": {}, |
316 | 315 | "source": [ |
317 | | - "## Eval -" |
| 316 | + "## Eval" |
| 317 | + ] |
| 318 | + }, |
| 319 | + { |
| 320 | + "cell_type": "markdown", |
| 321 | + "id": "0317b83e", |
| 322 | + "metadata": {}, |
| 323 | + "source": [ |
| 324 | + "`test_nb` decides which cells run through the `eval` cascade (`fastcore.nbio.does_cell_eval`): a cell's own `#| eval:` directive wins; otherwise the notebook-level `eval` directive — in frontmatter, or the notebook's `metadata.nbdev` mapping — sets the default; with neither, cells run. `#| eval: false` therefore skips one cell, as it always has, while a notebook-level `eval: false` flips the whole notebook to opt-in: only cells marked `#| eval: true` run, which suits a slow or service-dependent notebook where just a few cells are worth testing. Unlike `skip_exec: true`, which skips a notebook unconditionally, marked cells still run — here the unmarked cell would raise if executed, so the passing test is the proof it was skipped:" |
| 325 | + ] |
| 326 | + }, |
| 327 | + { |
| 328 | + "cell_type": "code", |
| 329 | + "execution_count": null, |
| 330 | + "id": "2c358146", |
| 331 | + "metadata": {}, |
| 332 | + "outputs": [], |
| 333 | + "source": [ |
| 334 | + "with tempfile.TemporaryDirectory() as td:\n", |
| 335 | + " cells = [mk_cell('---\\neval: false\\n---', 'raw'), mk_cell('raise Exception(\"unmarked: must not run\")'),\n", |
| 336 | + " mk_cell('#| eval: true\\nx = 1')]\n", |
| 337 | + " fn = Path(td)/'optin.ipynb'\n", |
| 338 | + " write_nb(new_nb(cells), fn)\n", |
| 339 | + " success,_ = await test_nb(fn)\n", |
| 340 | + "assert success" |
318 | 341 | ] |
319 | 342 | }, |
320 | 343 | { |
|
0 commit comments