Skip to content

Commit

Permalink
Merge pull request #831 from zeth/loadsave_test
Browse files Browse the repository at this point in the history
Write a test for ParseMMDFile function.
  • Loading branch information
TheJackiMonster committed Jun 8, 2022
2 parents e780963 + 344c21b commit 692995f
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
4 changes: 4 additions & 0 deletions manuskript/tests/load_save/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env python
# --!-- coding: utf8 --!--

"""Tests for load_save module."""
81 changes: 81 additions & 0 deletions manuskript/tests/load_save/test_ParseMMDFile.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 692995f

Please sign in to comment.