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