add tests for read & write jekyll posts

This commit is contained in:
Denis-Cosmin NUTIU 2023-06-02 10:52:35 +03:00
parent 90fafdc261
commit d7152d684b
2 changed files with 27 additions and 6 deletions

View file

@ -39,15 +39,13 @@ class FileWriter(IoWriter):
fo.write(data) fo.write(data)
class CallbackWriter(IoWriter): class TestingWriter(IoWriter):
""" """
Writes a post to a string. Writes a post to a string.
""" """
def __init__(self, callback: Callable[[str], None]): def __init__(self):
utils.guard_against_none(callback, "callback") self.content = ""
self.callback = callback
def write(self, data: str): def write(self, data: str):
self.callback(data) self.content += data

View file

@ -2,6 +2,8 @@ import pytest
from app.config import ConverterOptions from app.config import ConverterOptions
from app.converter import WordpressMarkdownConverter 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 from app.tests.utils import make_fake_configurator
@ -155,3 +157,24 @@ def test_fix_pre_content(input_lines, expected_lines):
) )
converter = WordpressMarkdownConverter(configurator) converter = WordpressMarkdownConverter(configurator)
assert converter.fix_pre_content(input_lines) == expected_lines 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"