Build an AsyncCodeModeContext with a document snapshot from the kernel. `extra_doc_cells` adds cells to the document that are *not* in the kernel graph, simulating cells that exist on disk but were never run.
(
k: Kernel,
extra_doc_cells: list[NotebookCell] | None = None,
)
| 31 | |
| 32 | @contextmanager |
| 33 | def _ctx( |
| 34 | k: Kernel, |
| 35 | extra_doc_cells: list[NotebookCell] | None = None, |
| 36 | ) -> Generator[AsyncCodeModeContext, None, None]: |
| 37 | """Build an AsyncCodeModeContext with a document snapshot from the kernel. |
| 38 | |
| 39 | `extra_doc_cells` adds cells to the document that are *not* in the |
| 40 | kernel graph, simulating cells that exist on disk but were never run. |
| 41 | """ |
| 42 | cells = [ |
| 43 | NotebookCell(id=cid, code=cell.code, name="", config=cell.config) |
| 44 | for cid, cell in k.graph.cells.items() |
| 45 | ] |
| 46 | if extra_doc_cells: |
| 47 | cells.extend(extra_doc_cells) |
| 48 | doc = NotebookDocument(cells) |
| 49 | with notebook_document_context(doc): |
| 50 | # Staleness check coverage lives in test_staleness.py. |
| 51 | ctx = AsyncCodeModeContext(k, skip_staleness_check=True) |
| 52 | # Use a deterministic seed in tests for snapshot stability. |
| 53 | ctx._id_generator = CellIdGenerator(seed=7) |
| 54 | ctx._id_generator.seen_ids = set(doc.cell_ids) |
| 55 | yield ctx |
| 56 | |
| 57 | |
| 58 | def _tx_ops(k: Kernel) -> list[dict[str, object]]: |
no test coverage detected
searching dependent graphs…