Refactor test_latex_table

This commit is contained in:
Takeshi KOMIYA 2017-05-11 18:23:38 +09:00
parent d7d7a1cff9
commit 515e3ad13d
22 changed files with 941 additions and 137 deletions

View File

@ -0,0 +1,57 @@
\label{\detokenize{complex:complex-spanning-cell}}
table having …
\begin{itemize}
\item {}
consecutive multirow at top of row (1-1 and 1-2)
\item {}
consecutive multirow at end of row (1-4 and 1-5)
\end{itemize}
\begin{savenotes}\sphinxattablestart
\centering
\begin{tabulary}{\linewidth}[t]{|T|T|T|T|T|}
\hline
\sphinxmultirow{3}{1}{%
\begin{varwidth}[t]{\sphinxcolwidth{1}{5}}
cell1-1
\par
\vskip-\baselineskip\strut\end{varwidth}%
}%
&\sphinxmultirow{3}{2}{%
\begin{varwidth}[t]{\sphinxcolwidth{1}{5}}
cell1-2
\par
\vskip-\baselineskip\strut\end{varwidth}%
}%
&
cell1-3
&\sphinxmultirow{3}{4}{%
\begin{varwidth}[t]{\sphinxcolwidth{1}{5}}
cell1-4
\par
\vskip-\baselineskip\strut\end{varwidth}%
}%
&\sphinxmultirow{2}{5}{%
\begin{varwidth}[t]{\sphinxcolwidth{1}{5}}
cell1-5
\par
\vskip-\baselineskip\strut\end{varwidth}%
}%
\\
\cline{3-3}\sphinxtablestrut{1}&\sphinxtablestrut{2}&\sphinxmultirow{2}{6}{%
\begin{varwidth}[t]{\sphinxcolwidth{1}{5}}
cell2-3
\par
\vskip-\baselineskip\strut\end{varwidth}%
}%
&\sphinxtablestrut{4}&\sphinxtablestrut{5}\\
\cline{5-5}\sphinxtablestrut{1}&\sphinxtablestrut{2}&\sphinxtablestrut{6}&\sphinxtablestrut{4}&
cell3-5
\\
\hline
\end{tabulary}
\par
\sphinxattableend\end{savenotes}

View File

@ -0,0 +1,56 @@
\label{\detokenize{complex:grid-table}}
\begin{savenotes}\sphinxattablestart
\centering
\begin{tabulary}{\linewidth}[t]{|T|T|T|}
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header3
\unskip}\relax \\
\hline
cell1-1
&\sphinxmultirow{2}{5}{%
\begin{varwidth}[t]{\sphinxcolwidth{1}{3}}
cell1-2
\par
\vskip-\baselineskip\strut\end{varwidth}%
}%
&
cell1-3
\\
\cline{1-1}\cline{3-3}\sphinxmultirow{2}{7}{%
\begin{varwidth}[t]{\sphinxcolwidth{1}{3}}
cell2-1
\par
\vskip-\baselineskip\strut\end{varwidth}%
}%
&\sphinxtablestrut{5}&
cell2-3
\\
\cline{2-3}\sphinxtablestrut{7}&\sphinxstartmulticolumn{2}%
\sphinxmultirow{2}{9}{%
\begin{varwidth}[t]{\sphinxcolwidth{2}{3}}
cell3-2
\par
\vskip-\baselineskip\strut\end{varwidth}%
}%
\sphinxstopmulticolumn
\\
\cline{1-1}
cell4-1
&\multicolumn{2}{l|}{\sphinxtablestrut{9}}\\
\hline\sphinxstartmulticolumn{3}%
\begin{varwidth}[t]{\sphinxcolwidth{3}{3}}
cell5-1
\par
\vskip-\baselineskip\strut\end{varwidth}%
\sphinxstopmulticolumn
\\
\hline
\end{tabulary}
\par
\sphinxattableend\end{savenotes}

View File

