You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_extract_code_blocks.py 833 B

12345678910111213141516171819202122232425262728293031323334353637
  1. from agnext.components.code_executor import extract_markdown_code_blocks
  2. def test_extract_markdown_code_blocks() -> None:
  3. text = """# This is a markdown text
  4. ```python
  5. print("Hello World")
  6. ```
  7. """
  8. code_blocks = extract_markdown_code_blocks(text)
  9. assert len(code_blocks) == 1
  10. assert code_blocks[0].language == "python"
  11. assert code_blocks[0].code == 'print("Hello World")\n'
  12. text = """More markdown text
  13. ```python
  14. print("Hello World")
  15. ```
  16. Another code block.
  17. ```python
  18. print("Hello World 2")
  19. ```
  20. """
  21. code_blocks = extract_markdown_code_blocks(text)
  22. assert len(code_blocks) == 2
  23. assert code_blocks[0].language == "python"
  24. assert code_blocks[0].code == 'print("Hello World")\n'
  25. assert code_blocks[1].language == "python"
  26. assert code_blocks[1].code == 'print("Hello World 2")\n'