Spaces:
Sleeping
Sleeping
File size: 1,082 Bytes
d8d14f1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | import pytest
from swarms.utils import extract_code_from_markdown
@pytest.fixture
def markdown_content_with_code():
return """
# This is a markdown document
Some intro text here.
Some additional text.
"""
@pytest.fixture
def markdown_content_without_code():
return """
# This is a markdown document
There is no code in this document.
"""
def test_extract_code_from_markdown_with_code(
markdown_content_with_code,
):
extracted_code = extract_code_from_markdown(
markdown_content_with_code
)
assert "def my_func():" in extracted_code
assert 'print("This is my function.")' in extracted_code
assert "class MyClass:" in extracted_code
assert "pass" in extracted_code
def test_extract_code_from_markdown_without_code(
markdown_content_without_code,
):
extracted_code = extract_code_from_markdown(
markdown_content_without_code
)
assert extracted_code == ""
def test_extract_code_from_markdown_exception():
with pytest.raises(TypeError):
extract_code_from_markdown(None)
|