@ -0,0 +1,45 @@
\label{\detokenize{longtable:longtable}}
\begin{savenotes}\sphinxatlongtablestart\begin{longtable}{|l|l|}
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
\endfirsthead
\multicolumn{2}{c}%
{\makebox[0pt]{\sphinxtablecontinued{\tablename\ \thetable{} -- continued from previous page}}}\\
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
\endhead
\hline
\multicolumn{2}{r}{\makebox[0pt][r]{\sphinxtablecontinued{Continued on next page}}}\\
\endfoot
\endlastfoot
cell1-1
&
cell1-2
\\
\hline
cell2-1
&
cell2-2
\\
\hline
cell3-1
&
cell3-2
\\
\hline
\end{longtable}\sphinxatlongtableend\end{savenotes}

View File

@ -0,0 +1,45 @@
\label{\detokenize{longtable:longtable-having-align-option}}
\begin{savenotes}\sphinxatlongtablestart\begin{longtable}[r]{|l|l|}
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
\endfirsthead
\multicolumn{2}{c}%
{\makebox[0pt]{\sphinxtablecontinued{\tablename\ \thetable{} -- continued from previous page}}}\\
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
\endhead
\hline
\multicolumn{2}{r}{\makebox[0pt][r]{\sphinxtablecontinued{Continued on next page}}}\\
\endfoot
\endlastfoot
cell1-1
&
cell1-2
\\
\hline
cell2-1
&
cell2-2
\\
\hline
cell3-1
&
cell3-2
\\
\hline
\end{longtable}\sphinxatlongtableend\end{savenotes}

View File

@ -0,0 +1,46 @@
\label{\detokenize{longtable:longtable-having-caption}}
\begin{savenotes}\sphinxatlongtablestart\begin{longtable}{|l|l|}
\caption{caption for longtable\strut}\label{\detokenize{longtable:id1}}\\*[\sphinxlongtablecapskipadjust]
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
\endfirsthead
\multicolumn{2}{c}%
{\makebox[0pt]{\sphinxtablecontinued{\tablename\ \thetable{} -- continued from previous page}}}\\
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
\endhead
\hline
\multicolumn{2}{r}{\makebox[0pt][r]{\sphinxtablecontinued{Continued on next page}}}\\
\endfoot
\endlastfoot
cell1-1
&
cell1-2
\\
\hline
cell2-1
&
cell2-2
\\
\hline
cell3-1
&
cell3-2
\\
\hline
\end{longtable}\sphinxatlongtableend\end{savenotes}

View File

@ -0,0 +1,51 @@
\label{\detokenize{longtable:longtable-having-problematic-cell}}
\begin{savenotes}\sphinxatlongtablestart\begin{longtable}{|*{2}{\X{1}{2}|}}
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
\endfirsthead
\multicolumn{2}{c}%
{\makebox[0pt]{\sphinxtablecontinued{\tablename\ \thetable{} -- continued from previous page}}}\\
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
\endhead
\hline
\multicolumn{2}{r}{\makebox[0pt][r]{\sphinxtablecontinued{Continued on next page}}}\\
\endfoot
\endlastfoot
\begin{itemize}
\item {}
item1
\item {}
item2
\end{itemize}
&
cell1-2
\\
\hline
cell2-1
&
cell2-2
\\
\hline
cell3-1
&
cell3-2
\\
\hline
\end{longtable}\sphinxatlongtableend\end{savenotes}

View File

@ -0,0 +1,54 @@
\label{\detokenize{longtable:longtable-having-both-stub-columns-and-problematic-cell}}
\begin{savenotes}\sphinxatlongtablestart\begin{longtable}{|*{3}{\X{1}{3}|}}
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header3
\unskip}\relax \\
\hline
\endfirsthead
\multicolumn{3}{c}%
{\makebox[0pt]{\sphinxtablecontinued{\tablename\ \thetable{} -- continued from previous page}}}\\
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header3
\unskip}\relax \\
\hline
\endhead
\hline
\multicolumn{3}{r}{\makebox[0pt][r]{\sphinxtablecontinued{Continued on next page}}}\\
\endfoot
\endlastfoot
\sphinxstylethead{\sphinxstyletheadfamily \begin{itemize}
\item {}
instub1-1a
\item {}
instub1-1b
\end{itemize}
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
instub1-2
\unskip}\relax &
notinstub1-3
\\
\hline\sphinxstylethead{\sphinxstyletheadfamily
cell2-1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
cell2-2
\unskip}\relax &
cell2-3
\\
\hline
\end{longtable}\sphinxatlongtableend\end{savenotes}

