org-rw/tests/test_dom.py

82 lines
3.4 KiB
Python
Raw Normal View History

2020-06-21 19:27:40 +00:00
import logging
import os
import unittest
from datetime import datetime as DT
from org_dom import dumps, load, loads
2020-06-27 17:20:34 +00:00
from utils.dom_assertions import (BOLD, CODE, HL, ITALIC, SPAN, STRIKE,
UNDERLINED, VERBATIM, Dom)
2020-06-21 19:27:40 +00:00
DIR = os.path.dirname(os.path.abspath(__file__))
class TestSerde(unittest.TestCase):
def test_simple_file_01(self):
with open(os.path.join(DIR, '01-simple.org')) as f:
doc = load(f)
ex = Dom(props=[('TITLE', '01-Simple'),
('DESCRIPTION', 'Simple org file'),
('TODO', 'TODO(t) PAUSED(p) | DONE(d)')],
children=(HL(
'First level',
props=[
('ID', '01-simple-first-level-id'),
('CREATED', DT(2020, 1, 1, 1, 1)),
],
2020-06-27 17:20:34 +00:00
content=' First level content\n',
2020-06-21 19:27:40 +00:00
children=[
HL('Second level',
props=[('ID', '01-simple-second-level-id')],
2020-06-27 17:20:34 +00:00
content='\n Second level content\n',
2020-06-21 19:27:40 +00:00
children=[
HL('Third level',
props=[('ID', '01-simple-third-level-id')],
2020-06-27 17:20:34 +00:00
content='\n Third level content\n')
2020-06-21 19:27:40 +00:00
])
])))
ex.assert_matches(self, doc)
def test_mimic_write_file_01(self):
"""A goal of this library is to be able to update a file without changing parts not directly modified."""
with open(os.path.join(DIR, '01-simple.org')) as f:
orig = f.read()
doc = loads(orig)
self.assertEqual(dumps(doc), orig)
2020-06-27 17:20:34 +00:00
def test_markup_file_02(self):
with open(os.path.join(DIR, '02-markup.org')) as f:
doc = load(f)
ex = Dom(props=[('TITLE', '02-Markup'),
('DESCRIPTION', 'Simple org file to test markup'),
('TODO', 'TODO(t) PAUSED(p) | DONE(d)')],
children=(HL('First level',
props=[
('ID', '02-markup-first-level-id'),
('CREATED', DT(2020, 1, 1, 1, 1)),
],
content=[
SPAN(" This is a ", BOLD("bold phrase"),
"."),
SPAN(""),
SPAN(" This is a ",
VERBATIM("verbatim phrase"), "."),
SPAN(""),
SPAN(" This is a ", ITALIC("italic phrase"),
"."),
SPAN(""),
SPAN(" This is a ",
STRIKE("strike-through phrase"), "."),
SPAN(""),
SPAN(" This is a ",
UNDERLINED("underlined phrase"), "."),
SPAN(""),
SPAN(" This is a ", CODE("code phrase"),
"."),
])))
ex.assert_matches(self, doc)