~ubuntu-branches/ubuntu/karmic/python-docutils/karmic

« back to all changes in this revision

Viewing changes to test/test_rst/test_TableParser.py

  • Committer: Bazaar Package Importer
  • Author(s): martin f. krafft
  • Date: 2006-07-10 11:45:05 UTC
  • mfrom: (2.1.4 edgy)
  • Revision ID: james.westby@ubuntu.com-20060710114505-otkhqcslevewxmz5
Tags: 0.4-3
Added build dependency on python-central (closes: #377580).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/env python
2
 
 
3
 
"""
4
 
:Author: David Goodger
5
 
:Contact: goodger@users.sourceforge.net
6
 
:Revision: $Revision: 1.3 $
7
 
:Date: $Date: 2002/07/18 01:47:22 $
8
 
:Copyright: This module has been placed in the public domain.
9
 
 
10
 
Tests for states.py.
11
 
"""
12
 
 
13
 
from __init__ import DocutilsTestSupport
14
 
 
15
 
def suite():
16
 
    s = DocutilsTestSupport.GridTableParserTestSuite()
17
 
    s.generateTests(totest)
18
 
    return s
19
 
 
20
 
totest = {}
21
 
 
22
 
totest['grid_tables'] = [
23
 
["""\
24
 
+-------------------------------------+
25
 
| A table with one cell and one line. |
26
 
+-------------------------------------+
27
 
""",
28
 
[(0, 0, 2, 38, ['A table with one cell and one line.'])],
29
 
([37],
30
 
 [],
31
 
 [[(0, 0, 1, ['A table with one cell and one line.'])]])],
32
 
["""\
33
 
+--------------+--------------+
34
 
| A table with | two columns. |
35
 
+--------------+--------------+
36
 
""",
37
 
[(0, 0, 2, 15, ['A table with']),
38
 
 (0, 15, 2, 30, ['two columns.'])],
39
 
([14, 14],
40
 
 [],
41
 
 [[(0, 0, 1, ['A table with']),
42
 
   (0, 0, 1, ['two columns.'])]])],
43
 
["""\
44
 
+--------------+-------------+
45
 
| A table with | two columns |
46
 
+--------------+-------------+
47
 
| and          | two rows.   |
48
 
+--------------+-------------+
49
 
""",
50
 
[(0, 0, 2, 15, ['A table with']),
51
 
 (0, 15, 2, 29, ['two columns']),
52
 
 (2, 0, 4, 15, ['and']),
53
 
 (2, 15, 4, 29, ['two rows.'])],
54
 
([14, 13],
55
 
 [],
56
 
 [[(0, 0, 1, ['A table with']),
57
 
   (0, 0, 1, ['two columns'])],
58
 
  [(0, 0, 3, ['and']),
59
 
   (0, 0, 3, ['two rows.'])]])],
60
 
["""\
61
 
+--------------------------+
62
 
| A table with three rows, |
63
 
+------------+-------------+
64
 
| and two    | columns.    |
65
 
+------------+-------------+
66
 
| First and last rows      |
67
 
| contain column spans.    |
68
 
+--------------------------+
69
 
""",
70
 
[(0, 0, 2, 27, ['A table with three rows,']),
71
 
 (2, 0, 4, 13, ['and two']),
72
 
 (2, 13, 4, 27, ['columns.']),
73
 
 (4, 0, 7, 27, ['First and last rows', 'contain column spans.'])],
74
 
([12, 13],
75
 
 [],
76
 
 [[(0, 1, 1, ['A table with three rows,']),
77
 
   None],
78
 
  [(0, 0, 3, ['and two']),
79
 
   (0, 0, 3, ['columns.'])],
80
 
  [(0, 1, 5, ['First and last rows', 'contain column spans.']),
81
 
   None]])],
82
 
["""\
83
 
+------------+-------------+---------------+
84
 
| A table    | two rows in | and row spans |
85
 
| with three +-------------+ to left and   |
86
 
| columns,   | the middle, | right.        |
87
 
+------------+-------------+---------------+
88
 
""",
89
 
[(0, 0, 4, 13, ['A table', 'with three', 'columns,']),
90
 
 (0, 13, 2, 27, ['two rows in']),
91
 
 (0, 27, 4, 43, ['and row spans', 'to left and', 'right.']),
92
 
 (2, 13, 4, 27, ['the middle,'])],
93
 
([12, 13, 15],
94
 
 [],
95
 
 [[(1, 0, 1, ['A table', 'with three', 'columns,']),
96
 
   (0, 0, 1, ['two rows in']),
97
 
   (1, 0, 1, ['and row spans', 'to left and', 'right.'])],
98
 
  [None,
99
 
   (0, 0, 3, ['the middle,']),
100
 
   None]])],
101
 
["""\
102
 
+------------+-------------+---------------+
103
 
| A table |  | two rows in | and funny     |
104
 
| with 3  +--+-------------+-+ stuff.      |
105
 
| columns,   | the middle, | |             |
106
 
+------------+-------------+---------------+
107
 
""",
108
 
[(0, 0, 4, 13, ['A table |', 'with 3  +--', 'columns,']),
109
 
 (0, 13, 2, 27, ['two rows in']),
110
 
 (0, 27, 4, 43, [' and funny', '-+ stuff.', ' |']),
111
 
 (2, 13, 4, 27, ['the middle,'])],
112
 
([12, 13, 15],
113
 
 [],
114
 
 [[(1, 0, 1, ['A table |', 'with 3  +--', 'columns,']),
115
 
   (0, 0, 1, ['two rows in']),
116
 
   (1, 0, 1, [' and funny', '-+ stuff.', ' |'])],
117
 
  [None,
118
 
   (0, 0, 3, ['the middle,']),
119
 
   None]])],
120
 
["""\
121
 
+-----------+-------------------------+
122
 
| W/NW cell | N/NE cell               |
123
 
|           +-------------+-----------+
124
 
|           | Middle cell | E/SE cell |
125
 
+-----------+-------------+           |
126
 
| S/SE cell               |           |
127
 
+-------------------------+-----------+
128
 
""",
129
 
[(0, 0, 4, 12, ['W/NW cell', '', '']),
130
 
 (0, 12, 2, 38, ['N/NE cell']),
131
 
 (2, 12, 4, 26, ['Middle cell']),
132
 
 (2, 26, 6, 38, ['E/SE cell', '', '']),
133
 
 (4, 0, 6, 26, ['S/SE cell'])],
134
 
([11, 13, 11],
135
 
 [],
136
 
 [[(1, 0, 1, ['W/NW cell', '', '']),
137
 
   (0, 1, 1, ['N/NE cell']),
138
 
   None],
139
 
  [None,
140
 
   (0, 0, 3, ['Middle cell']),
141
 
   (1, 0, 3, ['E/SE cell', '', ''])],
142
 
  [(0, 1, 5, ['S/SE cell']),
143
 
   None,
144
 
   None]])],
145
 
["""\
146
 
+--------------+-------------+
147
 
| A bad table. |             |
148
 
+--------------+             |
149
 
| Cells must be rectangles.  |
150
 
+----------------------------+
151
 
""",
152
 
'TableMarkupError: Malformed table; parse incomplete.',
153
 
'TableMarkupError: Malformed table; parse incomplete.'],
154
 
["""\
155
 
+-------------------------------+
156
 
| A table with two header rows, |
157
 
+------------+------------------+
158
 
| the first  | with a span.     |
159
 
+============+==================+
160
 
| Two body   | rows,            |
161
 
+------------+------------------+
162
 
| the second with a span.       |
163
 
+-------------------------------+
164
 
""",
165
 
[(0, 0, 2, 32, ['A table with two header rows,']),
166
 
 (2, 0, 4, 13, ['the first']),
167
 
 (2, 13, 4, 32, ['with a span.']),
168
 
 (4, 0, 6, 13, ['Two body']),
169
 
 (4, 13, 6, 32, ['rows,']),
170
 
 (6, 0, 8, 32, ['the second with a span.'])],
171
 
([12, 18],
172
 
 [[(0, 1, 1, ['A table with two header rows,']),
173
 
   None],
174
 
  [(0, 0, 3, ['the first']),
175
 
   (0, 0, 3, ['with a span.'])]],
176
 
 [[(0, 0, 5, ['Two body']),
177
 
   (0, 0, 5, ['rows,'])],
178
 
  [(0, 1, 7, ['the second with a span.']),
179
 
   None]])],
180
 
["""\
181
 
+-------------------------------+
182
 
| A table with two head/body    |
183
 
+=============+=================+
184
 
| row         | separators.     |
185
 
+=============+=================+
186
 
| That's bad. |                 |
187
 
+-------------+-----------------+
188
 
""",
189
 
'TableMarkupError: Multiple head/body row separators in table '
190
 
'(at line offset 2 and 4); only one allowed.',
191
 
'TableMarkupError: Multiple head/body row separators in table '
192
 
'(at line offset 2 and 4); only one allowed.'],
193
 
]
194
 
 
195
 
 
196
 
if __name__ == '__main__':
197
 
    import unittest
198
 
    unittest.main(defaultTest='suite')