~ubuntu-branches/ubuntu/hardy/python-docutils/hardy

« back to all changes in this revision

Viewing changes to test/test_parsers/test_rst/test_directives/test_tables.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
# Author: David Goodger
 
4
# Contact: goodger@python.org
 
5
# Revision: $Revision: 3165 $
 
6
# Date: $Date: 2005-04-05 04:55:06 +0200 (Tue, 05 Apr 2005) $
 
7
# Copyright: This module has been placed in the public domain.
 
8
 
 
9
"""
 
10
Tests for tables.py directives.
 
11
"""
 
12
 
 
13
from __init__ import DocutilsTestSupport
 
14
 
 
15
import os
 
16
try:
 
17
    import csv
 
18
except ImportError:
 
19
    csv = None
 
20
 
 
21
 
 
22
def suite():
 
23
    s = DocutilsTestSupport.ParserTestSuite()
 
24
    s.generateTests(totest)
 
25
    return s
 
26
 
 
27
mydir = 'test_parsers/test_rst/test_directives/'
 
28
utf_16_csv = os.path.join(mydir, 'utf-16.csv')
 
29
utf_16_csv_rel = DocutilsTestSupport.utils.relative_path(None, utf_16_csv)
 
30
empty_txt = os.path.join(mydir, 'empty.txt')
 
31
 
 
32
totest = {}
 
33
 
 
34
totest['table'] = [
 
35
["""\
 
36
.. table:: Truth table for "not"
 
37
   :class: custom
 
38
 
 
39
   =====  =====
 
40
     A    not A
 
41
   =====  =====
 
42
   False  True
 
43
   True   False
 
44
   =====  =====
 
45
""",
 
46
"""\
 
47
<document source="test data">
 
48
    <table classes="custom">
 
49
        <title>
 
50
            Truth table for "not"
 
51
        <tgroup cols="2">
 
52
            <colspec colwidth="5">
 
53
            <colspec colwidth="5">
 
54
            <thead>
 
55
                <row>
 
56
                    <entry>
 
57
                        <paragraph>
 
58
                            A
 
59
                    <entry>
 
60
                        <paragraph>
 
61
                            not A
 
62
            <tbody>
 
63
                <row>
 
64
                    <entry>
 
65
                        <paragraph>
 
66
                            False
 
67
                    <entry>
 
68
                        <paragraph>
 
69
                            True
 
70
                <row>
 
71
                    <entry>
 
72
                        <paragraph>
 
73
                            True
 
74
                    <entry>
 
75
                        <paragraph>
 
76
                            False
 
77
"""],
 
78
["""\
 
79
.. table:: title with an *error
 
80
 
 
81
   ======  =====
 
82
   Simple  table
 
83
   ======  =====
 
84
""",
 
85
"""\
 
86
<document source="test data">
 
87
    <table>
 
88
        <title>
 
89
            title with an \n\
 
90
            <problematic ids="id2" refid="id1">
 
91
                *
 
92
            error
 
93
        <tgroup cols="2">
 
94
            <colspec colwidth="6">
 
95
            <colspec colwidth="5">
 
96
            <tbody>
 
97
                <row>
 
98
                    <entry>
 
99
                        <paragraph>
 
100
                            Simple
 
101
                    <entry>
 
102
                        <paragraph>
 
103
                            table
 
104
    <system_message backrefs="id2" ids="id1" level="2" line="1" source="test data" type="WARNING">
 
105
        <paragraph>
 
106
            Inline emphasis start-string without end-string.
 
107
"""],
 
108
]
 
109
 
 
110
if not csv:
 
111
    print ('Tests of "csv-table" directive skipped; '
 
112
           'Python 2.3 or higher required.')
 
113
else:
 
114
    totest['csv-table'] = [
 
115
["""\
 
116
.. csv-table:: inline with integral header
 
117
   :widths: 10, 20, 30
 
118
   :header-rows: 1
 
119
   :stub-columns: 1
 
120
 
 
121
   "Treat", "Quantity", "Description"
 
122
   "Albatross", 2.99, "On a stick!"
 
123
   "Crunchy Frog", 1.49, "If we took the bones out, it wouldn\'t be
 
124
   crunchy, now would it?"
 
125
   "Gannet Ripple", 1.99, "On a stick!"
 
126
""",
 
127
"""\
 
128
<document source="test data">
 
129
    <table>
 
130
        <title>
 
131
            inline with integral header
 
132
        <tgroup cols="3">
 
133
            <colspec colwidth="10" stub="1">
 
134
            <colspec colwidth="20">
 
135
            <colspec colwidth="30">
 
136
            <thead>
 
137
                <row>
 
138
                    <entry>
 
139
                        <paragraph>
 
140
                            Treat
 
141
                    <entry>
 
142
                        <paragraph>
 
143
                            Quantity
 
144
                    <entry>
 
145
                        <paragraph>
 
146
                            Description
 
147
            <tbody>
 
148
                <row>
 
149
                    <entry>
 
150
                        <paragraph>
 
151
                            Albatross
 
152
                    <entry>
 
153
                        <paragraph>
 
154
                            2.99
 
155
                    <entry>
 
156
                        <paragraph>
 
157
                            On a stick!
 
158
                <row>
 
159
                    <entry>
 
160
                        <paragraph>
 
161
                            Crunchy Frog
 
162
                    <entry>
 
163
                        <paragraph>
 
164
                            1.49
 
165
                    <entry>
 
166
                        <paragraph>
 
167
                            If we took the bones out, it wouldn't be
 
168
                            crunchy, now would it?
 
169
                <row>
 
170
                    <entry>
 
171
                        <paragraph>
 
172
                            Gannet Ripple
 
173
                    <entry>
 
174
                        <paragraph>
 
175
                            1.99
 
176
                    <entry>
 
177
                        <paragraph>
 
178
                            On a stick!
 
179
"""],
 
180
["""\
 
181
.. csv-table:: inline with separate header
 
182
   :header: "Treat", Quantity, "Description"
 
183
   :widths: 10,20,30
 
184
 
 
185
   "Albatross", 2.99, "On a stick!"
 
186
""",
 
187
"""\
 
188
<document source="test data">
 
189
    <table>
 
190
        <title>
 
191
            inline with separate header
 
192
        <tgroup cols="3">
 
193
            <colspec colwidth="10">
 
194
            <colspec colwidth="20">
 
195
            <colspec colwidth="30">
 
196
            <thead>
 
197
                <row>
 
198
                    <entry>
 
199
                        <paragraph>
 
200
                            Treat
 
201
                    <entry>
 
202
                        <paragraph>
 
203
                            Quantity
 
204
                    <entry>
 
205
                        <paragraph>
 
206
                            Description
 
207
            <tbody>
 
208
                <row>
 
209
                    <entry>
 
210
                        <paragraph>
 
211
                            Albatross
 
212
                    <entry>
 
213
                        <paragraph>
 
214
                            2.99
 
215
                    <entry>
 
216
                        <paragraph>
 
217
                            On a stick!
 
218
"""],
 
219
["""\
 
220
.. csv-table:: complex internal structure
 
221
   :header: "Treat", Quantity, "
 
222
            * Description,
 
223
            * Definition, or
 
224
            * Narrative"
 
225
 
 
226
   "
 
227
   * Ice cream
 
228
   * Sorbet
 
229
   * Albatross", 2.99, "On a stick!"
 
230
""",
 
231
"""\
 
232
<document source="test data">
 
233
    <table>
 
234
        <title>
 
235
            complex internal structure
 
236
        <tgroup cols="3">
 
237
            <colspec colwidth="33">
 
238
            <colspec colwidth="33">
 
239
            <colspec colwidth="33">
 
240
            <thead>
 
241
                <row>
 
242
                    <entry>
 
243
                        <paragraph>
 
244
                            Treat
 
245
                    <entry>
 
246
                        <paragraph>
 
247
                            Quantity
 
248
                    <entry>
 
249
                        <bullet_list bullet="*">
 
250
                            <list_item>
 
251
                                <paragraph>
 
252
                                    Description,
 
253
                            <list_item>
 
254
                                <paragraph>
 
255
                                    Definition, or
 
256
                            <list_item>
 
257
                                <paragraph>
 
258
                                    Narrative
 
259
            <tbody>
 
260
                <row>
 
261
                    <entry>
 
262
                        <bullet_list bullet="*">
 
263
                            <list_item>
 
264
                                <paragraph>
 
265
                                    Ice cream
 
266
                            <list_item>
 
267
                                <paragraph>
 
268
                                    Sorbet
 
269
                            <list_item>
 
270
                                <paragraph>
 
271
                                    Albatross
 
272
                    <entry>
 
273
                        <paragraph>
 
274
                            2.99
 
275
                    <entry>
 
276
                        <paragraph>
 
277
                            On a stick!
 
278
"""],
 
279
["""\
 
280
.. csv-table:: short rows
 
281
 
 
282
   one, 2, three
 
283
   4, five
 
284
""",
 
285
"""\
 
286
<document source="test data">
 
287
    <table>
 
288
        <title>
 
289
            short rows
 
290
        <tgroup cols="3">
 
291
            <colspec colwidth="33">
 
292
            <colspec colwidth="33">
 
293
            <colspec colwidth="33">
 
294
            <tbody>
 
295
                <row>
 
296
                    <entry>
 
297
                        <paragraph>
 
298
                            one
 
299
                    <entry>
 
300
                        <paragraph>
 
301
                            2
 
302
                    <entry>
 
303
                        <paragraph>
 
304
                            three
 
305
                <row>
 
306
                    <entry>
 
307
                        <paragraph>
 
308
                            4
 
309
                    <entry>
 
310
                        <paragraph>
 
311
                            five
 
312
                    <entry>
 
313
"""],
 
314
["""\
 
315
.. csv-table:: short rows
 
316
   :header-rows: 1
 
317
 
 
318
   header col 1, header col 2
 
319
   one, 2, three
 
320
   4
 
321
""",
 
322
"""\
 
323
<document source="test data">
 
324
    <table>
 
325
        <title>
 
326
            short rows
 
327
        <tgroup cols="3">
 
328
            <colspec colwidth="33">
 
329
            <colspec colwidth="33">
 
330
            <colspec colwidth="33">
 
331
            <thead>
 
332
                <row>
 
333
                    <entry>
 
334
                        <paragraph>
 
335
                            header col 1
 
336
                    <entry>
 
337
                        <paragraph>
 
338
                            header col 2
 
339
                    <entry>
 
340
            <tbody>
 
341
                <row>
 
342
                    <entry>
 
343
                        <paragraph>
 
344
                            one
 
345
                    <entry>
 
346
                        <paragraph>
 
347
                            2
 
348
                    <entry>
 
349
                        <paragraph>
 
350
                            three
 
351
                <row>
 
352
                    <entry>
 
353
                        <paragraph>
 
354
                            4
 
355
                    <entry>
 
356
                    <entry>
 
357
"""],
 
358
[u"""\
 
359
.. csv-table:: non-ASCII characters
 
360
 
 
361
   Heiz\xf6lr\xfccksto\xdfabd\xe4mpfung
 
362
""",
 
363
u"""\
 
364
<document source="test data">
 
365
    <table>
 
366
        <title>
 
367
            non-ASCII characters
 
368
        <tgroup cols="1">
 
369
            <colspec colwidth="100">
 
370
            <tbody>
 
371
                <row>
 
372
                    <entry>
 
373
                        <paragraph>
 
374
                            Heiz\xf6lr\xfccksto\xdfabd\xe4mpfung
 
375
"""],
 
376
["""\
 
377
.. csv-table:: empty
 
378
""",
 
379
"""\
 
380
<document source="test data">
 
381
    <system_message level="2" line="1" source="test data" type="WARNING">
 
382
        <paragraph>
 
383
            The "csv-table" directive requires content; none supplied.
 
384
        <literal_block xml:space="preserve">
 
385
            .. csv-table:: empty
 
386
"""],
 
387
["""\
 
388
.. csv-table:: insufficient header row data
 
389
   :header-rows: 2
 
390
 
 
391
   some, csv, data
 
392
""",
 
393
"""\
 
394
<document source="test data">
 
395
    <system_message level="3" line="1" source="test data" type="ERROR">
 
396
        <paragraph>
 
397
            2 header row(s) specified but only 1 row(s) of data supplied ("csv-table" directive).
 
398
        <literal_block xml:space="preserve">
 
399
            .. csv-table:: insufficient header row data
 
400
               :header-rows: 2
 
401
            \n\
 
402
               some, csv, data
 
403
"""],
 
404
["""\
 
405
.. csv-table:: insufficient body data
 
406
   :header-rows: 1
 
407
 
 
408
   some, csv, data
 
409
""",
 
410
"""\
 
411
<document source="test data">
 
412
    <system_message level="3" line="1" source="test data" type="ERROR">
 
413
        <paragraph>
 
414
            Insufficient data supplied (1 row(s)); no data remaining for table body, required by "csv-table" directive.
 
415
        <literal_block xml:space="preserve">
 
416
            .. csv-table:: insufficient body data
 
417
               :header-rows: 1
 
418
            \n\
 
419
               some, csv, data
 
420
"""],
 
421
["""\
 
422
.. csv-table:: content and external
 
423
   :file: bogus.csv
 
424
 
 
425
   some, csv, data
 
426
""",
 
427
"""\
 
428
<document source="test data">
 
429
    <system_message level="3" line="1" source="test data" type="ERROR">
 
430
        <paragraph>
 
431
            "csv-table" directive may not both specify an external file and have content.
 
432
        <literal_block xml:space="preserve">
 
433
            .. csv-table:: content and external
 
434
               :file: bogus.csv
 
435
            \n\
 
436
               some, csv, data
 
437
"""],
 
438
["""\
 
439
.. csv-table:: external file and url
 
440
   :file: bogus.csv
 
441
   :url: http://example.org/bogus.csv
 
442
""",
 
443
"""\
 
444
<document source="test data">
 
445
    <system_message level="3" line="1" source="test data" type="ERROR">
 
446
        <paragraph>
 
447
            The "file" and "url" options may not be simultaneously specified for the "csv-table" directive.
 
448
        <literal_block xml:space="preserve">
 
449
            .. csv-table:: external file and url
 
450
               :file: bogus.csv
 
451
               :url: http://example.org/bogus.csv
 
452
"""],
 
453
["""\
 
454
.. csv-table:: error in the *title
 
455
 
 
456
   some, csv, data
 
457
""",
 
458
"""\
 
459
<document source="test data">
 
460
    <table>
 
461
        <title>
 
462
            error in the \n\
 
463
            <problematic ids="id2" refid="id1">
 
464
                *
 
465
            title
 
466
        <tgroup cols="3">
 
467
            <colspec colwidth="33">
 
468
            <colspec colwidth="33">
 
469
            <colspec colwidth="33">
 
470
            <tbody>
 
471
                <row>
 
472
                    <entry>
 
473
                        <paragraph>
 
474
                            some
 
475
                    <entry>
 
476
                        <paragraph>
 
477
                            csv
 
478
                    <entry>
 
479
                        <paragraph>
 
480
                            data
 
481
    <system_message backrefs="id2" ids="id1" level="2" line="1" source="test data" type="WARNING">
 
482
        <paragraph>
 
483
            Inline emphasis start-string without end-string.
 
484
"""],
 
485
["""\
 
486
.. csv-table:: no such file
 
487
   :file: bogus.csv
 
488
""",
 
489
"""\
 
490
<document source="test data">
 
491
    <system_message level="4" line="1" source="test data" type="SEVERE">
 
492
        <paragraph>
 
493
            Problems with "csv-table" directive path:
 
494
            [Errno 2] No such file or directory: 'bogus.csv'.
 
495
        <literal_block xml:space="preserve">
 
496
            .. csv-table:: no such file
 
497
               :file: bogus.csv
 
498
"""],
 
499
["""\
 
500
.. csv-table:: bad URL
 
501
   :url: bogus.csv
 
502
""",
 
503
"""\
 
504
<document source="test data">
 
505
    <system_message level="4" line="1" source="test data" type="SEVERE">
 
506
        <paragraph>
 
507
            Problems with "csv-table" directive URL "bogus.csv":
 
508
            unknown url type: bogus.csv.
 
509
        <literal_block xml:space="preserve">
 
510
            .. csv-table:: bad URL
 
511
               :url: bogus.csv
 
512
"""],
 
513
["""\
 
514
.. csv-table:: column mismatch
 
515
   :widths: 10,20
 
516
 
 
517
   some, csv, data
 
518
""",
 
519
"""\
 
520
<document source="test data">
 
521
    <system_message level="3" line="1" source="test data" type="ERROR">
 
522
        <paragraph>
 
523
            "csv-table" widths do not match the number of columns in table (3).
 
524
        <literal_block xml:space="preserve">
 
525
            .. csv-table:: column mismatch
 
526
               :widths: 10,20
 
527
            \n\
 
528
               some, csv, data
 
529
"""],
 
530
["""\
 
531
.. csv-table:: bad column widths
 
532
   :widths: 10,y,z
 
533
 
 
534
   some, csv, data
 
535
 
 
536
.. csv-table:: bad column widths
 
537
   :widths: 0 0 0
 
538
 
 
539
   some, csv, data
 
540
""",
 
541
"""\
 
542
<document source="test data">
 
543
    <system_message level="3" line="1" source="test data" type="ERROR">
 
544
        <paragraph>
 
545
            Error in "csv-table" directive:
 
546
            invalid option value: (option: "widths"; value: '10,y,z')
 
547
            invalid literal for int(): y.
 
548
        <literal_block xml:space="preserve">
 
549
            .. csv-table:: bad column widths
 
550
               :widths: 10,y,z
 
551
            \n\
 
552
               some, csv, data
 
553
    <system_message level="3" line="6" source="test data" type="ERROR">
 
554
        <paragraph>
 
555
            Error in "csv-table" directive:
 
556
            invalid option value: (option: "widths"; value: '0 0 0')
 
557
            negative or zero value; must be positive.
 
558
        <literal_block xml:space="preserve">
 
559
            .. csv-table:: bad column widths
 
560
               :widths: 0 0 0
 
561
            \n\
 
562
               some, csv, data
 
563
"""],
 
564
["""\
 
565
.. csv-table:: good delimiter
 
566
   :delim: /
 
567
 
 
568
   some/csv/data
 
569
 
 
570
.. csv-table:: good delimiter
 
571
   :delim: \\
 
572
 
 
573
   some\\csv\\data
 
574
 
 
575
.. csv-table:: good delimiter
 
576
   :delim: 0x5c
 
577
 
 
578
   some\\csv\\data
 
579
 
 
580
.. csv-table:: good delimiter
 
581
   :delim: space
 
582
 
 
583
   some csv data
 
584
""",
 
585
"""\
 
586
<document source="test data">
 
587
    <table>
 
588
        <title>
 
589
            good delimiter
 
590
        <tgroup cols="3">
 
591
            <colspec colwidth="33">
 
592
            <colspec colwidth="33">
 
593
            <colspec colwidth="33">
 
594
            <tbody>
 
595
                <row>
 
596
                    <entry>
 
597
                        <paragraph>
 
598
                            some
 
599
                    <entry>
 
600
                        <paragraph>
 
601
                            csv
 
602
                    <entry>
 
603
                        <paragraph>
 
604
                            data
 
605
    <table>
 
606
        <title>
 
607
            good delimiter
 
608
        <tgroup cols="3">
 
609
            <colspec colwidth="33">
 
610
            <colspec colwidth="33">
 
611
            <colspec colwidth="33">
 
612
            <tbody>
 
613
                <row>
 
614
                    <entry>
 
615
                        <paragraph>
 
616
                            some
 
617
                    <entry>
 
618
                        <paragraph>
 
619
                            csv
 
620
                    <entry>
 
621
                        <paragraph>
 
622
                            data
 
623
    <table>
 
624
        <title>
 
625
            good delimiter
 
626
        <tgroup cols="3">
 
627
            <colspec colwidth="33">
 
628
            <colspec colwidth="33">
 
629
            <colspec colwidth="33">
 
630
            <tbody>
 
631
                <row>
 
632
                    <entry>
 
633
                        <paragraph>
 
634
                            some
 
635
                    <entry>
 
636
                        <paragraph>
 
637
                            csv
 
638
                    <entry>
 
639
                        <paragraph>
 
640
                            data
 
641
    <table>
 
642
        <title>
 
643
            good delimiter
 
644
        <tgroup cols="3">
 
645
            <colspec colwidth="33">
 
646
            <colspec colwidth="33">
 
647
            <colspec colwidth="33">
 
648
            <tbody>
 
649
                <row>
 
650
                    <entry>
 
651
                        <paragraph>
 
652
                            some
 
653
                    <entry>
 
654
                        <paragraph>
 
655
                            csv
 
656
                    <entry>
 
657
                        <paragraph>
 
658
                            data
 
659
"""],
 
660
["""\
 
661
.. csv-table:: bad delimiter
 
662
   :delim: multiple
 
663
 
 
664
.. csv-table:: bad delimiter
 
665
   :delim: U+9999999999999
 
666
""",
 
667
"""\
 
668
<document source="test data">
 
669
    <system_message level="3" line="1" source="test data" type="ERROR">
 
670
        <paragraph>
 
671
            Error in "csv-table" directive:
 
672
            invalid option value: (option: "delim"; value: 'multiple')
 
673
            'multiple' invalid; must be a single character or a Unicode code.
 
674
        <literal_block xml:space="preserve">
 
675
            .. csv-table:: bad delimiter
 
676
               :delim: multiple
 
677
    <system_message level="3" line="4" source="test data" type="ERROR">
 
678
        <paragraph>
 
679
            Error in "csv-table" directive:
 
680
            invalid option value: (option: "delim"; value: 'U+9999999999999')
 
681
            code too large (long int too large to convert to int).
 
682
        <literal_block xml:space="preserve">
 
683
            .. csv-table:: bad delimiter
 
684
               :delim: U+9999999999999
 
685
"""],
 
686
["""\
 
687
.. csv-table:: bad CSV data
 
688
 
 
689
   "bad", \"csv, data
 
690
""",
 
691
"""\
 
692
<document source="test data">
 
693
    <system_message level="3" line="1" source="test data" type="ERROR">
 
694
        <paragraph>
 
695
            Error with CSV data in "csv-table" directive:
 
696
            newline inside string
 
697
        <literal_block xml:space="preserve">
 
698
            .. csv-table:: bad CSV data
 
699
            \n\
 
700
               "bad", \"csv, data
 
701
"""],
 
702
["""\
 
703
.. csv-table:: bad CSV header data
 
704
   :header: "bad", \"csv, data
 
705
 
 
706
   good, csv, data
 
707
""",
 
708
"""\
 
709
<document source="test data">
 
710
    <system_message level="3" line="1" source="test data" type="ERROR">
 
711
        <paragraph>
 
712
            Error with CSV data in "csv-table" directive:
 
713
            newline inside string
 
714
        <literal_block xml:space="preserve">
 
715
            .. csv-table:: bad CSV header data
 
716
               :header: "bad", \"csv, data
 
717
            \n\
 
718
               good, csv, data
 
719
"""],
 
720
["""\
 
721
.. csv-table:: bad encoding
 
722
   :file: %s
 
723
   :encoding: latin-1
 
724
 
 
725
(7- and 8-bit text encoded as UTF-16 has lots of null/zero bytes.)
 
726
""" % utf_16_csv,
 
727
"""\
 
728
<document source="test data">
 
729
    <system_message level="3" line="1" source="test data" type="ERROR">
 
730
        <paragraph>
 
731
            Error with CSV data in "csv-table" directive:
 
732
            string with NUL bytes
 
733
        <literal_block xml:space="preserve">
 
734
            .. csv-table:: bad encoding
 
735
               :file: %s
 
736
               :encoding: latin-1
 
737
    <paragraph>
 
738
        (7- and 8-bit text encoded as UTF-16 has lots of null/zero bytes.)
 
739
""" % utf_16_csv],
 
740
["""\
 
741
.. csv-table:: good encoding
 
742
   :file: %s
 
743
   :encoding: utf-16
 
744
   :header-rows: 1
 
745
""" % utf_16_csv,
 
746
u"""\
 
747
<document source="test data">
 
748
    <table>
 
749
        <title>
 
750
            good encoding
 
751
        <tgroup cols="3">
 
752
            <colspec colwidth="33">
 
753
            <colspec colwidth="33">
 
754
            <colspec colwidth="33">
 
755
            <thead>
 
756
                <row>
 
757
                    <entry>
 
758
                        <paragraph>
 
759
                            Treat
 
760
                    <entry>
 
761
                        <paragraph>
 
762
                            Quantity
 
763
                    <entry>
 
764
                        <paragraph>
 
765
                            Description
 
766
            <tbody>
 
767
                <row>
 
768
                    <entry>
 
769
                        <paragraph>
 
770
                            Albatr\u00b0\u00df
 
771
                    <entry>
 
772
                        <paragraph>
 
773
                            2.99
 
774
                    <entry>
 
775
                        <paragraph>
 
776
                            \u00a1On a \u03c3\u03c4\u03b9\u03ba!
 
777
                <row>
 
778
                    <entry>
 
779
                        <paragraph>
 
780
                            Crunchy Frog
 
781
                    <entry>
 
782
                        <paragraph>
 
783
                            1.49
 
784
                    <entry>
 
785
                        <paragraph>
 
786
                            If we took the b\u00f6nes out, it wouldn\u2019t be
 
787
                            crunchy, now would it?
 
788
                <row>
 
789
                    <entry>
 
790
                        <paragraph>
 
791
                            Gannet Ripple
 
792
                    <entry>
 
793
                        <paragraph>
 
794
                            1.99
 
795
                    <entry>
 
796
                        <paragraph>
 
797
                            \u00bfOn a \u03c3\u03c4\u03b9\u03ba?
 
798
"""],
 
799
["""\
 
800
.. csv-table:: no CSV data
 
801
   :file: %s
 
802
""" % empty_txt,
 
803
"""\
 
804
<document source="test data">
 
805
    <system_message level="3" line="1" source="test data" type="ERROR">
 
806
        <paragraph>
 
807
            No table data detected in CSV file.
 
808
        <literal_block xml:space="preserve">
 
809
            .. csv-table:: no CSV data
 
810
               :file: %s
 
811
""" % empty_txt],
 
812
]
 
813
 
 
814
totest['list-table'] = [
 
815
["""\
 
816
.. list-table:: list table with integral header
 
817
   :widths: 10 20 30
 
818
   :header-rows: 1
 
819
   :stub-columns: 1
 
820
 
 
821
   * - Treat
 
822
     - Quantity
 
823
     - Description
 
824
   * - Albatross
 
825
     - 2.99
 
826
     - On a stick!
 
827
   * - Crunchy Frog
 
828
     - 1.49
 
829
     - If we took the bones out, it wouldn\'t be
 
830
       crunchy, now would it?
 
831
   * - Gannet Ripple
 
832
     - 1.99
 
833
     - On a stick!
 
834
""",
 
835
"""\
 
836
<document source="test data">
 
837
    <table>
 
838
        <title>
 
839
            list table with integral header
 
840
        <tgroup cols="3">
 
841
            <colspec colwidth="10" stub="1">
 
842
            <colspec colwidth="20">
 
843
            <colspec colwidth="30">
 
844
            <thead>
 
845
                <row>
 
846
                    <entry>
 
847
                        <paragraph>
 
848
                            Treat
 
849
                    <entry>
 
850
                        <paragraph>
 
851
                            Quantity
 
852
                    <entry>
 
853
                        <paragraph>
 
854
                            Description
 
855
            <tbody>
 
856
                <row>
 
857
                    <entry>
 
858
                        <paragraph>
 
859
                            Albatross
 
860
                    <entry>
 
861
                        <paragraph>
 
862
                            2.99
 
863
                    <entry>
 
864
                        <paragraph>
 
865
                            On a stick!
 
866
                <row>
 
867
                    <entry>
 
868
                        <paragraph>
 
869
                            Crunchy Frog
 
870
                    <entry>
 
871
                        <paragraph>
 
872
                            1.49
 
873
                    <entry>
 
874
                        <paragraph>
 
875
                            If we took the bones out, it wouldn\'t be
 
876
                            crunchy, now would it?
 
877
                <row>
 
878
                    <entry>
 
879
                        <paragraph>
 
880
                            Gannet Ripple
 
881
                    <entry>
 
882
                        <paragraph>
 
883
                            1.99
 
884
                    <entry>
 
885
                        <paragraph>
 
886
                            On a stick!
 
887
"""],
 
888
["""\
 
889
.. list-table::
 
890
 
 
891
   not a bullet list
 
892
""",
 
893
"""\
 
894
<document source="test data">
 
895
    <system_message level="3" line="1" source="test data" type="ERROR">
 
896
        <paragraph>
 
897
            Error parsing content block for the "list-table" directive: exactly one bullet list expected.
 
898
        <literal_block xml:space="preserve">
 
899
            .. list-table::
 
900
            \n\
 
901
               not a bullet list
 
902
"""],
 
903
["""\
 
904
.. list-table::
 
905
 
 
906
   * not a second-level bullet list
 
907
""",
 
908
"""\
 
909
<document source="test data">
 
910
    <system_message level="3" line="1" source="test data" type="ERROR">
 
911
        <paragraph>
 
912
            Error parsing content block for the "list-table" directive: two-level bullet list expected, but row 1 does not contain a second-level bullet list.
 
913
        <literal_block xml:space="preserve">
 
914
            .. list-table::
 
915
            \n\
 
916
               * not a second-level bullet list
 
917
"""],
 
918
["""\
 
919
.. list-table::
 
920
 
 
921
   * - columns not uniform
 
922
   * - first row has one,
 
923
     - second row has two
 
924
""",
 
925
"""\
 
926
<document source="test data">
 
927
    <system_message level="3" line="1" source="test data" type="ERROR">
 
928
        <paragraph>
 
929
            Error parsing content block for the "list-table" directive: uniform two-level bullet list expected, but row 2 does not contain the same number of items as row 1 (2 vs 1).
 
930
        <literal_block xml:space="preserve">
 
931
            .. list-table::
 
932
            \n\
 
933
               * - columns not uniform
 
934
               * - first row has one,
 
935
                 - second row has two
 
936
"""],
 
937
["""\
 
938
.. list-table::
 
939
   :widths: 10 20
 
940
 
 
941
   * - ":widths:" option doesn't match columns
 
942
""",
 
943
"""\
 
944
<document source="test data">
 
945
    <system_message level="3" line="1" source="test data" type="ERROR">
 
946
        <paragraph>
 
947
            "list-table" widths do not match the number of columns in table (1).
 
948
        <literal_block xml:space="preserve">
 
949
            .. list-table::
 
950
               :widths: 10 20
 
951
            \n\
 
952
               * - ":widths:" option doesn\'t match columns
 
953
"""],
 
954
["""\
 
955
.. list-table::
 
956
   :stub-columns: 3
 
957
 
 
958
   * - column 1
 
959
     - column 2
 
960
""",
 
961
"""\
 
962
<document source="test data">
 
963
    <system_message level="3" line="1" source="test data" type="ERROR">
 
964
        <paragraph>
 
965
            3 stub column(s) specified but only 2 columns(s) of data supplied ("list-table" directive).
 
966
        <literal_block xml:space="preserve">
 
967
            .. list-table::
 
968
               :stub-columns: 3
 
969
            \n\
 
970
               * - column 1
 
971
                 - column 2
 
972
"""],
 
973
["""\
 
974
.. list-table::
 
975
   :stub-columns: 2
 
976
 
 
977
   * - column 1
 
978
     - column 2
 
979
""",
 
980
"""\
 
981
<document source="test data">
 
982
    <system_message level="3" line="1" source="test data" type="ERROR">
 
983
        <paragraph>
 
984
            Insufficient data supplied (2 columns(s)); no data remaining for table body, required by "list-table" directive.
 
985
        <literal_block xml:space="preserve">
 
986
            .. list-table::
 
987
               :stub-columns: 2
 
988
            \n\
 
989
               * - column 1
 
990
                 - column 2
 
991
"""],
 
992
]
 
993
 
 
994
 
 
995
if __name__ == '__main__':
 
996
    import unittest
 
997
    unittest.main(defaultTest='suite')