mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-13 13:17:52 +02:00
docs: process cell magics (#4462)
Handle a small thing that can be fairly confusing to new python users. Before:  After: 
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
import nbformat
|
||||
import pytest
|
||||
|
||||
from _scripts.notebook_convert import (
|
||||
_convert_links_in_markdown,
|
||||
_has_output,
|
||||
convert_notebook,
|
||||
)
|
||||
|
||||
|
||||
@@ -32,3 +37,41 @@ def test_has_output() -> None:
|
||||
def test_link_conversion(source: str, expected: str) -> None:
|
||||
"""Test logic to convert links in markdown cells."""
|
||||
assert _convert_links_in_markdown(source) == expected
|
||||
|
||||
|
||||
EXPECTED_OUTPUT = """\
|
||||
```shell
|
||||
pip install -U langgraph
|
||||
```
|
||||
|
||||
|
||||
```python
|
||||
print('Hello')
|
||||
```\
|
||||
|
||||
"""
|
||||
|
||||
|
||||
def test_converting_cell_magic() -> None:
|
||||
"""Test converting cell magic to code blocks."""
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
nb_path = os.path.join(tmpdir, "test_notebook.ipynb")
|
||||
|
||||
# Create a minimal notebook object
|
||||
nb = nbformat.v4.new_notebook()
|
||||
nb.cells = [
|
||||
nbformat.v4.new_code_cell(
|
||||
"%%capture --no-stderr\n"
|
||||
"%pip install -U langgraph"
|
||||
),
|
||||
nbformat.v4.new_code_cell("print('Hello')"),
|
||||
]
|
||||
nb.metadata["language_info"] = {"name": "python"}
|
||||
|
||||
# Write to file
|
||||
with open(nb_path, "w", encoding="utf-8") as f:
|
||||
nbformat.write(nb, f)
|
||||
|
||||
# Run the conversion
|
||||
converted = convert_notebook(nb_path)
|
||||
assert converted == EXPECTED_OUTPUT
|
||||
|
||||
Reference in New Issue
Block a user