File: test_transform.py

package info (click to toggle)
codespeak-lib 0.9.1-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,212 kB
  • ctags: 5,409
  • sloc: python: 33,390; ansic: 961; xml: 582; makefile: 90
file content (39 lines) | stat: -rw-r--r-- 1,437 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import py
from py.__.rest.rst import *
from py.__.rest.transform import *

def convert_to_html(tree):
    handler = HTMLHandler()
    t = RestTransformer(tree)
    t.parse(handler)
    return handler.html

class HTMLHandler(py.__.rest.transform.HTMLHandler):
    def startDocument(self):
        pass
    endDocument = startDocument

def test_transform_basic_html():
    for rest, expected in ((Rest(Title('foo')), '<h1>foo</h1>'),
                           (Rest(Paragraph('foo')), '<p>foo</p>'),
                           (Rest(SubParagraph('foo')),
                            '<p class="sub">foo</p>'),
                           (Rest(LiteralBlock('foo\tbar')),
                            '<pre>foo\tbar</pre>'),
                           (Rest(Paragraph(Link('foo',
                                                'http://www.foo.com/'))),
                            '<p><a href="http://www.foo.com/">foo</a></p>')):
        html = convert_to_html(rest)
        assert html == expected

def test_transform_list_simple():
    rest = Rest(ListItem('foo'), ListItem('bar'))
    html = convert_to_html(rest)
    assert html == '<ul>\n  <li>foo</li>\n  <li>bar</li></ul>'

def test_transform_list_nested():
    rest = Rest(ListItem('foo'), ListItem('bar', ListItem('baz')))
    html = convert_to_html(rest)
    assert html == ('<ul>\n  <li>foo</li>\n  <li>bar\n    <ul>'
                    '\n      <li>baz</li></ul></li></ul>')