View File

@ -0,0 +1,47 @@
\label{\detokenize{longtable:longtable-having-verbatim}}
\begin{savenotes}\sphinxatlongtablestart\begin{longtable}{|*{2}{\X{1}{2}|}}
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
\endfirsthead
\multicolumn{2}{c}%
{\makebox[0pt]{\sphinxtablecontinued{\tablename\ \thetable{} -- continued from previous page}}}\\
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
\endhead
\hline
\multicolumn{2}{r}{\makebox[0pt][r]{\sphinxtablecontinued{Continued on next page}}}\\
\endfoot
\endlastfoot
\begin{sphinxVerbatimintable}[commandchars=\\\{\}]
\PYG{n}{hello} \PYG{n}{world}
\end{sphinxVerbatimintable}
&
cell1-2
\\
\hline
cell2-1
&
cell2-2
\\
\hline
cell3-1
&
cell3-2
\\
\hline
\end{longtable}\sphinxatlongtableend\end{savenotes}

View File

@ -0,0 +1,45 @@
\label{\detokenize{longtable:longtable-having-widths-option}}
\begin{savenotes}\sphinxatlongtablestart\begin{longtable}{|\X{30}{100}|\X{70}{100}|}
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
\endfirsthead
\multicolumn{2}{c}%
{\makebox[0pt]{\sphinxtablecontinued{\tablename\ \thetable{} -- continued from previous page}}}\\
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
\endhead
\hline
\multicolumn{2}{r}{\makebox[0pt][r]{\sphinxtablecontinued{Continued on next page}}}\\
\endfoot
\endlastfoot
cell1-1
&
cell1-2
\\
\hline
cell2-1
&
cell2-2
\\
\hline
cell3-1
&
cell3-2
\\
\hline
\end{longtable}\sphinxatlongtableend\end{savenotes}

View File

@ -0,0 +1,51 @@
\label{\detokenize{longtable:longtable-having-both-widths-and-problematic-cell}}
\begin{savenotes}\sphinxatlongtablestart\begin{longtable}{|\X{30}{100}|\X{70}{100}|}
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
\endfirsthead
\multicolumn{2}{c}%
{\makebox[0pt]{\sphinxtablecontinued{\tablename\ \thetable{} -- continued from previous page}}}\\
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
\endhead
\hline
\multicolumn{2}{r}{\makebox[0pt][r]{\sphinxtablecontinued{Continued on next page}}}\\
\endfoot
\endlastfoot
\begin{itemize}
\item {}
item1
\item {}
item2
\end{itemize}
&
cell1-2
\\
\hline
cell2-1
&
cell2-2
\\
\hline
cell3-1
&
cell3-2
\\
\hline
\end{longtable}\sphinxatlongtableend\end{savenotes}

View File

@ -0,0 +1,45 @@
\label{\detokenize{longtable:longtable-with-tabularcolumn}}
\begin{savenotes}\sphinxatlongtablestart\begin{longtable}{|c|c|}
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
\endfirsthead
\multicolumn{2}{c}%
{\makebox[0pt]{\sphinxtablecontinued{\tablename\ \thetable{} -- continued from previous page}}}\\
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
\endhead
\hline
\multicolumn{2}{r}{\makebox[0pt][r]{\sphinxtablecontinued{Continued on next page}}}\\
\endfoot
\endlastfoot
cell1-1
&
cell1-2
\\
\hline
cell2-1
&
cell2-2
\\
\hline
cell3-1
&
cell3-2
\\
\hline
\end{longtable}\sphinxatlongtableend\end{savenotes}

View File

