Debian Codegraph @

test/test_parsers/test_rst/test_tables.py

raw symbols SCIP
1 #! /usr/bin/env python3
2
3 # $Id: test_tables.py 10280 2026-01-07 07:51:16Z milde $
4 # Author: David Goodger <[email protected]>
5 # Copyright: This module has been placed in the public domain.
6
7 """
8 Tests for states.py.
9 """
10
11 import os
12
13 from pathlib import Path
14 import sys
15 import unittest
16
17 if __name__ == '__main__':
18 # prepend the "docutils root" to the Python library path
19 # so we import the local `docutils` package.
20 sys.path.insert(0, str(Path(__file__).resolve().parents[3]))
21
22 from docutils.frontend import get_default_settings
23 from docutils.parsers.rst import Parser
24 from docutils.utils import new_document
25
26 # TEST_ROOT is ./test/ from the docutils root
27 TEST_ROOT = os.path.abspath(os.path.join(__file__, '..', '..', '..'))
28
29
30 class ParserTestCase(unittest.TestCase):
31 maxDiff = None
32
33 def test_parser(self):
34 parser = Parser()
35 settings = get_default_settings(Parser)
36 settings.warning_stream = ''
37 settings.halt_level = 5
38 for name, cases in totest.items():
39 for casenum, (case_input, case_expected) in enumerate(cases):
40 with self.subTest(id=f'totest[{name!r}][{casenum}]'):
41 document = new_document('test data', settings.copy())
42 parser.parse(case_input, document)
43 output = document.pformat()
44 self.assertEqual(case_expected, output)
45
46
47 mydir = os.path.join(TEST_ROOT, 'test_parsers/test_rst')
48 include2 = os.path.join(mydir, 'test_directives/include2.rst')
49
50 totest = {}
51
52 totest['grid_tables'] = [
53 ["""\
54 +-------------------------------------+
55 | A table with one cell and one line. |
56 +-------------------------------------+
57 """,
58 """\
59 <document source="test data">
60 <table>
61 <tgroup cols="1">
62 <colspec colwidth="37">
63 <tbody>
64 <row>
65 <entry>
66 <paragraph>
67 A table with one cell and one line.
68 """],
69 ["""\
70 +-----------------------+
71 | A table with one cell |
72 | and two lines. |
73 +-----------------------+
74 """,
75 """\
76 <document source="test data">
77 <table>
78 <tgroup cols="1">
79 <colspec colwidth="23">
80 <tbody>
81 <row>
82 <entry>
83 <paragraph>
84 A table with one cell
85 and two lines.
86 """],
87 ["""\
88 +-----------------------+
89 | A misaligned table. |
90 +-----------------------+
91
92 +-----------------------+
93 | Right border missing.
94 +-----------------------+
95 """,
96 """\
97 <document source="test data">
98 <system_message level="3" line="2" source="test data" type="ERROR">
99 <paragraph>
100 Malformed table.
101 Right border not aligned or missing.
102 <literal_block xml:space="preserve">
103 +-----------------------+
104 | A misaligned table. |
105 +-----------------------+
106 <system_message level="3" line="6" source="test data" type="ERROR">
107 <paragraph>
108 Malformed table.
109 Right border not aligned or missing.
110 <literal_block xml:space="preserve">
111 +-----------------------+
112 | Right border missing.
113 +-----------------------+
114 """],
115 ["""\
116 +-------------------------+
117 | A table with one cell |
118 | and missing bottom. |
119 """,
120 """\
121 <document source="test data">
122 <system_message level="3" line="3" source="test data" type="ERROR">
123 <paragraph>
124 Malformed table.
125 Bottom border missing or corrupt.
126 <literal_block xml:space="preserve">
127 +-------------------------+
128 | A table with one cell |
129 | and missing bottom. |
130 """],
131 ["""\
132 +-------------------------+
133 | A table with one cell |
134 | and corrupt bottom. |
135 +------------------------ +
136 """,
137 """\
138 <document source="test data">
139 <system_message level="3" line="3" source="test data" type="ERROR">
140 <paragraph>
141 Malformed table.
142 Bottom border missing or corrupt.
143 <literal_block xml:space="preserve">
144 +-------------------------+
145 | A table with one cell |
146 | and corrupt bottom. |
147 +------------------------ +
148 """],
149 ["""\
150 +-------------------------+
151 | A table with one cell |
152 | and corrupt bottom. |
153 --------------------------+
154 """,
155 """\
156 <document source="test data">
157 <system_message level="3" line="4" source="test data" type="ERROR">
158 <paragraph>
159 Malformed table.
160 Bottom border missing or corrupt.
161 <literal_block xml:space="preserve">
162 +-------------------------+
163 | A table with one cell |
164 | and corrupt bottom. |
165 <system_message level="2" line="4" source="test data" type="WARNING">
166 <paragraph>
167 Blank line required after table.
168 <paragraph>
169 --------------------------+
170 """],
171 ["""\
172 +------------------------+
173 | A well-formed | table. |
174 +------------------------+
175
176 +------------------------+
177 | This +----------+ too! |
178 +------------------------+
179 """,
180 """\
181 <document source="test data">
182 <table>
183 <tgroup cols="1">
184 <colspec colwidth="24">
185 <tbody>
186 <row>
187 <entry>
188 <paragraph>
189 A well-formed | table.
190 <table>
191 <tgroup cols="1">
192 <colspec colwidth="24">
193 <tbody>
194 <row>
195 <entry>
196 <paragraph>
197 This +----------+ too!
198 """],
199 ["""\
200 +--------------+--------------+
201 | A table with | two columns. |
202 +--------------+--------------+
203 """,
204 """\
205 <document source="test data">
206 <table>
207 <tgroup cols="2">
208 <colspec colwidth="14">
209 <colspec colwidth="14">
210 <tbody>
211 <row>
212 <entry>
213 <paragraph>
214 A table with
215 <entry>
216 <paragraph>
217 two columns.
218 """],
219 ["""\
220 +--------------+
221 | A table with |
222 +--------------+
223 | two rows. |
224 +--------------+
225 """,
226 """\
227 <document source="test data">
228 <table>
229 <tgroup cols="1">
230 <colspec colwidth="14">
231 <tbody>
232 <row>
233 <entry>
234 <paragraph>
235 A table with
236 <row>
237 <entry>
238 <paragraph>
239 two rows.
240 """],
241 ["""\
242 +--------------+-------------+
243 | A table with | two columns |
244 +--------------+-------------+
245 | and | two rows. |
246 +--------------+-------------+
247 """,
248 """\
249 <document source="test data">
250 <table>
251 <tgroup cols="2">
252 <colspec colwidth="14">
253 <colspec colwidth="13">
254 <tbody>
255 <row>
256 <entry>
257 <paragraph>
258 A table with
259 <entry>
260 <paragraph>
261 two columns
262 <row>
263 <entry>
264 <paragraph>
265 and
266 <entry>
267 <paragraph>
268 two rows.
269 """],
270 ["""\
271 +--------------+---------------+
272 | A table with | two columns, |
273 +--------------+---------------+
274 | two rows, and a column span. |
275 +------------------------------+
276 """,
277 """\
278 <document source="test data">
279 <table>
280 <tgroup cols="2">
281 <colspec colwidth="14">
282 <colspec colwidth="15">
283 <tbody>
284 <row>
285 <entry>
286 <paragraph>
287 A table with
288 <entry>
289 <paragraph>
290 two columns,
291 <row>
292 <entry morecols="1">
293 <paragraph>
294 two rows, and a column span.
295 """],
296 ["""\
297 +--------------------------+
298 | A table with three rows, |
299 +------------+-------------+
300 | and two | columns. |
301 +------------+-------------+
302 | First and last rows |
303 | contains column spans. |
304 +--------------------------+
305 """,
306 """\
307 <document source="test data">
308 <table>
309 <tgroup cols="2">
310 <colspec colwidth="12">
311 <colspec colwidth="13">
312 <tbody>
313 <row>
314 <entry morecols="1">
315 <paragraph>
316 A table with three rows,
317 <row>
318 <entry>
319 <paragraph>
320 and two
321 <entry>
322 <paragraph>
323 columns.
324 <row>
325 <entry morecols="1">
326 <paragraph>
327 First and last rows
328 contains column spans.
329 """],
330 ["""\
331 +--------------+--------------+
332 | A table with | two columns, |
333 +--------------+ and a row |
334 | two rows, | span. |
335 +--------------+--------------+
336 """,
337 """\
338 <document source="test data">
339 <table>
340 <tgroup cols="2">
341 <colspec colwidth="14">
342 <colspec colwidth="14">
343 <tbody>
344 <row>
345 <entry>
346 <paragraph>
347 A table with
348 <entry morerows="1">
349 <paragraph>
350 two columns,
351 and a row
352 span.
353 <row>
354 <entry>
355 <paragraph>
356 two rows,
357 """],
358 ["""\
359 +------------+-------------+---------------+
360 | A table | two rows in | and row spans |
361 | with three +-------------+ to left and |
362 | columns, | the middle, | right. |
363 +------------+-------------+---------------+
364 """,
365 """\
366 <document source="test data">
367 <table>
368 <tgroup cols="3">
369 <colspec colwidth="12">
370 <colspec colwidth="13">
371 <colspec colwidth="15">
372 <tbody>
373 <row>
374 <entry morerows="1">
375 <paragraph>
376 A table
377 with three
378 columns,
379 <entry>
380 <paragraph>
381 two rows in
382 <entry morerows="1">
383 <paragraph>
384 and row spans
385 to left and
386 right.
387 <row>
388 <entry>
389 <paragraph>
390 the middle,
391 """],
392 ["""\
393 Complex spanning pattern (no edge knows all rows/cols):
394
395 +-----------+-------------------------+
396 | W/NW cell | N/NE cell |
397 | +-------------+-----------+
398 | | Middle cell | E/SE cell |
399 +-----------+-------------+ |
400 | S/SE cell | |
401 +-------------------------+-----------+
402 """,
403 """\
404 <document source="test data">
405 <paragraph>
406 Complex spanning pattern (no edge knows all rows/cols):
407 <table>
408 <tgroup cols="3">
409 <colspec colwidth="11">
410 <colspec colwidth="13">
411 <colspec colwidth="11">
412 <tbody>
413 <row>
414 <entry morerows="1">
415 <paragraph>
416 W/NW cell
417 <entry morecols="1">
418 <paragraph>
419 N/NE cell
420 <row>
421 <entry>
422 <paragraph>
423 Middle cell
424 <entry morerows="1">
425 <paragraph>
426 E/SE cell
427 <row>
428 <entry morecols="1">
429 <paragraph>
430 S/SE cell
431 """],
432 ["""\
433 +------------------------+------------+----------+----------+
434 | Header row, column 1 | Header 2 | Header 3 | Header 4 |
435 +========================+============+==========+==========+
436 | body row 1, column 1 | column 2 | column 3 | column 4 |
437 +------------------------+------------+----------+----------+
438 | body row 2 | Cells may span columns. |
439 +------------------------+------------+---------------------+
440 | body row 3 | Cells may | - Table cells |
441 +------------------------+ span rows. | - contain |
442 | body row 4 | | - body elements. |
443 +------------------------+------------+---------------------+
444 """,
445 """\
446 <document source="test data">
447 <table>
448 <tgroup cols="4">
449 <colspec colwidth="24">
450 <colspec colwidth="12">
451 <colspec colwidth="10">
452 <colspec colwidth="10">
453 <thead>
454 <row>
455 <entry>
456 <paragraph>
457 Header row, column 1
458 <entry>
459 <paragraph>
460 Header 2
461 <entry>
462 <paragraph>
463 Header 3
464 <entry>
465 <paragraph>
466 Header 4
467 <tbody>
468 <row>
469 <entry>
470 <paragraph>
471 body row 1, column 1
472 <entry>
473 <paragraph>
474 column 2
475 <entry>
476 <paragraph>
477 column 3
478 <entry>
479 <paragraph>
480 column 4
481 <row>
482 <entry>
483 <paragraph>
484 body row 2
485 <entry morecols="2">
486 <paragraph>
487 Cells may span columns.
488 <row>
489 <entry>
490 <paragraph>
491 body row 3
492 <entry morerows="1">
493 <paragraph>
494 Cells may
495 span rows.
496 <entry morecols="1" morerows="1">
497 <bullet_list bullet="-">
498 <list_item>
499 <paragraph>
500 Table cells
501 <list_item>
502 <paragraph>
503 contain
504 <list_item>
505 <paragraph>
506 body elements.
507 <row>
508 <entry>
509 <paragraph>
510 body row 4
511 """],
512 ["""\
513 +-----------------+--------+
514 | A simple table | cell 2 |
515 +-----------------+--------+
516 | cell 3 | cell 4 |
517 +-----------------+--------+
518 No blank line after table.
519 """,
520 """\
521 <document source="test data">
522 <table>
523 <tgroup cols="2">
524 <colspec colwidth="17">
525 <colspec colwidth="8">
526 <tbody>
527 <row>
528 <entry>
529 <paragraph>
530 A simple table
531 <entry>
532 <paragraph>
533 cell 2
534 <row>
535 <entry>
536 <paragraph>
537 cell 3
538 <entry>
539 <paragraph>
540 cell 4
541 <system_message level="2" line="6" source="test data" type="WARNING">
542 <paragraph>
543 Blank line required after table.
544 <paragraph>
545 No blank line after table.
546 """],
547 ["""\
548 +-----------------+--------+
549 | A simple table | cell 2 |
550 +-----------------+--------+
551 | cell 3 | cell 4 |
552 +-----------------+--------+
553 Unexpected indent and no blank line after table.
554 """,
555 """\
556 <document source="test data">
557 <table>
558 <tgroup cols="2">
559 <colspec colwidth="17">
560 <colspec colwidth="8">
561 <tbody>
562 <row>
563 <entry>
564 <paragraph>
565 A simple table
566 <entry>
567 <paragraph>
568 cell 2
569 <row>
570 <entry>
571 <paragraph>
572 cell 3
573 <entry>
574 <paragraph>
575 cell 4
576 <system_message level="3" line="6" source="test data" type="ERROR">
577 <paragraph>
578 Unexpected indentation.
579 <system_message level="2" line="6" source="test data" type="WARNING">
580 <paragraph>
581 Blank line required after table.
582 <block_quote>
583 <paragraph>
584 Unexpected indent and no blank line after table.
585 """],
586 ["""\
587 +--------------+-------------+
588 | A bad table. | |
589 +--------------+ |
590 | Cells must be rectangles. |
591 +----------------------------+
592 """,
593 """\
594 <document source="test data">
595 <system_message level="3" line="1" source="test data" type="ERROR">
596 <paragraph>
597 Malformed table.
598 Malformed table; parse incomplete.
599 <literal_block xml:space="preserve">
600 +--------------+-------------+
601 | A bad table. | |
602 +--------------+ |
603 | Cells must be rectangles. |
604 +----------------------------+
605 """],
606 ["""\
607 +------------------------------+
608 | This table contains another. |
609 | |
610 | +-------------------------+ |
611 | | A table within a table. | |
612 | +-------------------------+ |
613 +------------------------------+
614 """,
615 """\
616 <document source="test data">
617 <table>
618 <tgroup cols="1">
619 <colspec colwidth="30">
620 <tbody>
621 <row>
622 <entry>
623 <paragraph>
624 This table contains another.
625 <table>
626 <tgroup cols="1">
627 <colspec colwidth="25">
628 <tbody>
629 <row>
630 <entry>
631 <paragraph>
632 A table within a table.
633 """],
634 ["""\
635 +------------------+--------+
636 | A simple table | |
637 +------------------+--------+
638 | with empty cells | |
639 +------------------+--------+
640 """,
641 """\
642 <document source="test data">
643 <table>
644 <tgroup cols="2">
645 <colspec colwidth="18">
646 <colspec colwidth="8">
647 <tbody>
648 <row>
649 <entry>
650 <paragraph>
651 A simple table
652 <entry>
653 <row>
654 <entry>
655 <paragraph>
656 with empty cells
657 <entry>
658 """],
659 [("""\
660 +------------------------------------------------------------------------------+
661 | .. include:: |
662 %s
663 +------------------------------------------------------------------------------+
664 | (The first cell of this table may expand |
665 | to accommodate long filesystem paths.) |
666 +------------------------------------------------------------------------------+
667 """) % ('\n'.join('| %-70s |' % include2[part * 70 : (part + 1) * 70] # noqa: E203
668 for part in range(len(include2) // 70 + 1))),
669 """\
670 <document source="test data">
671 <table>
672 <tgroup cols="1">
673 <colspec colwidth="78">
674 <tbody>
675 <row>
676 <entry>
677 <paragraph>
678 Here are some paragraphs
679 that can appear at any level.
680 <paragraph>
681 This file (include2.rst) is used by
682 <literal>
683 test_include.py
684 .
685 <row>
686 <entry>
687 <paragraph>
688 (The first cell of this table may expand
689 to accommodate long filesystem paths.)
690 """],
691 [("""\
692 Something before.
693
694 +------------------------------------------------------------------------------+
695 | .. include:: |
696 %s
697 +------------------------------------------------------------------------------+
698
699 Something afterwards.
700
701 And more.
702 """) % ('\n'.join('| %-70s |' % include2[part * 70 : (part + 1) * 70] # noqa: E203
703 for part in range(len(include2) // 70 + 1))),
704 """\
705 <document source="test data">
706 <paragraph>
707 Something before.
708 <table>
709 <tgroup cols="1">
710 <colspec colwidth="78">
711 <tbody>
712 <row>
713 <entry>
714 <paragraph>
715 Here are some paragraphs
716 that can appear at any level.
717 <paragraph>
718 This file (include2.rst) is used by
719 <literal>
720 test_include.py
721 .
722 <paragraph>
723 Something afterwards.
724 <paragraph>
725 And more.
726 """],
727 ]
728
729 totest['simple_tables'] = [
730 ["""\
731 ============ ============
732 A table with two columns.
733 ============ ============
734
735 Paragraph.
736 """,
737 """\
738 <document source="test data">
739 <table>
740 <tgroup cols="2">
741 <colspec colwidth="12">
742 <colspec colwidth="12">
743 <tbody>
744 <row>
745 <entry>
746 <paragraph>
747 A table with
748 <entry>
749 <paragraph>
750 two columns.
751 <paragraph>
752 Paragraph.
753 """],
754 ["""\
755 ================================= ========
756 The ERROR should point to line 2. .. tip::
757 ================================= ========
758 """,
759 """\
760 <document source="test data">
761 <table>
762 <tgroup cols="2">
763 <colspec colwidth="33">
764 <colspec colwidth="8">
765 <tbody>
766 <row>
767 <entry>
768 <paragraph>
769 The ERROR should point to line 2.
770 <entry>
771 <system_message level="3" line="2" source="test data" type="ERROR">
772 <paragraph>
773 Content block expected for the "tip" directive; none found.
774 <literal_block xml:space="preserve">
775 .. tip::
776 """],
777 ["""\
778 ============ ============
779 A table with two columns
780 and two rows.
781 ============ ============
782 """,
783 """\
784 <document source="test data">
785 <table>
786 <tgroup cols="2">
787 <colspec colwidth="12">
788 <colspec colwidth="12">
789 <tbody>
790 <row>
791 <entry>
792 <paragraph>
793 A table with
794 <entry>
795 <paragraph>
796 two columns
797 <row>
798 <entry>
799 <paragraph>
800 and
801 <entry>
802 <paragraph>
803 two rows.
804 """],
805 ["""\
806 ============ ==============
807 A table with two columns,
808 two rows, and a column span.
809 ============================
810 """,
811 """\
812 <document source="test data">
813 <table>
814 <tgroup cols="2">
815 <colspec colwidth="12">
816 <colspec colwidth="14">
817 <tbody>
818 <row>
819 <entry>
820 <paragraph>
821 A table with
822 <entry>
823 <paragraph>
824 two columns,
825 <row>
826 <entry morecols="1">
827 <paragraph>
828 two rows, and a column span.
829 """],
830 ["""\
831 == =========== ===========
832 1 A table with three rows,
833 -- ------------------------
834 2 and three columns.
835 3 First and third rows
836 contain column spans.
837
838 This row is a multi-line row, and overflows to the right.
839 -- ------------------------
840 4 One last row.
841 == =========== ===========
842 """,
843 """\
844 <document source="test data">
845 <table>
846 <tgroup cols="3">
847 <colspec colwidth="2">
848 <colspec colwidth="11">
849 <colspec colwidth="44">
850 <tbody>
851 <row>
852 <entry>
853 <paragraph>
854 1
855 <entry morecols="1">
856 <paragraph>
857 A table with three rows,
858 <row>
859 <entry>
860 <paragraph>
861 2
862 <entry>
863 <paragraph>
864 and three
865 <entry>
866 <paragraph>
867 columns.
868 <row>
869 <entry>
870 <paragraph>
871 3
872 <entry morecols="1">
873 <paragraph>
874 First and third rows
875 contain column spans.
876 <paragraph>
877 This row is a multi-line row, and overflows to the right.
878 <row>
879 <entry>
880 <paragraph>
881 4
882 <entry>
883 <paragraph>
884 One last
885 <entry>
886 <paragraph>
887 row.
888 """],
889 ["""\
890 ======= ========= ========
891 A table with three columns.
892 ================== ========
893 """,
894 """\
895 <document source="test data">
896 <table>
897 <tgroup cols="3">
898 <colspec colwidth="7">
899 <colspec colwidth="9">
900 <colspec colwidth="8">
901 <tbody>
902 <row>
903 <entry morecols="1">
904 <paragraph>
905 A table with three
906 <entry>
907 <paragraph>
908 columns.
909 """],
910 ["""\
911 ============== ======
912 A simple table this text extends to the right
913 cell 3 as does this text
914 ============== ======
915 """,
916 """\
917 <document source="test data">
918 <table>
919 <tgroup cols="2">
920 <colspec colwidth="14">
921 <colspec colwidth="30">
922 <tbody>
923 <row>
924 <entry>
925 <paragraph>
926 A simple table
927 <entry>
928 <paragraph>
929 this text extends to the right
930 <row>
931 <entry>
932 <paragraph>
933 cell 3
934 <entry>
935 <paragraph>
936 as does this text
937 """],
938 ["""\
939 ============== ======
940 A simple table this text extends to the right
941 continuation of cell 2
942 ============== ======
943 """,
944 """\
945 <document source="test data">
946 <table>
947 <tgroup cols="2">
948 <colspec colwidth="14">
949 <colspec colwidth="30">
950 <tbody>
951 <row>
952 <entry>
953 <paragraph>
954 A simple table
955 <entry>
956 <paragraph>
957 this text extends to the right
958 continuation of cell 2
959 """],
960 ["""\
961 ============== ======
962 A simple table with
963 no bottom border
964 """,
965 """\
966 <document source="test data">
967 <system_message level="3" line="1" source="test data" type="ERROR">
968 <paragraph>
969 Malformed table.
970 No bottom table border found.
971 <literal_block xml:space="preserve">
972 ============== ======
973 A simple table with
974 no bottom border
975 """],
976 ["""\
977 ============== ======
978 A simple table cell 2
979 ============== ======
980 this could be cell content
981 or text after the table
982 """,
983 """\
984 <document source="test data">
985 <system_message level="3" line="1" source="test data" type="ERROR">
986 <paragraph>
987 Malformed table.
988 No bottom table border found or no blank line after table bottom.
989 <literal_block xml:space="preserve">
990 ============== ======
991 A simple table cell 2
992 ============== ======
993 <system_message level="2" line="4" source="test data" type="WARNING">
994 <paragraph>
995 Blank line required after table.
996 <paragraph>
997 this could be cell content
998 or text after the table
999 """],
1000 ["""\
1001 ============== ======
1002 A simple table cell 2
1003 ============== ======
1004 cell 3 cell 4
1005 ============== ======
1006 No blank line after table.
1007 """,
1008 """\
1009 <document source="test data">
1010 <table>
1011 <tgroup cols="2">
1012 <colspec colwidth="14">
1013 <colspec colwidth="6">
1014 <thead>
1015 <row>
1016 <entry>
1017 <paragraph>
1018 A simple table
1019 <entry>
1020 <paragraph>
1021 cell 2
1022 <tbody>
1023 <row>
1024 <entry>
1025 <paragraph>
1026 cell 3
1027 <entry>
1028 <paragraph>
1029 cell 4
1030 <system_message level="2" line="6" source="test data" type="WARNING">
1031 <paragraph>
1032 Blank line required after table.
1033 <paragraph>
1034 No blank line after table.
1035 """],
1036 ["""\
1037 ============== ======
1038 A simple table cell 2
1039 cell 3 cell 4
1040 ============== ======
1041 Unexpected indent and no blank line after table.
1042 """,
1043 """\
1044 <document source="test data">
1045 <system_message level="3" line="1" source="test data" type="ERROR">
1046 <paragraph>
1047 Malformed table.
1048 No bottom table border found or no blank line after table bottom.
1049 <literal_block xml:space="preserve">
1050 ============== ======
1051 A simple table cell 2
1052 cell 3 cell 4
1053 ============== ======
1054 <system_message level="2" line="5" source="test data" type="WARNING">
1055 <paragraph>
1056 Blank line required after table.
1057 <block_quote>
1058 <paragraph>
1059 Unexpected indent and no blank line after table.
1060 """],
1061 ["""\
1062 ============== ======
1063 A bad table cell 2
1064 cell 3 cell 4
1065 ============ ========
1066 """,
1067 """\
1068 <document source="test data">
1069 <system_message level="3" line="4" source="test data" type="ERROR">
1070 <paragraph>
1071 Malformed table.
1072 Column span alignment problem in table line 4.
1073 <literal_block xml:space="preserve">
1074 ============== ======
1075 A bad table cell 2
1076 cell 3 cell 4
1077 ============ ========
1078 """],
1079 ["""\
1080 ======== =========
1081 A bad table cell 2
1082 cell 3 cell 4
1083 ======== =========
1084 """,
1085 """\
1086 <document source="test data">
1087 <system_message level="3" line="2" source="test data" type="ERROR">
1088 <paragraph>
1089 Malformed table.
1090 Text in column margin in table line 2.
1091 <literal_block xml:space="preserve">
1092 ======== =========
1093 A bad table cell 2
1094 cell 3 cell 4
1095 ======== =========
1096 """],
1097 ["""\
1098 == ============================
1099 1 This table contains another.
1100 2 ======= ====== ========
1101 A table within a table.
1102 ======= ====== ========
1103
1104 The outer table does have to
1105 have at least two columns
1106 though.
1107 == ============================
1108 """,
1109 """\
1110 <document source="test data">
1111 <table>
1112 <tgroup cols="2">
1113 <colspec colwidth="2">
1114 <colspec colwidth="28">
1115 <tbody>
1116 <row>
1117 <entry>
1118 <paragraph>
1119 1
1120 <entry>
1121 <paragraph>
1122 This table contains another.
1123 <row>
1124 <entry>
1125 <paragraph>
1126 2
1127 <entry>
1128 <table>
1129 <tgroup cols="3">
1130 <colspec colwidth="7">
1131 <colspec colwidth="6">
1132 <colspec colwidth="8">
1133 <tbody>
1134 <row>
1135 <entry>
1136 <paragraph>
1137 A table
1138 <entry>
1139 <paragraph>
1140 within
1141 <entry>
1142 <paragraph>
1143 a table.
1144 <paragraph>
1145 The outer table does have to
1146 have at least two columns
1147 though.
1148 """],
1149 ["""\
1150 ================ ======
1151 A simple table
1152 with empty cells
1153 ================ ======
1154 """,
1155 """\
1156 <document source="test data">
1157 <table>
1158 <tgroup cols="2">
1159 <colspec colwidth="16">
1160 <colspec colwidth="6">
1161 <tbody>
1162 <row>
1163 <entry>
1164 <paragraph>
1165 A simple table
1166 <entry>
1167 <row>
1168 <entry>
1169 <paragraph>
1170 with empty cells
1171 <entry>
1172 """],
1173 ["""\
1174 ============== ========
1175 A table with
1176 ============== ========
1177 centered cells.
1178
1179 ============== ========
1180 """,
1181 """\
1182 <document source="test data">
1183 <table>
1184 <tgroup cols="2">
1185 <colspec colwidth="14">
1186 <colspec colwidth="8">
1187 <thead>
1188 <row>
1189 <entry>
1190 <paragraph>
1191 A table
1192 <entry>
1193 <paragraph>
1194 with
1195 <tbody>
1196 <row>
1197 <entry>
1198 <paragraph>
1199 centered
1200 <entry>
1201 <paragraph>
1202 cells.
1203 """],
1204 ["""\
1205 ============== ======
1206 A simple table this text extends to the right
1207 cell 3 the bottom border below is too long
1208 ============== ========
1209 """,
1210 """\
1211 <document source="test data">
1212 <system_message level="3" line="4" source="test data" type="ERROR">
1213 <paragraph>
1214 Malformed table.
1215 Bottom border or header rule does not match top border.
1216 <literal_block xml:space="preserve">
1217 ============== ======
1218 A simple table this text extends to the right
1219 cell 3 the bottom border below is too long
1220 ============== ========
1221 """],
1222 ["""\
1223 ============ =================
1224 A table with row separators.
1225 ------------ -----------------
1226
1227 Blank line before.
1228 ------------ -----------------
1229
1230 Blank lines before and after.
1231
1232 ------------ -----------------
1233 Blank line after.
1234
1235 ============ =================
1236 """,
1237 """\
1238 <document source="test data">
1239 <table>
1240 <tgroup cols="2">
1241 <colspec colwidth="12">
1242 <colspec colwidth="17">
1243 <tbody>
1244 <row>
1245 <entry>
1246 <paragraph>
1247 A table with
1248 <entry>
1249 <paragraph>
1250 row separators.
1251 <row>
1252 <entry>
1253 <paragraph>
1254 Blank line
1255 <entry>
1256 <paragraph>
1257 before.
1258 <row>
1259 <entry>
1260 <paragraph>
1261 Blank lines
1262 <entry>
1263 <paragraph>
1264 before and after.
1265 <row>
1266 <entry>
1267 <paragraph>
1268 Blank line
1269 <entry>
1270 <paragraph>
1271 after.
1272 """],
1273 ["""\
1274 ============ ====================
1275 A table with many row separators.
1276 ------------ --------------------
1277 ------------ --------------------
1278
1279 ------------ --------------------
1280 ============ ====================
1281 """,
1282 """\
1283 <document source="test data">
1284 <table>
1285 <tgroup cols="2">
1286 <colspec colwidth="12">
1287 <colspec colwidth="20">
1288 <tbody>
1289 <row>
1290 <entry>
1291 <paragraph>
1292 A table with
1293 <entry>
1294 <paragraph>
1295 many row separators.
1296 <row>
1297 <entry>
1298 <entry>
1299 <row>
1300 <entry>
1301 <entry>
1302 <row>
1303 <entry>
1304 <entry>
1305 """],
1306 ["""\
1307 == =========== ===========
1308 1 Span columns 2 & 3
1309 -- ------------------------
1310 2 Span columns 2 & 3
1311 ------------------------
1312 3
1313 == =========== ===========
1314
1315 == =========== ===========
1316 1 Span cols 1&2 but not 3
1317 --------------- -----------
1318 2 Span cols 1&2 but not 3
1319 ---------------
1320 3 no spans here
1321 == =========== ===========
1322
1323 == =========== ===========
1324 1 Not a span Not a span
1325 ----------- -----------
1326 2
1327 == =========== ===========
1328 """,
1329 """\
1330 <document source="test data">
1331 <system_message level="3" line="4" source="test data" type="ERROR">
1332 <paragraph>
1333 Malformed table.
1334 Text in column margin in table line 4.
1335 <literal_block xml:space="preserve">
1336 == =========== ===========
1337 1 Span columns 2 & 3
1338 -- ------------------------
1339 2 Span columns 2 & 3
1340 ------------------------
1341 3
1342 == =========== ===========
1343 <system_message level="3" line="13" source="test data" type="ERROR">
1344 <paragraph>
1345 Malformed table.
1346 Column span incomplete in table line 5.
1347 <literal_block xml:space="preserve">
1348 == =========== ===========
1349 1 Span cols 1&2 but not 3
1350 --------------- -----------
1351 2 Span cols 1&2 but not 3
1352 ---------------
1353 3 no spans here
1354 == =========== ===========
1355 <table>
1356 <tgroup cols="3">
1357 <colspec colwidth="2">
1358 <colspec colwidth="11">
1359 <colspec colwidth="11">
1360 <tbody>
1361 <row>
1362 <entry>
1363 <paragraph>
1364 1
1365 <entry>
1366 <system_message level="3" line="19" source="test data" type="ERROR">
1367 <paragraph>
1368 Unexpected section title.
1369 <literal_block xml:space="preserve">
1370 Not a span
1371 -----------
1372 <entry>
1373 <system_message level="3" line="19" source="test data" type="ERROR">
1374 <paragraph>
1375 Unexpected section title.
1376 <literal_block xml:space="preserve">
1377 Not a span
1378 -----------
1379 <row>
1380 <entry>
1381 <paragraph>
1382 2
1383 <entry>
1384 <entry>
1385 """],
1386 ["""\
1387 ========= =====================================================================
1388 Inclusion .. include::
1389 %s
1390 Note The first row of this table may expand
1391 to accommodate long filesystem paths.
1392 ========= =====================================================================
1393 """ % ('\n'.join(' %-65s' % include2[part * 65 : (part + 1) * 65] # noqa: E203
1394 for part in range(len(include2) // 65 + 1))),
1395 """\
1396 <document source="test data">
1397 <table>
1398 <tgroup cols="2">
1399 <colspec colwidth="9">
1400 <colspec colwidth="69">
1401 <tbody>
1402 <row>
1403 <entry>
1404 <paragraph>
1405 Inclusion
1406 <entry>
1407 <paragraph>
1408 Here are some paragraphs
1409 that can appear at any level.
1410 <paragraph>
1411 This file (include2.rst) is used by
1412 <literal>
1413 test_include.py
1414 .
1415 <row>
1416 <entry>
1417 <paragraph>
1418 Note
1419 <entry>
1420 <paragraph>
1421 The first row of this table may expand
1422 to accommodate long filesystem paths.
1423 """],
1424 ]
1425
1426
1427 if __name__ == '__main__':
1428 unittest.main()