Write a test for ParseMMDFile function.

This commit is contained in:
Zeth Green 2021-02-02 21:47:36 +00:00
parent 917f1a2f73
commit 64c67eaf48
2 changed files with 77 additions and 0 deletions

View file

@ -0,0 +1,4 @@
#!/usr/bin/env python
# --!-- coding: utf8 --!--
"""Tests for loadSave.py."""

View file

@ -0,0 +1,73 @@
#!/usr/bin/env python
# --!-- coding: utf8 --!--
"""Test ParseMMDFile function."""
from collections import OrderedDict
from manuskript.load_save.version_1 import parseMMDFile
BASE = "title: TheExampleNovel\n"
BASE += "ID: 42\n"
BASE += "type: folder\n"
TEXT = BASE + '\n'
TEXT_WITH_NONE_AT_START = "None: hello\n" + TEXT
TEXT_WITH_NONE_AT_END = BASE + "None: hello\n\n"
TEXT_WITH_HANGING_SPACE = BASE + " "
def test_empty_string():
"""An empty string given to parseMMDFile."""
result = parseMMDFile("")
assert result == ([], '')
def test_text():
"""A result as a list of tuples"""
result = parseMMDFile(TEXT)
assert result == ([
('title', 'TheExampleNovel'),
('ID', '42'),
('type', 'folder')
], '')
def test_text_asdict():
"""A result as an OrderedDict."""
result = parseMMDFile(TEXT, True)
assert result == (OrderedDict([
('title', 'TheExampleNovel'),
('ID', '42'),
('type', 'folder')]
), '')
def test_text_with_none_at_start():
"""If the description is None, replace with an empty string."""
result = parseMMDFile(TEXT_WITH_NONE_AT_START)
assert result == ([
('', 'hello'),
('title', 'TheExampleNovel'),
('ID', '42'),
('type', 'folder')
], '')
def test_text_wth_none_at_end():
"""If the last description is None, replace with an empty string."""
result = parseMMDFile(TEXT_WITH_NONE_AT_END)
assert result == ([
('title', 'TheExampleNovel'),
('ID', '42'),
('type', 'folder'),
('', 'hello')
], '')
def test_text_hanging_space():
"""Hanging space invalidates the line."""
result = parseMMDFile(TEXT_WITH_HANGING_SPACE)
assert result == ([
('title', 'TheExampleNovel'),
('ID', '42')
], '')