@ -0,0 +1,30 @@
\label{\detokenize{tabular:simple-table}}
\begin{savenotes}\sphinxattablestart
\centering
\begin{tabulary}{\linewidth}[t]{|T|T|}
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
cell1-1
&
cell1-2
\\
\hline
cell2-1
&
cell2-2
\\
\hline
cell3-1
&
cell3-2
\\
\hline
\end{tabulary}
\par
\sphinxattableend\end{savenotes}

View File

@ -0,0 +1,33 @@
\label{\detokenize{tabular:table-having-caption}}
\begin{savenotes}\sphinxattablestart
\centering
\sphinxcapstartof{table}
\sphinxcaption{caption for table}\label{\detokenize{tabular:id1}}
\sphinxaftercaption
\begin{tabulary}{\linewidth}[t]{|T|T|}
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
cell1-1
&
cell1-2
\\
\hline
cell2-1
&
cell2-2
\\
\hline
cell3-1
&
cell3-2
\\
\hline
\end{tabulary}
\par
\sphinxattableend\end{savenotes}

View File

@ -0,0 +1,36 @@
\label{\detokenize{tabular:table-having-problematic-cell}}
\begin{savenotes}\sphinxattablestart
\centering
\begin{tabular}[t]{|*{2}{\X{1}{2}|}}
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline\begin{itemize}
\item {}
item1
\item {}
item2
\end{itemize}
&
cell1-2
\\
\hline
cell2-1
&
cell2-2
\\
\hline
cell3-1
&
cell3-2
\\
\hline
\end{tabular}
\par
\sphinxattableend\end{savenotes}

View File

@ -0,0 +1,37 @@
\label{\detokenize{tabular:table-having-both-stub-columns-and-problematic-cell}}
\begin{savenotes}\sphinxattablestart
\centering
\begin{tabular}[t]{|*{3}{\X{1}{3}|}}
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header3
\unskip}\relax \\
\hline\sphinxstylethead{\sphinxstyletheadfamily \begin{itemize}
\item {}
instub1-1a
\item {}
instub1-1b
\end{itemize}
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
instub1-2
\unskip}\relax &
notinstub1-3
\\
\hline\sphinxstylethead{\sphinxstyletheadfamily
cell2-1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
cell2-2
\unskip}\relax &
cell2-3
\\
\hline
\end{tabular}
\par
\sphinxattableend\end{savenotes}

View File

@ -0,0 +1,32 @@
\label{\detokenize{tabular:table-having-verbatim}}
\begin{savenotes}\sphinxattablestart
\centering
\begin{tabular}[t]{|*{2}{\X{1}{2}|}}
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
\begin{sphinxVerbatimintable}[commandchars=\\\{\}]
\PYG{n}{hello} \PYG{n}{world}
\end{sphinxVerbatimintable}
&
cell1-2
\\
\hline
cell2-1
&
cell2-2
\\
\hline
cell3-1
&
cell3-2
\\
\hline
\end{tabular}
\par
\sphinxattableend\end{savenotes}

View File

@ -0,0 +1,30 @@
\label{\detokenize{tabular:table-having-widths-option}}
\begin{savenotes}\sphinxattablestart
\centering
\begin{tabular}[t]{|\X{30}{100}|\X{70}{100}|}
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
cell1-1
&
cell1-2
\\
\hline
cell2-1
&
cell2-2
\\
\hline
cell3-1
&
cell3-2
\\
\hline
\end{tabular}
\par
\sphinxattableend\end{savenotes}

View File

@ -0,0 +1,36 @@
\label{\detokenize{tabular:table-having-both-widths-and-problematic-cell}}
\begin{savenotes}\sphinxattablestart
\centering
\begin{tabular}[t]{|\X{30}{100}|\X{70}{100}|}
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline\begin{itemize}
\item {}
item1
\item {}
item2
\end{itemize}
&
cell1-2
\\
\hline
cell2-1
&
cell2-2
\\
\hline
cell3-1
&
cell3-2
\\
\hline
\end{tabular}
\par
\sphinxattableend\end{savenotes}

View File

