2025-02-10 23:21:44 +00:00
|
|
|
#!/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
|
2025-02-10 23:21:44 +00:00
|
|
|
|
|
|
|
|
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.",
|
2025-02-10 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_converter() -> None:
|
|
|
|
|
"""Tests the RTF converter dirctly."""
|
2025-03-06 05:16:55 +00:00
|
|
|
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"
|
|
|
|
|
),
|
|
|
|
|
)
|
2025-02-10 23:21:44 +00:00
|
|
|
|
2025-03-06 05:16:55 +00:00
|
|
|
for test_string in RTF_TEST_STRINGS:
|
|
|
|
|
assert test_string in result.text_content
|
2025-02-10 23:21:44 +00:00
|
|
|
|
|
|
|
|
|
2025-04-21 07:13:19 +00:00
|
|
|
def test_markitup() -> None:
|
|
|
|
|
"""Tests that MarkItUp correctly loads the plugin."""
|
|
|
|
|
md = MarkItUp(enable_plugins=True)
|
2025-02-10 23:21:44 +00:00
|
|
|
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()
|
2025-02-10 23:21:44 +00:00
|
|
|
print("All tests passed.")
|