markitdown/packages/markitup-sample-plugin/tests/test_sample_plugin.py

45 lines
1.3 KiB
Python
Raw Normal View History

#!/usr/bin/env python3 -m pytest
import os
import pytest
2025-04-21 07:13:19 +00:00
from markitup import MarkItUp, StreamInfo
from markitup_sample_plugin import RtfConverter
TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), "test_files")
RTF_TEST_STRINGS = {
"This is a Sample RTF File",
2025-04-21 07:13:19 +00:00
"It is included to test if the MarkItUp sample plugin can correctly convert RTF files.",
}
def test_converter() -> None:
"""Tests the RTF converter dirctly."""
with open(os.path.join(TEST_FILES_DIR, "test.rtf"), "rb") as file_stream:
converter = RtfConverter()
result = converter.convert(
file_stream=file_stream,
stream_info=StreamInfo(
mimetype="text/rtf", extension=".rtf", filename="test.rtf"
),
)
for test_string in RTF_TEST_STRINGS:
assert test_string in result.text_content
2025-04-21 07:13:19 +00:00
def test_markitup() -> None:
"""Tests that MarkItUp correctly loads the plugin."""
md = MarkItUp(enable_plugins=True)
result = md.convert(os.path.join(TEST_FILES_DIR, "test.rtf"))
for test_string in RTF_TEST_STRINGS:
assert test_string in result.text_content
if __name__ == "__main__":
"""Runs this file's tests from the command line."""
test_converter()
2025-04-21 07:13:19 +00:00
test_markitup()
print("All tests passed.")