Skip to content

Commit

Permalink
Fix a coding error and extend table testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jfbu committed Aug 10, 2022
1 parent fdf6081 commit fae68d2
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion sphinx/writers/latex.py
Expand Up @@ -880,7 +880,7 @@ def visit_table(self, node: Element) -> None:
(self.curfilestack[-1], node.line or ''))

self.tables.append(Table(node))
if not self.table.colsep:
if self.table.colsep == None:
self.table.colsep = '' if (
'booktabs' in self.builder.config.latex_table_style or
'borderless' in self.builder.config.latex_table_style
Expand Down
4 changes: 4 additions & 0 deletions tests/roots/test-latex-table/complex.rst
Expand Up @@ -4,6 +4,8 @@ complex tables
grid table
----------

.. rst-class:: nocolorrows

+---------+---------+---------+
| header1 | header2 | header3 |
+=========+=========+=========+
Expand All @@ -26,6 +28,8 @@ table having ...
* consecutive multirow at top of row (1-1 and 1-2)
* consecutive multirow at end of row (1-4 and 1-5)

.. rst-class:: standard

+-----------+-----------+-----------+-----------+-----------+
| | | cell1-3 | | |
| | +-----------+ | cell1-5 |
Expand Down
Expand Up @@ -15,6 +15,7 @@

\begin{savenotes}\sphinxattablestart
\sphinxthistablewithglobalstyle
\sphinxthistablewithstandardstyle
\centering
\begin{tabulary}{\linewidth}[t]{|T|T|T|T|T|}
\sphinxtoprule
Expand Down
1 change: 1 addition & 0 deletions tests/roots/test-latex-table/expects/gridtable.tex
Expand Up @@ -2,6 +2,7 @@

\begin{savenotes}\sphinxattablestart
\sphinxthistablewithglobalstyle
\sphinxthistablewithnocolorrowsstyle
\centering
\begin{tabulary}{\linewidth}[t]{|T|T|T|}
\sphinxtoprule
Expand Down
3 changes: 2 additions & 1 deletion tests/roots/test-latex-table/expects/longtable.tex
Expand Up @@ -3,7 +3,8 @@
\begin{savenotes}
\sphinxatlongtablestart
\sphinxthistablewithglobalstyle
\begin{longtable}[c]{|l|l|}
\sphinxthistablewithborderlessstyle
\begin{longtable}[c]{ll}
\sphinxtoprule
\sphinxstyletheadfamily
\sphinxAtStartPar
Expand Down
4 changes: 3 additions & 1 deletion tests/roots/test-latex-table/expects/table_having_widths.tex
Expand Up @@ -2,9 +2,11 @@

\begin{savenotes}\sphinxattablestart
\sphinxthistablewithglobalstyle
\sphinxthistablewithbooktabsstyle
\sphinxthistablewithcolorrowsstyle
\centering
\phantomsection\label{\detokenize{tabular:namedtabular}}\label{\detokenize{tabular:mytabular}}\nobreak
\begin{tabular}[t]{|\X{30}{100}|\X{70}{100}|}
\begin{tabular}[t]{\X{30}{100}\X{70}{100}}
\sphinxtoprule
\sphinxstyletheadfamily
\sphinxAtStartPar
Expand Down
2 changes: 1 addition & 1 deletion tests/roots/test-latex-table/longtable.rst
Expand Up @@ -5,7 +5,7 @@ longtable
---------

.. table::
:class: longtable
:class: longtable, borderless

======= =======
header1 header2
Expand Down
1 change: 1 addition & 0 deletions tests/roots/test-latex-table/tabular.rst
Expand Up @@ -20,6 +20,7 @@ table having :widths: option
.. table::
:widths: 30,70
:name: namedtabular
:class: booktabs, colorrows

======= =======
header1 header2
Expand Down
5 changes: 4 additions & 1 deletion tests/test_build_latex.py
Expand Up @@ -1327,7 +1327,10 @@ def test_latex_table_with_booktabs(app, status, warning):
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
assert r'\PassOptionsToPackage{booktabs}{sphinx}' in result
assert r'\PassOptionsToPackage{colorrows}{sphinx}' in result
assert r'\begin{tabulary}{\linewidth}[t]{TTTTT}' in result
# tabularcolumns
assert r'\begin{tabulary}{\linewidth}[t]{|c|c|}' in result
# class: standard
assert r'\begin{tabulary}{\linewidth}[t]{|T|T|T|T|T|}' in result
assert r'\begin{longtable}[c]{ll}' in result
assert r'\begin{tabular}[t]{*{2}{\X{1}{2}}}' in result
assert r'\begin{tabular}[t]{\X{30}{100}\X{70}{100}}' in result
Expand Down

0 comments on commit fae68d2

Please sign in to comment.