forked from kenkeiras/org-rw
Add base support for markup tests.
This commit is contained in:
parent
d23ee1adba
commit
0dab7e4703
6 changed files with 209 additions and 22 deletions
|
@ -2,6 +2,8 @@ import collections
|
|||
import unittest
|
||||
from datetime import datetime
|
||||
|
||||
from org_dom import get_raw_contents
|
||||
|
||||
|
||||
def timestamp_to_datetime(ts):
|
||||
return datetime(ts.year, ts.month, ts.day, ts.hour, ts.minute)
|
||||
|
@ -48,13 +50,13 @@ class HL:
|
|||
self.children = children
|
||||
|
||||
def assert_matches(self, test_case: unittest.TestCase, doc):
|
||||
test_case.assertEqual(self.title, doc['title'])
|
||||
test_case.assertEqual(self.title, doc.title)
|
||||
|
||||
# Check properties
|
||||
if self.props is None:
|
||||
test_case.assertEqual(len(doc['properties']), 0)
|
||||
test_case.assertEqual(len(doc.properties), 0)
|
||||
else:
|
||||
doc_props = doc['properties']
|
||||
doc_props = doc.properties
|
||||
test_case.assertEqual(len(doc_props), len(self.props))
|
||||
|
||||
for i, prop in enumerate(self.props):
|
||||
|
@ -63,15 +65,84 @@ class HL:
|
|||
test_case.assertEqual(
|
||||
timestamp_to_datetime(doc_props[i].value), prop[1])
|
||||
|
||||
# @TODO: Check properties
|
||||
if isinstance(self.content, str):
|
||||
test_case.assertEqual(get_raw_contents(doc), self.content)
|
||||
else:
|
||||
test_case.assertEqual(len(doc.contents), len(self.content))
|
||||
for i, content in enumerate(self.content):
|
||||
test_case.assertEqual(get_raw_contents(doc.contents[i]),
|
||||
content.to_raw())
|
||||
|
||||
# Check children
|
||||
if self.children is None:
|
||||
test_case.assertEqual(len(doc['children']), 0)
|
||||
test_case.assertEqual(len(doc.children), 0)
|
||||
else:
|
||||
doc_headlines = doc['children']
|
||||
doc_headlines = doc.children
|
||||
test_case.assertEqual(len(doc_headlines), len(self.children),
|
||||
self.title)
|
||||
|
||||
for i, children in enumerate(self.children):
|
||||
children.assert_matches(test_case, doc_headlines[i])
|
||||
|
||||
|
||||
class SPAN:
|
||||
def __init__(self, *kwargs):
|
||||
self.contents = kwargs
|
||||
|
||||
def to_raw(self):
|
||||
chunks = []
|
||||
for section in self.contents:
|
||||
if isinstance(section, str):
|
||||
chunks.append(section)
|
||||
else:
|
||||
chunks.append(section.to_raw())
|
||||
|
||||
return ''.join(chunks)
|
||||
|
||||
|
||||
class BOLD:
|
||||
def __init__(self, text):
|
||||
self.text = text
|
||||
|
||||
def to_raw(self):
|
||||
return '*{}*'.format(self.text)
|
||||
|
||||
|
||||
class CODE:
|
||||
def __init__(self, text):
|
||||
self.text = text
|
||||
|
||||
def to_raw(self):
|
||||
return '~{}~'.format(self.text)
|
||||
|
||||
|
||||
class ITALIC:
|
||||
def __init__(self, text):
|
||||
self.text = text
|
||||
|
||||
def to_raw(self):
|
||||
return '/{}/'.format(self.text)
|
||||
|
||||
|
||||
class STRIKE:
|
||||
def __init__(self, text):
|
||||
self.text = text
|
||||
|
||||
def to_raw(self):
|
||||
return '+{}+'.format(self.text)
|
||||
|
||||
|
||||
class UNDERLINED:
|
||||
def __init__(self, text):
|
||||
self.text = text
|
||||
|
||||
def to_raw(self):
|
||||
return '_{}_'.format(self.text)
|
||||
|
||||
|
||||
class VERBATIM:
|
||||
def __init__(self, text):
|
||||
self.text = text
|
||||
|
||||
def to_raw(self):
|
||||
return '={}='.format(self.text)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue