~ubuntu-branches/ubuntu/saucy/python-docutils/saucy-proposed

« back to all changes in this revision

Viewing changes to .pc/unknown-url-exc-use-repr.diff/test/test_parsers/test_rst/test_directives/test_tables.py

  • Committer: Package Import Robot
  • Author(s): Dmitry Shachnev
  • Date: 2013-05-17 16:47:30 UTC
  • mfrom: (20.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20130517164730-5ux7p59z0jdku6pf
Tags: 0.10-3ubuntu1
* Merge with Debian unstable, remaining changes:
  - Use dh_python2 instead of dh_pysupport.
  - Backport patch to support embedded aliases in references
    (support-aliases-in-references.diff).
* disable_py33_failing_tests.diff: dropped, the issue is now
  properly fixed in Debian.

Show diffs side-by-side

added added

removed removed

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