Notebook-Tests: nbmake + Subprocess-Zellen + inkrementeller Test

Alle 25 Notebooks sind nun fehlerfrei testbar (25 passed). Dafür drei
Änderungen im Build und eine neue Test-Infrastruktur:

1. pyproject.toml: nbmake>=1.5 in der dev-Gruppe.

2. build_version_04.py: Notebooks bekommen zwei Setup-Zellen und
   Subprocess-Zellen für Programme, die nicht direkt im Kernel laufen:
   - NOTEBOOK_SETUP_2: __file__ definieren, sys.path für or_kern,
     multiprocessing auf fork (Spawn findet Kernel-Funktionen nicht).
   - _braucht_subprocess: erkennt highspy (Solver-Konflikt), pytest
     (SystemExit), get_context('spawn'), subprocess+__file__ (sucht
     .py-Dateien), sys.exit (SystemExit). Diese Programme erscheinen
     als Markdown-Codeblock (sichtbar, nicht ausführbar) plus einer
     Subprocess-Zelle mit NO_COLOR=1 (verhindert ANSI-Codes, die der
     Parser von Mutationstest.py nicht verarbeitet).
   - Solver-Konflikt-Erkennung: wenn ein Kapitel sowohl ortools als
     auch highspy importiert, laufen auch reine ortools-Programme als
     Subprocess (highspy schon im Kernel).

3. teste_code_04.py: inkrementeller Test — nur geänderte/neue Programme
   und Notebooks (via git status). Netzabhängige Dateien (yfinance)
   werden automatisch erkannt und nur getestet, wenn Internet verfügbar.

4. PLAN.md Abschnitt 10: neuer Verifikationsschritt 4 (pytest --nbmake).
   PROGRESS.md und CLAUDE.md aktualisiert.

Gefundene und behobene Probleme:
- or_kern-Import: sys.path im Notebook erweitert.
- __file__ nicht definiert: zweite Setup-Zelle setzt es.
- multiprocessing spawn: fork erzwungen (Ein_System_Vier_Ansaetze.py).
- ortools/highspy-Konflikt: Subprocess für beide Solver.
- pytest SystemExit: Subprocess für test_or_kern.py und Mutationstest.py.
- sys.exit(0): Subprocess für Installationstest.py.
- ANSI-Codes in pytest-Ausgabe: NO_COLOR=1 in Subprocess-Zelle.
This commit is contained in:
dschlueter 2026-09-11 22:38:59 +02:00
commit a4fc247116
70 changed files with 4073 additions and 305 deletions

View file

@ -12,7 +12,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": [
"nbmake-skip"
]
},
"outputs": [],
"source": [
"# Einmalig ausfuehren: installiert alle im Buch verwendeten Pakete.\n",
@ -21,6 +25,36 @@
" scikit-learn matplotlib plotly pyomo linopy pymoo pydantic openpyxl"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Notebook-spezifisches Setup: __file__ definieren (Programme nutzen es\n",
"# fuer OUTPUT_DIR), Programmverzeichnis in den Suchpfad aufnehmen (or_kern)\n",
"# und multiprocessing auf 'fork' stellen (Spawn findet Kernel-Funktionen nicht).\n",
"import os, sys\n",
"__file__ = os.path.join(os.getcwd(), '_notebook.py')\n",
"for _p in [os.path.join(os.path.dirname(os.getcwd()),\n",
" 'Operations_Research_mit_Python_Version_04_Programme'),\n",
" os.path.dirname(os.getcwd()), os.getcwd()]:\n",
" if os.path.isfile(os.path.join(_p, 'or_kern.py')):\n",
" sys.path.insert(0, _p); break\n",
"import multiprocessing as _mp\n",
"try: _mp.set_start_method('fork', force=True)\n",
"except (RuntimeError, ValueError): pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Der Fluch des Durchschnitts\n",
"\n",
"`Fluch_des_Durchschnitts.py`\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
@ -100,6 +134,15 @@
"`Monte_Carlo.py`\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Monte-Carlo-Simulation{idx:Monte-Carlo-Simulation}\n",
"\n",
"`Monte_Carlo.py`\n"
]
},
{
"cell_type": "code",
"execution_count": null,
@ -209,6 +252,15 @@
"`Stochastische_Optimierung.py`\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Zweistufige stochastische Programmierung\n",
"\n",
"`Stochastische_Optimierung.py`\n"
]
},
{
"cell_type": "code",
"execution_count": null,
@ -345,6 +397,15 @@
"`Robuste_Optimierung.py`\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Robuste Optimierung{idx:Robuste Optimierung}: gegen den Worst Case absichern\n",
"\n",
"`Robuste_Optimierung.py`\n"
]
},
{
"cell_type": "code",
"execution_count": null,
@ -461,6 +522,15 @@
"`Chance_Constraints.py`\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Der Fall: ein Kraftwerkspark mit 500 MW Zusage\n",
"\n",
"`Chance_Constraints.py`\n"
]
},
{
"cell_type": "code",
"execution_count": null,