#! /usr/bin/env python # $Id: test_tables.py 7313 2012-01-11 20:28:57Z milde $ # Author: David Goodger # Copyright: This module has been placed in the public domain. """ Tests for states.py. """ import os from .__init__ import DocutilsTestSupport def suite(): s = DocutilsTestSupport.ParserTestSuite() s.generateTests(totest) return s mydir = 'test_parsers/test_rst/' include2 = os.path.join(mydir, 'test_directives/include2.txt') totest = {} totest['grid_tables'] = [ ["""\ +-------------------------------------+ | A table with one cell and one line. | +-------------------------------------+ """, """\ A table with one cell and one line. """], ["""\ +-----------------------+ | A table with one cell | | and two lines. | +-----------------------+ """, """\
A table with one cell and two lines. """], ["""\ +-----------------------+ | A malformed table. | +-----------------------+ """, """\ Malformed table. +-----------------------+ | A malformed table. | +-----------------------+ """], ["""\ +------------------------+ | A well-formed | table. | +------------------------+ +------------------------+ | This +----------+ too! | +------------------------+ """, """\
A well-formed | table.
This +----------+ too! """], ["""\ +--------------+--------------+ | A table with | two columns. | +--------------+--------------+ """, """\
A table with two columns. """], ["""\ +--------------+ | A table with | +--------------+ | two rows. | +--------------+ """, """\
A table with two rows. """], ["""\ +--------------+-------------+ | A table with | two columns | +--------------+-------------+ | and | two rows. | +--------------+-------------+ """, """\
A table with two columns and two rows. """], ["""\ +--------------+---------------+ | A table with | two columns, | +--------------+---------------+ | two rows, and a column span. | +------------------------------+ """, """\
A table with two columns, two rows, and a column span. """], ["""\ +--------------------------+ | A table with three rows, | +------------+-------------+ | and two | columns. | +------------+-------------+ | First and last rows | | contains column spans. | +--------------------------+ """, """\
A table with three rows, and two columns. First and last rows contains column spans. """], ["""\ +--------------+--------------+ | A table with | two columns, | +--------------+ and a row | | two rows, | span. | +--------------+--------------+ """, """\
A table with two columns, and a row span. two rows, """], ["""\ +------------+-------------+---------------+ | A table | two rows in | and row spans | | with three +-------------+ to left and | | columns, | the middle, | right. | +------------+-------------+---------------+ """, """\
A table with three columns, two rows in and row spans to left and right. the middle, """], ["""\ Complex spanning pattern (no edge knows all rows/cols): +-----------+-------------------------+ | W/NW cell | N/NE cell | | +-------------+-----------+ | | Middle cell | E/SE cell | +-----------+-------------+ | | S/SE cell | | +-------------------------+-----------+ """, """\ Complex spanning pattern (no edge knows all rows/cols):
W/NW cell N/NE cell Middle cell E/SE cell S/SE cell """], ["""\ +------------------------+------------+----------+----------+ | Header row, column 1 | Header 2 | Header 3 | Header 4 | +========================+============+==========+==========+ | body row 1, column 1 | column 2 | column 3 | column 4 | +------------------------+------------+----------+----------+ | body row 2 | Cells may span columns. | +------------------------+------------+---------------------+ | body row 3 | Cells may | - Table cells | +------------------------+ span rows. | - contain | | body row 4 | | - body elements. | +------------------------+------------+---------------------+ """, """\
Header row, column 1 Header 2 Header 3 Header 4 body row 1, column 1 column 2 column 3 column 4 body row 2 Cells may span columns. body row 3 Cells may span rows. Table cells contain body elements. body row 4 """], ["""\ +-----------------+--------+ | A simple table | cell 2 | +-----------------+--------+ | cell 3 | cell 4 | +-----------------+--------+ No blank line after table. """, """\
A simple table cell 2 cell 3 cell 4 Blank line required after table. No blank line after table. """], ["""\ +-----------------+--------+ | A simple table | cell 2 | +-----------------+--------+ | cell 3 | cell 4 | +-----------------+--------+ Unexpected indent and no blank line after table. """, """\
A simple table cell 2 cell 3 cell 4 Unexpected indentation. Blank line required after table. Unexpected indent and no blank line after table. """], ["""\ +--------------+-------------+ | A bad table. | | +--------------+ | | Cells must be rectangles. | +----------------------------+ """, """\ Malformed table. Malformed table; parse incomplete. +--------------+-------------+ | A bad table. | | +--------------+ | | Cells must be rectangles. | +----------------------------+ """], ["""\ +------------------------------+ | This table contains another. | | | | +-------------------------+ | | | A table within a table. | | | +-------------------------+ | +------------------------------+ """, """\
This table contains another.
A table within a table. """], ["""\ +------------------+--------+ | A simple table | | +------------------+--------+ | with empty cells | | +------------------+--------+ """, """\
A simple table with empty cells """], [("""\ +------------------------------------------------------------------------------+ | .. include:: | %s +------------------------------------------------------------------------------+ | (The first cell of this table may expand | | to accommodate long filesystem paths.) | +------------------------------------------------------------------------------+ """) % ('\n'.join(['| %-70s |' % include2[part * 70 : (part + 1) * 70] for part in range(len(include2) // 70 + 1)])), """\
Here are some paragraphs that can appear at any level. This file (include2.txt) is used by test_include.py . (The first cell of this table may expand to accommodate long filesystem paths.) """], [("""\ Something before. +------------------------------------------------------------------------------+ | .. include:: | %s +------------------------------------------------------------------------------+ Something afterwards. And more. """) % ('\n'.join(['| %-70s |' % include2[part * 70 : (part + 1) * 70] for part in range(len(include2) // 70 + 1)])), """\ Something before.
Here are some paragraphs that can appear at any level. This file (include2.txt) is used by test_include.py . Something afterwards. And more. """], ] totest['simple_tables'] = [ ["""\ ============ ============ A table with two columns. ============ ============ Paragraph. """, """\
A table with two columns. Paragraph. """], ["""\ ============ ============ A table with two columns and two rows. ============ ============ """, """\
A table with two columns and two rows. """], ["""\ ============ ============== A table with two columns, two rows, and a column span. ============================ """, """\
A table with two columns, two rows, and a column span. """], ["""\ == =========== =========== 1 A table with three rows, -- ------------------------ 2 and three columns. 3 First and third rows contain column spans. This row is a multi-line row, and overflows to the right. -- ------------------------ 4 One last row. == =========== =========== """, """\
1 A table with three rows, 2 and three columns. 3 First and third rows contain column spans. This row is a multi-line row, and overflows to the right. 4 One last row. """], ["""\ ======= ========= ======== A table with three columns. ================== ======== """, """\
A table with three columns. """], ["""\ ============== ====== A simple table with no bottom border """, """\ Malformed table. No bottom table border found. ============== ====== A simple table with no bottom border """], ["""\ ============== ====== A simple table cell 2 cell 3 cell 4 ============== ====== No blank line after table. """, """\ Malformed table. No bottom table border found or no blank line after table bottom. ============== ====== A simple table cell 2 cell 3 cell 4 ============== ====== Blank line required after table. No blank line after table. """], ["""\ ============== ====== A simple table cell 2 ============== ====== cell 3 cell 4 ============== ====== No blank line after table. """, """\
A simple table cell 2 cell 3 cell 4 Blank line required after table. No blank line after table. """], ["""\ ============== ====== A simple table cell 2 cell 3 cell 4 ============== ====== Unexpected indent and no blank line after table. """, """\ Malformed table. No bottom table border found or no blank line after table bottom. ============== ====== A simple table cell 2 cell 3 cell 4 ============== ====== Blank line required after table. Unexpected indent and no blank line after table. """], ["""\ ============== ====== A bad table cell 2 cell 3 cell 4 ============ ======== """, """\ Malformed table. Column span alignment problem in table line 4. ============== ====== A bad table cell 2 cell 3 cell 4 ============ ======== """], ["""\ ======== ========= A bad table cell 2 cell 3 cell 4 ======== ========= """, """\ Malformed table. Text in column margin in table line 2. ======== ========= A bad table cell 2 cell 3 cell 4 ======== ========= """], ["""\ == ============================ 1 This table contains another. 2 ======= ====== ======== A table within a table. ======= ====== ======== The outer table does have to have at least two columns though. == ============================ """, """\
1 This table contains another. 2
A table within a table. The outer table does have to have at least two columns though. """], ["""\ ================ ====== A simple table with empty cells ================ ====== """, """\
A simple table with empty cells """], ["""\ ============== ======== A table with ============== ======== centered cells. ============== ======== """, """\
A table with centered cells. """], ["""\ ============== ====== A simple table this text extends to the right cell 3 the bottom border below is too long ============== ======== """, """\ Malformed table. Bottom/header table border does not match top border. ============== ====== A simple table this text extends to the right cell 3 the bottom border below is too long ============== ======== """], ["""\ ============ ================= A table with row separators. ------------ ----------------- Blank line before. ------------ ----------------- Blank lines before and after. ------------ ----------------- Blank line after. ============ ================= """, """\
A table with row separators. Blank line before. Blank lines before and after. Blank line after. """], ["""\ ============ ==================== A table with many row separators. ------------ -------------------- ------------ -------------------- ------------ -------------------- ============ ==================== """, """\
A table with many row separators. """], ["""\ == =========== =========== 1 Span columns 2 & 3 -- ------------------------ 2 Span columns 2 & 3 ------------------------ 3 == =========== =========== == =========== =========== 1 Span cols 1&2 but not 3 --------------- ----------- 2 Span cols 1&2 but not 3 --------------- 3 no spans here == =========== =========== == =========== =========== 1 Not a span Not a span ----------- ----------- 2 == =========== =========== """, """\ Malformed table. Text in column margin in table line 4. == =========== =========== 1 Span columns 2 & 3 -- ------------------------ 2 Span columns 2 & 3 ------------------------ 3 == =========== =========== Malformed table. Column span incomplete in table line 5. == =========== =========== 1 Span cols 1&2 but not 3 --------------- ----------- 2 Span cols 1&2 but not 3 --------------- 3 no spans here == =========== ===========
1 Unexpected section title. Not a span ----------- Unexpected section title. Not a span ----------- 2 """], ["""\ ========= ===================================================================== Inclusion .. include:: %s Note The first row of this table may expand to accommodate long filesystem paths. ========= ===================================================================== """ % ('\n'.join([' %-65s' % include2[part * 65 : (part + 1) * 65] for part in range(len(include2) // 65 + 1)])), """\
Inclusion Here are some paragraphs that can appear at any level. This file (include2.txt) is used by test_include.py . Note The first row of this table may expand to accommodate long filesystem paths. """], ] if __name__ == '__main__': import unittest unittest.main(defaultTest='suite')