@ -0,0 +1,30 @@
\label{\detokenize{tabular:table-having-align-option-tabular}}
\begin{savenotes}\sphinxattablestart
\raggedright
\begin{tabular}[t]{|\X{30}{100}|\X{70}{100}|}
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
cell1-1
&
cell1-2
\\
\hline
cell2-1
&
cell2-2
\\
\hline
cell3-1
&
cell3-2
\\
\hline
\end{tabular}
\par
\sphinxattableend\end{savenotes}

View File

@ -0,0 +1,30 @@
\label{\detokenize{tabular:table-with-tabularcolumn}}
\begin{savenotes}\sphinxattablestart
\centering
\begin{tabulary}{\linewidth}[t]{|c|c|}
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
cell1-1
&
cell1-2
\\
\hline
cell2-1
&
cell2-2
\\
\hline
cell3-1
&
cell3-2
\\
\hline
\end{tabulary}
\par
\sphinxattableend\end{savenotes}

View File

@ -0,0 +1,30 @@
\label{\detokenize{tabular:table-having-align-option-tabulary}}
\begin{savenotes}\sphinxattablestart
\raggedleft
\begin{tabulary}{\linewidth}[t]{|T|T|}
\hline
\sphinxstylethead{\sphinxstyletheadfamily
header1
\unskip}\relax &\sphinxstylethead{\sphinxstyletheadfamily
header2
\unskip}\relax \\
\hline
cell1-1
&
cell1-2
\\
\hline
cell2-1
&
cell2-2
\\
\hline
cell3-1
&
cell3-2
\\
\hline
\end{tabulary}
\par
\sphinxattableend\end{savenotes}

View File

