Source

pyorg / pyorg / tests / test_parser.py

Gabriele Lanaro 4243507 
Gabriele Lanaro 7d86853 
Gabriele Lanaro 4243507 
















Gabriele Lanaro 7d86853 

Gabriele Lanaro 4243507 





Gabriele Lanaro aa9225a 

Gabriele Lanaro 4243507 



Gabriele Lanaro aa9225a 







Gabriele Lanaro 7d86853 
Gabriele Lanaro aa9225a 
Gabriele Lanaro 7d86853 




Gabriele Lanaro 4243507 
from attest import Assert, Tests
from pyorg.parser import splitheads, maxhead, Node, parse_tags

tpars = Tests()

H1 = """* Heading 1
text H1
** Heading 1.1
text H1.1
"""
 
H2 = """* Heading 2
text H2
** Heading 2.1
text H2.1
"""

SAMPLE = ''.join([H1,H2])

TAG_SAMPLE = '** Tag sample :tag1:tag2:tag3'

@tpars.test
def test_splitting():
    """Splitting the text in the major sections
    """
    headings = splitheads(SAMPLE)
    Assert(headings[0]) == H1
    Assert(splitheads('')) == []
    Assert(splitheads(H1)) == [H1]

@tpars.test
def test_maxhead():
    Assert(maxhead(SAMPLE)) == 1
    Assert(maxhead(H1)) == 1

@tpars.test
def test_node():
    node = Node(H1)
    Assert(node.headline) == '* Heading 1'
    Assert(node.level) == 1
    
    Assert(node.childs[0].text) == '** Heading 1.1\ntext H1.1'

@tpars.test
def test_parse_tags():
    Assert(parse_tags('** Tag sample :tag1:tag2:tag3:')) == ['tag1', 'tag2', 'tag3']
    Assert(parse_tags('* Tag sample  :tag1:  ')) == ['tag1']
    Assert(parse_tags('* Tag sample   ')) == []
if __name__ == '__main__':
    tpars.run()