diff --git a/app/io/writer.py b/app/io/writer.py index 9f935a3..d726a2a 100644 --- a/app/io/writer.py +++ b/app/io/writer.py @@ -39,15 +39,13 @@ class FileWriter(IoWriter): fo.write(data) -class CallbackWriter(IoWriter): +class TestingWriter(IoWriter): """ Writes a post to a string. """ - def __init__(self, callback: Callable[[str], None]): - utils.guard_against_none(callback, "callback") - - self.callback = callback + def __init__(self): + self.content = "" def write(self, data: str): - self.callback(data) + self.content += data diff --git a/app/tests/converter/wordpress_markdown_test.py b/app/tests/converter/wordpress_markdown_test.py index 8038779..5c5f91b 100644 --- a/app/tests/converter/wordpress_markdown_test.py +++ b/app/tests/converter/wordpress_markdown_test.py @@ -2,6 +2,8 @@ import pytest from app.config import ConverterOptions from app.converter import WordpressMarkdownConverter +from app.io.reader import StringReader +from app.io.writer import TestingWriter from app.tests.utils import make_fake_configurator @@ -155,3 +157,24 @@ def test_fix_pre_content(input_lines, expected_lines): ) converter = WordpressMarkdownConverter(configurator) assert converter.fix_pre_content(input_lines) == expected_lines + + +def test_read_jekyll_post(): + configurator = make_fake_configurator( + "wordpress_markdown_converter", + ConverterOptions(), + ) + converter = WordpressMarkdownConverter(configurator) + reader = StringReader("Test") + assert converter.read_jekyll_post(reader) == "Test" + + +def test_write_hugo_post(): + configurator = make_fake_configurator( + "wordpress_markdown_converter", + ConverterOptions(), + ) + converter = WordpressMarkdownConverter(configurator) + writer = TestingWriter() + converter.write_hugo_post(writer, {"title": "Test"}, "Test\nLine 2") + assert writer.content == "---\ntitle: Test\n---\nTest\nLine 2"