@ -850,78 +850,62 @@ def test_latex_table_tabulars(app, status, warning):
app.builder.build_all()
result = (app.outdir / 'test.tex').text(encoding='utf8')
tables = {}
for chap in re.split(r'\\section{', result)[1:]:
for chap in re.split(r'\\(?:section|chapter){', result)[1:]:
sectname, content = chap.split('}', 1)
tables[sectname] = content.strip()
def get_expected(name):
return (app.srcdir / 'expects' / (name + '.tex')).text().strip()
# simple_table
table = tables['simple table']
assert ('\\begin{savenotes}\\sphinxattablestart\n\\centering\n'
'\\begin{tabulary}{\\linewidth}[t]{|T|T|}' in table)
assert ('\\hline\n'
'\\sphinxstylethead{\\sphinxstyletheadfamily \nheader1\n\\unskip}\\relax &'
'\\sphinxstylethead{\\sphinxstyletheadfamily \nheader2\n\\unskip}\\relax'
in table)
assert ('\\hline\ncell1-1\n&\ncell1-2\n\\\\' in table)
assert ('\\hline\ncell2-1\n&\ncell2-2\n\\\\' in table)
assert ('\\hline\ncell3-1\n&\ncell3-2\n\\\\' in table)
assert ('\\hline\n\\end{tabulary}\n\\par\n'
'\\sphinxattableend\\end{savenotes}' in table)
actual = tables['simple table']
expected = get_expected('simple_table')
assert actual == expected
# table having :widths: option
table = tables['table having :widths: option']
assert ('\\begin{savenotes}\\sphinxattablestart\n\\centering\n'
'\\begin{tabular}[t]{|\\X{30}{100}|\\X{70}{100}|}' in table)
assert ('\\hline\n\\end{tabular}\n\\par\n'
'\\sphinxattableend\\end{savenotes}' in table)
actual = tables['table having :widths: option']
expected = get_expected('table_having_widths')
assert actual == expected
# table having :align: option (tabulary)
table = tables['table having :align: option (tabulary)']
assert ('\\begin{savenotes}\\sphinxattablestart\n\\raggedleft\n'
'\\begin{tabulary}{\\linewidth}[t]{|T|T|}\n' in table)
assert ('\\hline\n\\end{tabulary}\n\\par\n'
'\\sphinxattableend\\end{savenotes}' in table)
actual = tables['table having :align: option (tabulary)']
expected = get_expected('tabulary_having_widths')
assert actual == expected
# table having :align: option (tabular)
table = tables['table having :align: option (tabular)']
assert ('\\begin{savenotes}\\sphinxattablestart\n\\raggedright\n'
'\\begin{tabular}[t]{|\\X{30}{100}|\\X{70}{100}|}\n' in table)
assert ('\\hline\n\\end{tabular}\n\\par\n'
'\\sphinxattableend\\end{savenotes}' in table)
actual = tables['table having :align: option (tabular)']
expected = get_expected('tabular_having_widths')
assert actual == expected
# table with tabularcolumn
table = tables['table with tabularcolumn']
assert ('\\begin{tabulary}{\\linewidth}[t]{|c|c|}' in table)
actual = tables['table with tabularcolumn']
expected = get_expected('tabularcolumn')
assert actual == expected
# table having caption
table = tables['table having caption']
assert ('\\begin{savenotes}\\sphinxattablestart\n\\centering\n'
'\\sphinxcapstartof{table}\n'
'\\sphinxcaption{caption for table}'
'\\label{\\detokenize{tabular:id1}}\n'
'\\sphinxaftercaption' in table)
assert ('\\begin{tabulary}{\\linewidth}[t]{|T|T|}' in table)
assert ('\\hline\n\\end{tabulary}'
'\n\\par\n\\sphinxattableend\\end{savenotes}' in table)
actual = tables['table having caption']
expected = get_expected('table_having_caption')
assert actual == expected
# table having verbatim
table = tables['table having verbatim']
assert ('\\begin{tabular}[t]{|*{2}{\\X{1}{2}|}}\n\\hline' in table)
actual = tables['table having verbatim']
expected = get_expected('table_having_verbatim')
assert actual == expected
# table having problematic cell
table = tables['table having problematic cell']
assert ('\\begin{tabular}[t]{|*{2}{\\X{1}{2}|}}\n\\hline' in table)
actual = tables['table having problematic cell']
expected = get_expected('table_having_problematic_cell')
assert actual == expected
# table having both :widths: and problematic cell
table = tables['table having both :widths: and problematic cell']
assert ('\\begin{tabular}[t]{|\\X{30}{100}|\\X{70}{100}|}' in table)
actual = tables['table having both :widths: and problematic cell']
expected = get_expected('table_having_widths_and_problematic_cell')
assert actual == expected
# table having both stub columns and problematic cell
table = tables['table having both stub columns and problematic cell']
assert ('&\\sphinxstylethead{\\sphinxstyletheadfamily \n'
'instub1-2\n\\unskip}\\relax &\nnotinstub1-3\n\\\\\n'
'\\hline\\sphinxstylethead{\\sphinxstyletheadfamily \n'
'cell2-1\n\\unskip}\\relax &' in table)
actual = tables['table having both stub columns and problematic cell']
expected = get_expected('table_having_stub_columns_and_problematic_cell')
assert actual == expected
@pytest.mark.skipif(docutils.__version_info__ < (0, 13),
@ -932,69 +916,57 @@ def test_latex_table_longtable(app, status, warning):
app.builder.build_all()
result = (app.outdir / 'test.tex').text(encoding='utf8')
tables = {}
for chap in re.split(r'\\section{', result)[1:]:
for chap in re.split(r'\\(?:section|chapter){', result)[1:]:
sectname, content = chap.split('}', 1)
tables[sectname] = content.strip()
def get_expected(name):
return (app.srcdir / 'expects' / (name + '.tex')).text().strip()
# longtable
table = tables['longtable']
assert ('\\begin{savenotes}\\sphinxatlongtablestart'
'\\begin{longtable}{|l|l|}\n\\hline' in table)
assert ('\\hline\n'
'\\sphinxstylethead{\\sphinxstyletheadfamily \nheader1\n\\unskip}\\relax &'
'\\sphinxstylethead{\\sphinxstyletheadfamily \nheader2\n\\unskip}\\relax '
'\\\\\n\\hline\n\\endfirsthead' in table)
assert ('\\multicolumn{2}{c}%\n'
'{\\makebox[0pt]{\\sphinxtablecontinued{\\tablename\\ \\thetable{} -- '
'continued from previous page}}}\\\\\n\\hline\n'
'\\sphinxstylethead{\\sphinxstyletheadfamily \nheader1\n\\unskip}\\relax &'
'\\sphinxstylethead{\\sphinxstyletheadfamily \nheader2\n\\unskip}\\relax '
'\\\\\n\\hline\n\\endhead' in table)
assert ('\\hline\n\\multicolumn{2}{r}'
'{\\makebox[0pt][r]{\\sphinxtablecontinued{Continued on next page}}}\\\\\n'
'\\endfoot\n\n\\endlastfoot' in table)
assert ('\ncell1-1\n&\ncell1-2\n\\\\' in table)
assert ('\\hline\ncell2-1\n&\ncell2-2\n\\\\' in table)
assert ('\\hline\ncell3-1\n&\ncell3-2\n\\\\' in table)
assert ('\\hline\n\\end{longtable}\\sphinxatlongtableend\\end{savenotes}' in table)
actual = tables['longtable']
expected = get_expected('longtable')
assert actual == expected
# longtable having :widths: option
table = tables['longtable having :widths: option']
assert ('\\begin{longtable}{|\\X{30}{100}|\\X{70}{100}|}' in table)
actual = tables['longtable having :widths: option']
expected = get_expected('longtable_having_widths')
assert actual == expected
# longtable having :align: option
table = tables['longtable having :align: option']
assert ('\\begin{longtable}[r]{|l|l|}\n' in table)
assert ('\\hline\n\\end{longtable}' in table)
actual = tables['longtable having :align: option']
expected = get_expected('longtable_having_align')
assert actual == expected
# longtable with tabularcolumn
table = tables['longtable with tabularcolumn']
assert ('\\begin{longtable}{|c|c|}' in table)
actual = tables['longtable with tabularcolumn']
expected = get_expected('longtable_with_tabularcolumn')
assert actual == expected
# longtable having caption
table = tables['longtable having caption']
assert ('\\begin{longtable}{|l|l|}\n\\caption{caption for longtable\\strut}'
'\\label{\\detokenize{longtable:id1}}'
'\\\\*[\\sphinxlongtablecapskipadjust]\n\\hline' in table)
actual = tables['longtable having caption']
expected = get_expected('longtable_having_caption')
assert actual == expected
# longtable having verbatim
table = tables['longtable having verbatim']
assert ('\\begin{longtable}{|*{2}{\\X{1}{2}|}}\n\\hline' in table)
actual = tables['longtable having verbatim']
expected = get_expected('longtable_having_verbatim')
assert actual == expected
# longtable having problematic cell
table = tables['longtable having problematic cell']
assert ('\\begin{longtable}{|*{2}{\\X{1}{2}|}}\n\\hline' in table)
actual = tables['longtable having problematic cell']
expected = get_expected('longtable_having_problematic_cell')
assert actual == expected
# longtable having both :widths: and problematic cell
table = tables['longtable having both :widths: and problematic cell']
assert ('\\begin{longtable}{|\\X{30}{100}|\\X{70}{100}|}' in table)
actual = tables['longtable having both :widths: and problematic cell']
expected = get_expected('longtable_having_widths_and_problematic_cell')
assert actual == expected
# longtable having both stub columns and problematic cell
table = tables['longtable having both stub columns and problematic cell']
assert ('&\\sphinxstylethead{\\sphinxstyletheadfamily \n'
'instub1-2\n\\unskip}\\relax &\nnotinstub1-3\n\\\\\n'
'\\hline\\sphinxstylethead{\\sphinxstyletheadfamily \n'
'cell2-1\n\\unskip}\\relax &' in table)
actual = tables['longtable having both stub columns and problematic cell']
expected = get_expected('longtable_having_stub_columns_and_problematic_cell')
assert actual == expected
@pytest.mark.skipif(docutils.__version_info__ < (0, 13),
@ -1005,56 +977,22 @@ def test_latex_table_complex_tables(app, status, warning):
app.builder.build_all()
result = (app.outdir / 'test.tex').text(encoding='utf8')
tables = {}
for chap in re.split(r'\\section{', result)[1:]:
for chap in re.split(r'\\(?:section|renewcommand){', result)[1:]:
sectname, content = chap.split('}', 1)
tables[sectname] = content.strip()
def get_expected(name):
return (app.srcdir / 'expects' / (name + '.tex')).text().strip()
# grid table
table = tables['grid table']
assert ('\\begin{tabulary}{\\linewidth}[t]{|T|T|T|}' in table)
assert ('\\hline\n'
'\\sphinxstylethead{\\sphinxstyletheadfamily \nheader1\n\\unskip}\\relax &'
'\\sphinxstylethead{\\sphinxstyletheadfamily \nheader2\n\\unskip}\\relax &'
'\\sphinxstylethead{\\sphinxstyletheadfamily \nheader3\n\\unskip}\\relax '
'\\\\' in table)
assert ('\\hline\ncell1-1\n&\\sphinxmultirow{2}{5}{%\n\\begin{varwidth}[t]'
'{\\sphinxcolwidth{1}{3}}\n'
'cell1-2\n\\par\n' in table)
assert ('\\cline{1-1}\\cline{3-3}\\sphinxmultirow{2}{7}{%\n' in table)
assert ('&\\sphinxtablestrut{5}&\ncell2-3\n\\\\\n'
'\\cline{2-3}\\sphinxtablestrut{7}&\\sphinxstartmulticolumn{2}%\n'
'\\sphinxmultirow{2}{9}{%\n\\begin{varwidth}' in table)
assert ('\\cline{1-1}\ncell4-1\n&\\multicolumn{2}{l|}'
'{\\sphinxtablestrut{9}}\\\\' in table)
assert ('\\hline\\sphinxstartmulticolumn{3}%\n'
in table)
actual = tables['grid table']
expected = get_expected('gridtable')
assert actual == expected
# complex spanning cell
table = tables['complex spanning cell']
assert ('\\begin{tabulary}{\\linewidth}[t]{|T|T|T|T|T|}' in table)
assert ('\\sphinxmultirow{3}{1}{%\n'
'\\begin{varwidth}[t]{\\sphinxcolwidth{1}{5}}\n'
'cell1-1\n\\par\n\\vskip-\\baselineskip\\strut\\end{varwidth}%\n'
'}%\n'
'&\\sphinxmultirow{3}{2}{%\n'
'\\begin{varwidth}[t]{\\sphinxcolwidth{1}{5}}\n'
'cell1-2\n\\par\n\\vskip-\\baselineskip\\strut\\end{varwidth}%\n'
'}%\n&\ncell1-3\n&\\sphinxmultirow{3}{4}{%\n'
'\\begin{varwidth}[t]{\\sphinxcolwidth{1}{5}}\n'
'cell1-4\n\\par\n\\vskip-\\baselineskip\\strut\\end{varwidth}%\n'
'}%\n'
'&\\sphinxmultirow{2}{5}{%\n'
'\\begin{varwidth}[t]{\\sphinxcolwidth{1}{5}}\n'
'cell1-5\n'
in table)
assert ('\\cline{3-3}\\sphinxtablestrut{1}&\\sphinxtablestrut{2}&'
'\\sphinxmultirow{2}{6}{%\n'
in table)
assert ('&\\sphinxtablestrut{4}&\\sphinxtablestrut{5}\\\\\n'
'\\cline{5-5}\\sphinxtablestrut{1}&\\sphinxtablestrut{2}&'
'\\sphinxtablestrut{6}&\\sphinxtablestrut{4}&\ncell3-5\n'
'\\\\\n\\hline\n\\end{tabulary}\n'
in table)
actual = tables['complex spanning cell']
expected = get_expected('complex_spanning_cell')
assert actual == expected
@pytest.mark.sphinx('latex', testroot='directives-raw')