sources for test_htmlgen.py [rev. unknown]
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import py
from py.__.apigen import htmlgen
from py.__.apigen.linker import Linker
def assert_eq_string(string1, string2):
    if string1 == string2:
        return
    __tracebackhide__ = True
    for i, (c1, c2) in py.builtin.enumerate(zip(string1, string2)):
        if c1 != c2:
            start = max(0, i-20)
            end = i + 20
            py.test.fail("strings not equal in position i=%d\n"
                         "string1[%d:%d] = %r\n"
                         "string2[%d:%d] = %r\n"
                         "string1 = %r\n"
                         "string2 = %r\n" 
                         % (i, 
                            start, end, string1[start:end], 
                            start, end, string2[start:end], 
                            string1, string2
                        ))
def test_create_namespace_tree():
    tree = htmlgen.create_namespace_tree(['foo.bar.baz'])
    assert tree == {'': ['foo'],
                    'foo': ['foo.bar'],
                    'foo.bar': ['foo.bar.baz']}
    tree = htmlgen.create_namespace_tree(['foo.bar.baz', 'foo.bar.qux'])
    assert tree == {'': ['foo'],
                    'foo': ['foo.bar'],
                    'foo.bar': ['foo.bar.baz', 'foo.bar.qux']}
    tree = htmlgen.create_namespace_tree(['pkg.sub.func',
                                          'pkg.SomeClass',
                                          'pkg.SomeSubClass'])
    assert tree == {'': ['pkg'],
                    'pkg.sub': ['pkg.sub.func'],
                    'pkg': ['pkg.sub', 'pkg.SomeClass',
                            'pkg.SomeSubClass']}
def test_source_dirs_files():
    temp = py.test.ensuretemp('test_source_dirs_files')
    temp.join('dir').ensure(dir=True)
    temp.join('dir/file1.py').ensure(file=True)
    temp.join('dir/file2.pyc').ensure(file=True)
    temp.join('dir/file3.c').ensure(file=True)
    temp.join('dir/.hidden_file').ensure(file=True)
    temp.join('dir/sub').ensure(dir=True)
    temp.join('dir/.hidden_dir').ensure(dir=True)
    dirs, files = htmlgen.source_dirs_files(temp.join('dir'))
    dirnames = py.builtin.sorted([d.basename for d in dirs])
    filenames = py.builtin.sorted([f.basename for f in files])
    assert dirnames == ['sub']
    assert filenames == ['file1.py', 'file3.c']
def test_deindent():
    assert htmlgen.deindent('foo\n\n    bar\n    ') == 'foo\n\nbar\n'
    assert htmlgen.deindent(' foo\n\n    bar\n    ') == 'foo\n\nbar\n'
    assert htmlgen.deindent('foo\n\n    bar\n    baz') == 'foo\n\nbar\nbaz\n'
    assert htmlgen.deindent(' foo\n\n    bar\n      baz\n') == (
        'foo\n\nbar\n  baz\n')
    assert htmlgen.deindent('foo\n\n      bar\n    baz\n') == (
        'foo\n\n  bar\nbaz\n')
def test_enumerate_and_color():
    colored = htmlgen.enumerate_and_color(['def foo():', '  print "bar"'], 0,
                                          'ascii')
    div = py.xml.html.div(colored).unicode(indent=0)
    print repr(div)
    assert_eq_string(div,
                    u'<div>'
                    '<table class="codeblock">'
                    '<tbody>'
                    '<tr>'
                    '<td style="width: 1%">'
                    '<table>'
                    '<tbody>'
                    '<tr><td class="lineno">1</td></tr>'
                    '<tr><td class="lineno">2</td></tr>'
                    '</tbody>'
                    '</table>'
                    '</td>'
                    '<td>'
                    '<table>'
                    '<tbody>'
                    '<tr><td class="codecell">'
                    '<pre class="code">'
                    '<span class="alt_keyword">def</span> foo():'
                    '</pre>'
                    '</td></tr>'
                    '<tr><td class="codecell">'
                    '<pre class="code">'
                    '  <span class="alt_keyword">print</span>'
                    ' <span class="string">&quot;bar&quot;</span>'
                    '</pre>'
                    '</td></tr>'
                    '</tbody>'
                    '</table>'
                    '</td>'
                    '</tr>'
                    '</tbody>'
                    '</table>'
                    '</div>')
def test_enumerate_and_color_multiline():
    colored = htmlgen.enumerate_and_color(['code = """\\', 'foo bar', '"""'],
                                          0, 'ascii')
    div = py.xml.html.div(colored).unicode(indent=0)
    print repr(div)
    assert_eq_string (div,
                    u'<div>'
                    '<table class="codeblock">'
                    '<tbody>'
                    '<tr>'
                    '<td style="width: 1%">'
                    '<table>'
                    '<tbody>'
                    '<tr><td class="lineno">1</td></tr>'
                    '<tr><td class="lineno">2</td></tr>'
                    '<tr><td class="lineno">3</td></tr>'
                    '</tbody>'
                    '</table>'
                    '</td>'
                    '<td>'
                    '<table>'
                    '<tbody>'
                    '<tr><td class="codecell">'
                    '<pre class="code">'
                    'code = <span class="string">&quot;&quot;&quot;\\</span>'
                    '</pre>'
                    '</td></tr>'
                    '<tr><td class="codecell">'
                    '<pre class="code">'
                    '<span class="string">foo bar</span>'
                    '</pre>'
                    '</td></tr>'
                    '<tr><td class="codecell">'
                    '<pre class="code">'
                    '<span class="string">&quot;&quot;&quot;</span>'
                    '</pre>'
                    '</td></tr>'
                    '</tbody>'
                    '</table>'
                    '</td>'
                    '</tr>'
                    '</tbody>'
                    '</table>'
                    '</div>')
def test_show_property():
    assert htmlgen.show_property('foo')
    assert not htmlgen.show_property('_foo')
    assert htmlgen.show_property('__foo__')
    assert not htmlgen.show_property('__doc__')
    assert not htmlgen.show_property('__dict__')
    assert not htmlgen.show_property('__name__')
    assert not htmlgen.show_property('__class__')
def test_get_rel_sourcepath():
    projpath = py.path.local('/proj')
    assert (htmlgen.get_rel_sourcepath(projpath, py.path.local('/proj/foo')) ==
            'foo')
    assert (htmlgen.get_rel_sourcepath(projpath, py.path.local('/foo')) is
            None)
    assert (htmlgen.get_rel_sourcepath(projpath, py.path.local('<string>')) is
            None)