mirror of
https://github.com/microsoft/autogen.git
synced 2026-04-20 03:02:16 -04:00
Add quick start and utils for extracting code blocks (#404)
* Add quick start and utils for extracting code blocks * format * Spelling
This commit is contained in:
37
python/tests/execution/test_extract_code_blocks.py
Normal file
37
python/tests/execution/test_extract_code_blocks.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from agnext.components.code_executor import extract_markdown_code_blocks
|
||||
|
||||
|
||||
def test_extract_markdown_code_blocks() -> None:
|
||||
|
||||
text = """# This is a markdown text
|
||||
```python
|
||||
print("Hello World")
|
||||
```
|
||||
"""
|
||||
|
||||
code_blocks = extract_markdown_code_blocks(text)
|
||||
|
||||
assert len(code_blocks) == 1
|
||||
assert code_blocks[0].language == "python"
|
||||
assert code_blocks[0].code == 'print("Hello World")\n'
|
||||
|
||||
|
||||
text = """More markdown text
|
||||
```python
|
||||
print("Hello World")
|
||||
```
|
||||
|
||||
Another code block.
|
||||
|
||||
```python
|
||||
print("Hello World 2")
|
||||
```
|
||||
"""
|
||||
|
||||
code_blocks = extract_markdown_code_blocks(text)
|
||||
|
||||
assert len(code_blocks) == 2
|
||||
assert code_blocks[0].language == "python"
|
||||
assert code_blocks[0].code == 'print("Hello World")\n'
|
||||
assert code_blocks[1].language == "python"
|
||||
assert code_blocks[1].code == 'print("Hello World 2")\n'
|
||||
Reference in New Issue
Block a user