File: test_block.py

package info (click to toggle)
python-textile 1%3A4.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 452 kB
  • sloc: python: 2,620; sh: 7; makefile: 4
file content (98 lines) | stat: -rw-r--r-- 2,994 bytes parent folder | download | duplicates (3)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from __future__ import unicode_literals

import textile
from textile.objects import Block

try:
    from collections import OrderedDict
except ImportError:
    from ordereddict import OrderedDict

def test_block():
    t = textile.Textile()
    result = t.block('h1. foobar baby')
    expect = '\t<h1>foobar baby</h1>'
    assert result == expect

    b = Block(t, "bq", "", None, "", "Hello BlockQuote")
    expect = ('blockquote', OrderedDict(), 'p', OrderedDict(),
            'Hello BlockQuote')
    result = (b.outer_tag, b.outer_atts, b.inner_tag, b.inner_atts, b.content)
    assert result == expect

    b = Block(t, "bq", "", None, "http://google.com", "Hello BlockQuote")
    citation = '{0}1:url'.format(t.uid)
    expect = ('blockquote', OrderedDict([('cite',
        '{0.uid}{0.refIndex}:url'.format(t))]), 'p', OrderedDict(),
        'Hello BlockQuote')
    result = (b.outer_tag, b.outer_atts, b.inner_tag, b.inner_atts, b.content)
    assert result == expect

    b = Block(t, "bc", "", None, "", 'printf "Hello, World";')
    # the content of text will be turned shelved, so we'll asert only the
    # deterministic portions of the expected values, below
    expect = ('pre', OrderedDict(), 'code', OrderedDict())
    result = (b.outer_tag, b.outer_atts, b.inner_tag, b.inner_atts)
    assert result == expect

    b = Block(t, "h1", "", None, "", "foobar")
    expect = ('h1', OrderedDict(), '', OrderedDict(), 'foobar')
    result = (b.outer_tag, b.outer_atts, b.inner_tag, b.inner_atts, b.content)
    assert result == expect

def test_block_tags_false():
    t = textile.Textile(block_tags=False)
    assert t.block_tags is False

    result = t.parse('test')
    expect = 'test'
    assert result == expect

def test_blockcode_extended():
    input = 'bc.. text\nmoretext\n\nevenmoretext\n\nmoremoretext\n\np. test'
    expect = '<pre><code>text\nmoretext\n\nevenmoretext\n\nmoremoretext</code></pre>\n\n\t<p>test</p>'
    t = textile.Textile()
    result = t.parse(input)
    assert result == expect

def test_blockcode_in_README():
    with open('README.textile') as f:
        readme = ''.join(f.readlines())
    result = textile.textile(readme)
    with open('tests/fixtures/README.txt') as f:
        expect = ''.join(f.readlines())
    assert result == expect

def test_blockcode_comment():
    input = '###.. block comment\nanother line\n\np. New line'
    expect = '\t<p>New line</p>'
    t = textile.Textile()
    result = t.parse(input)
    assert result == expect

def test_extended_pre_block_with_many_newlines():
    """Extra newlines in an extended pre block should not get cut down to only
    two."""
    text = '''pre.. word

another

word


yet anothe word'''
    expect = '''<pre>word

another

word


yet anothe word</pre>'''
    result = textile.textile(text)
    assert result == expect

    text = 'p. text text\n\n\nh1. Hello\n'
    expect = '\t<p>text text</p>\n\n\n\t<h1>Hello</h1>'
    result = textile.textile(text)
    assert result == expect