Merge pull request #831 from zeth/loadsave_test

Write a test for ParseMMDFile function.
This commit is contained in:
Tobias Frisch 2022-06-08 13:24:47 +02:00 committed by GitHub
commit 692995f51c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 85 additions and 0 deletions

View File

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

View File

@ -0,0 +1,81 @@
#!/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 + " "
CONTENT = "Once upon a time, there was a dog"
TEXT_WITH_CONTENT = TEXT + CONTENT
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')
], '')
def test_text_with_content():
"""The scene has text."""
result = parseMMDFile(TEXT_WITH_CONTENT)
assert result[1] == CONTENT