Skip to content

Commit

Permalink
100% coverage for document.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Aug 24, 2017
1 parent 24daa13 commit b220daa
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/zope/structuredtext/document.py
Expand Up @@ -64,7 +64,7 @@ class Document(object):
'doc_description',
'doc_header',
'doc_table',
]
]

#'doc_inner_link',
#'doc_named_link',
Expand All @@ -81,7 +81,7 @@ class Document(object):
'doc_underline',
'doc_sgml',
'doc_xref',
]
]

def __call__(self, doc):
if isinstance(doc, string_types):
Expand Down
47 changes: 47 additions & 0 deletions src/zope/structuredtext/tests.py
Expand Up @@ -17,6 +17,7 @@
import os

from zope.structuredtext import stng
from zope.structuredtext import stdom
from zope.structuredtext.document import DocumentWithImages

here = os.path.dirname(__file__)
Expand Down Expand Up @@ -44,6 +45,8 @@ class MockParagraph(object):
co_texts = ()
sub_paragraphs = ()
indent = 0
node_type = stdom.TEXT_NODE
node_value = ''

def __init__(self, **kwargs):
for k, v in kwargs.items():
Expand All @@ -55,6 +58,12 @@ def getColorizableTexts(self):
def getSubparagraphs(self):
return self.sub_paragraphs

def getNodeType(self):
return self.node_type

def getNodeValue(self):
return self.node_value

class TestFiles(unittest.TestCase):

maxDiff = None
Expand Down Expand Up @@ -171,6 +180,44 @@ def test_description_example(self):
self.assertIsInstance(result.getSubparagraphs()[0], stng.StructuredTextExample)
self.assertEqual(result._src, ':')

def test_parse_returns_string(self):
doc = DocumentWithImages()
returns = ['', ('a string', 0, 0)]
def text_type(arg):
return returns.pop()

result = doc.parse('raw_string', text_type)
self.assertEqual('a stringraw_string', result)

def test_parse_returns_list(self):
doc = DocumentWithImages()
returns = ['', ([1], 0, 0)]

def text_type(arg):
return returns.pop()

result = doc.parse('raw_string', text_type)
self.assertEqual([1, 'raw_string'], result)

def test_header_empty(self):
doc = DocumentWithImages()
header = MockParagraph(sub_paragraphs=self, co_texts=[''])

result = doc.doc_header(header)
self.assertIsNone(result)

def test_header_example(self):
doc = DocumentWithImages()
header = MockParagraph(sub_paragraphs=[MockParagraph()], co_texts=["::"])
result = doc.doc_header(header)
self.assertIsInstance(result, stng.StructuredTextExample)

def test_inner_link_is_not_named_link(self):
doc = DocumentWithImages()
result = doc.doc_inner_link('...[abc]')
self.assertIsInstance(result, tuple)
self.assertIsInstance(result[0], stng.StructuredTextInnerLink)

class BasicTests(unittest.TestCase):

def _test(self, stxtxt, expected):
Expand Down

0 comments on commit b220daa

Please sign in to comment.