SF.net SVN: docutils:[10157 ] trunk/docutils/test/test _writers

milde--- via Docutils-checkins <[email protected]> Sat, 07 Jun 2025 15:37:21 +0000
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 10157
          http://sourceforge.net/p/docutils/code/10157
Author:   milde
Date:     2025-06-07 15:37:21 +0000 (Sat, 07 Jun 2025)
Log Message:
-----------
Simplify LaTeX writer tests.

Move test cases where it suffices to compare the "body" part
from "test_latex2e_parts" to "test_latex2e".

Modified Paths:
--------------
    trunk/docutils/test/test_writers/test_latex2e.py
    trunk/docutils/test/test_writers/test_latex2e_parts.py

Modified: trunk/docutils/test/test_writers/test_latex2e.py
===================================================================
--- trunk/docutils/test/test_writers/test_latex2e.py	2025-06-06 08:29:43 UTC (rev 10156)
+++ trunk/docutils/test/test_writers/test_latex2e.py	2025-06-07 15:37:21 UTC (rev 10157)
@@ -150,6 +150,187 @@
 \caption{The larch}
 \end{figure}
 """],
+# tables
+# ======
+# borderless table
+["""\
+.. table::
+   :class: borderless
+
+   +-----+-----+
+   |  1  |  2  |
+   +-----+-----+
+   |  3  |  4  |
+   +-----+-----+
+""",
+"""
+\\setlength{\\DUtablewidth}{\\linewidth}%
+\\begin{longtable*}{p{0.075\\DUtablewidth}p{0.075\\DUtablewidth}}
+
+1
+ & \n\
+2
+ \\\\
+
+3
+ & \n\
+4
+ \\\\
+\\end{longtable*}
+"""],
+# collumn widths determined by LaTeX (via class argument)
+["""\
+.. table::
+   :class: colwidths-auto
+
+   +-----+-+
+   |  1  |2|
+   +-----+-+
+""",
+r"""
+\begin{longtable*}{|l|l|}
+\hline
+1 & 2 \\
+\hline
+\end{longtable*}
+"""],
+# collumn widths determined by LaTeX (via "width" option)
+["""\
+.. table::
+   :widths: auto
+
+   +-----+-+
+   |  1  |2|
+   +-----+-+
+""",
+r"""
+\begin{longtable*}{|l|l|}
+\hline
+1 & 2 \\
+\hline
+\end{longtable*}
+"""],
+# collumn widths specified via "width" option
+["""\
+.. table::
+   :widths: 15, 30
+
+   +-----+-----+
+   |  1  |  2  |
+   +-----+-----+
+""",
+"""
+\\setlength{\\DUtablewidth}{\\linewidth}%
+\\begin{longtable*}{|p{0.191\\DUtablewidth}|p{0.365\\DUtablewidth}|}
+\\hline
+
+1
+ & \n\
+2
+ \\\\
+\\hline
+\\end{longtable*}
+"""],
+# table alignment
+["""\
+.. table::
+   :align: right
+
+   +-----+-----+
+   |  1  |  2  |
+   +-----+-----+
+""",
+"""
+\\setlength{\\DUtablewidth}{\\linewidth}%
+\\begin{longtable*}[r]{|p{0.075\\DUtablewidth}|p{0.075\\DUtablewidth}|}
+\\hline
+
+1
+ & \n\
+2
+ \\\\
+\\hline
+\\end{longtable*}
+"""],
+# table with title row and empty cell
+["""\
+===== ======
+Title
+===== ======
+entry value1
+===== ======
+""",
+"""
+\\setlength{\\DUtablewidth}{\\linewidth}%
+\\begin{longtable*}{|p{0.075\\DUtablewidth}|p{0.086\\DUtablewidth}|}
+\\hline
+\\textbf{%
+Title
+} &  \\\\
+\\hline
+\\endfirsthead
+\\hline
+\\textbf{%
+Title
+} &  \\\\
+\\hline
+\\endhead
+\\multicolumn{2}{p{0.16\\DUtablewidth}}{\\raggedleft\\ldots continued on next page}\\\\
+\\endfoot
+\\endlastfoot
+
+entry
+ & \n\
+value1
+ \\\\
+\\hline
+\\end{longtable*}
+"""],
+# table with emtpy rowspanning cell
+["""\
++----+----+
+| c3 | c4 |
++----+----+
+|         |
++---------+
+""",
+"""
+\\setlength{\\DUtablewidth}{\\linewidth}%
+\\begin{longtable*}{|p{0.063\\DUtablewidth}|p{0.063\\DUtablewidth}|}
+\\hline
+
+c3
+ & \n\
+c4
+ \\\\
+\\hline
+\\multicolumn{2}{|p{0.13\\DUtablewidth}|}{} \\\\
+\\hline
+\\end{longtable*}
+"""],
+# table with IDs and custom + special class values
+["""\
+.. class:: cls1
+.. _label1:
+.. table::
+   :name: label2
+   :class: cls2 borderless
+   :widths: auto
+
+   = =
+   Y N
+   = =
+""",
+r"""
+\begin{DUclass}{cls2}
+\begin{DUclass}{cls1}
+\phantomsection\label{label2}\label{label1}
+\begin{longtable*}{ll}
+Y & N \\
+\end{longtable*}
+\end{DUclass}
+\end{DUclass}
+"""],
 ])
 
 samples['latex_sectnum'] = ({'sectnum_xform': False}, [
@@ -222,6 +403,65 @@
 ])
 
 
+samples['colwidths_auto'] = ({'table_style': ['colwidths-auto']}, [
+# Requires longtable, etc. and setup --- see "test_latex2e_parts".
+# borderless table with auto-width columns
+["""\
+.. table::
+   :class: borderless
+
+   +-----+-----+
+   |  1  |  2  |
+   +-----+-----+
+   |  3  |  4  |
+   +-----+-----+
+""",
+r"""
+\begin{longtable*}{ll}
+1 & 2 \\
+3 & 4 \\
+\end{longtable*}
+"""],
+# booktabs style table with auto-width columns
+["""\
+.. table::
+   :class: booktabs
+
+   +-----+-+
+   |  1  |2|
+   +-----+-+
+""",
+r"""
+\begin{longtable*}{ll}
+\toprule
+1 & 2 \\
+\bottomrule
+\end{longtable*}
+"""],
+# given width overrides "colwidth-auto"
+["""\
+.. table::
+   :widths: 15, 30
+
+   +-----+-----+
+   |  1  |  2  |
+   +-----+-----+
+""",
+"""
+\\setlength{\\DUtablewidth}{\\linewidth}%
+\\begin{longtable*}{|p{0.191\\DUtablewidth}|p{0.365\\DUtablewidth}|}
+\\hline
+
+1
+ & \n\
+2
+ \\\\
+\\hline
+\\end{longtable*}
+"""],
+])
+
+
 samples['bibtex'] = ({'use_bibtex': ['alpha', 'xampl']}, [
 ["""\
 Just a test citation [book-full]_.

Modified: trunk/docutils/test/test_writers/test_latex2e_parts.py
===================================================================
--- trunk/docutils/test/test_writers/test_latex2e_parts.py	2025-06-06 08:29:43 UTC (rev 10156)
+++ trunk/docutils/test/test_writers/test_latex2e_parts.py	2025-06-07 15:37:21 UTC (rev 10157)
@@ -341,35 +341,6 @@
   'requirements': '\\usepackage[T1]{fontenc}\n'
                   + REQUIREMENTS_TABLE,
   }],
-# borderless table
-["""\
-.. table::
-   :class: borderless
-
-   +-----+-----+
-   |  1  |  2  |
-   +-----+-----+
-   |  3  |  4  |
-   +-----+-----+
-""",
- {'body': """
-\\setlength{\\DUtablewidth}{\\linewidth}%
-\\begin{longtable*}{p{0.075\\DUtablewidth}p{0.075\\DUtablewidth}}
-
-1
- & \n\
-2
- \\\\
-
-3
- & \n\
-4
- \\\\
-\\end{longtable*}
-""",
-  'requirements': '\\usepackage[T1]{fontenc}\n'
-                  + REQUIREMENTS_TABLE
-  }],
 # table style "booktabs"
 ["""\
 .. table::
@@ -395,203 +366,8 @@
                   '\\usepackage{booktabs}\n'
                   + REQUIREMENTS_TABLE
   }],
-# collumn widths determined by LaTeX (via class argument)
+# literal block requires alltt
 ["""\
-.. table::
-   :class: colwidths-auto
-
-   +-----+-+
-   |  1  |2|
-   +-----+-+
-""",
- {'body': r"""
-\begin{longtable*}{|l|l|}
-\hline
-1 & 2 \\
-\hline
-\end{longtable*}
-""",
-  'requirements': '\\usepackage[T1]{fontenc}\n'
-                  + REQUIREMENTS_TABLE
-  }],
-# collumn widths determined by LaTeX (via "width" option)
-["""\
-.. table::
-   :widths: auto
-
-   +-----+-+
-   |  1  |2|
-   +-----+-+
-""",
- {'body': r"""
-\begin{longtable*}{|l|l|}
-\hline
-1 & 2 \\
-\hline
-\end{longtable*}
-""",
-  'requirements': '\\usepackage[T1]{fontenc}\n'
-                  + REQUIREMENTS_TABLE
-  }],
-# collumn widths specified via "width" option
-["""\
-.. table::
-   :widths: 15, 30
-
-   +-----+-----+
-   |  1  |  2  |
-   +-----+-----+
-""",
- {'body': """
-\\setlength{\\DUtablewidth}{\\linewidth}%
-\\begin{longtable*}{|p{0.191\\DUtablewidth}|p{0.365\\DUtablewidth}|}
-\\hline
-
-1
- & \n\
-2
- \\\\
-\\hline
-\\end{longtable*}
-""",
-  'requirements': '\\usepackage[T1]{fontenc}\n'
-                  + REQUIREMENTS_TABLE
-  }],
-# table alignment
-["""\
-.. table::
-   :align: right
-
-   +-----+-----+
-   |  1  |  2  |
-   +-----+-----+
-""",
- {'body': """
-\\setlength{\\DUtablewidth}{\\linewidth}%
-\\begin{longtable*}[r]{|p{0.075\\DUtablewidth}|p{0.075\\DUtablewidth}|}
-\\hline
-
-1
- & \n\
-2
- \\\\
-\\hline
-\\end{longtable*}
-""",
-  'requirements': '\\usepackage[T1]{fontenc}\n'
-                  + REQUIREMENTS_TABLE
-  }],
-# table with title row and empty cell
-["""\
-===== ======
-Title
-===== ======
-entry value1
-===== ======
-""",
- {'body': """
-\\setlength{\\DUtablewidth}{\\linewidth}%
-\\begin{longtable*}{|p{0.075\\DUtablewidth}|p{0.086\\DUtablewidth}|}
-\\hline
-\\textbf{%
-Title
-} &  \\\\
-\\hline
-\\endfirsthead
-\\hline
-\\textbf{%
-Title
-} &  \\\\
-\\hline
-\\endhead
-\\multicolumn{2}{p{0.16\\DUtablewidth}}{\\raggedleft\\ldots continued on next page}\\\\
-\\endfoot
-\\endlastfoot
-
-entry
- & \n\
-value1
- \\\\
-\\hline
-\\end{longtable*}
-""",
-  'requirements': '\\usepackage[T1]{fontenc}\n'
-                  + REQUIREMENTS_TABLE
-  }],
-# table with emtpy rowspanning cell
-["""\
-+----+----+
-| c3 | c4 |
-+----+----+
-|         |
-+---------+
-""",
- {'body': """
-\\setlength{\\DUtablewidth}{\\linewidth}%
-\\begin{longtable*}{|p{0.063\\DUtablewidth}|p{0.063\\DUtablewidth}|}
-\\hline
-
-c3
- & \n\
-c4
- \\\\
-\\hline
-\\multicolumn{2}{|p{0.13\\DUtablewidth}|}{} \\\\
-\\hline
-\\end{longtable*}
-""",
-  'requirements': '\\usepackage[T1]{fontenc}\n'
-                  + REQUIREMENTS_TABLE
-  }],
-# table with custom class value
-["""\
-.. table::
-   :class: my-class
-
-   +-----+-----+
-   |  1  |  2  |
-   +-----+-----+
-   |  3  |  4  |
-   +-----+-----+
-""",
- {'body': """
-\\begin{DUclass}{my-class}
-\\setlength{\\DUtablewidth}{\\linewidth}%
-\\begin{longtable*}{|p{0.075\\DUtablewidth}|p{0.075\\DUtablewidth}|}
-\\hline
-
-1
- & \n\
-2
- \\\\
-\\hline
-
-3
- & \n\
-4
- \\\\
-\\hline
-\\end{longtable*}
-\\end{DUclass}
-""",
-  'fallbacks': r"""
-% class handling for environments (block-level elements)
-% \begin{DUclass}{spam} tries \DUCLASSspam and
-% \end{DUclass}{spam} tries \endDUCLASSspam
-\ifdefined\DUclass
-\else % poor man's "provideenvironment"
-  \newenvironment{DUclass}[1]%
-    {% "#1" does not work in end-part of environment.
-     \def\DocutilsClassFunctionName{DUCLASS#1}
-     \csname \DocutilsClassFunctionName \endcsname}%
-    {\csname end\DocutilsClassFunctionName \endcsname}%
-\fi
-""",
-  'requirements': '\\usepackage[T1]{fontenc}\n'
-                  + REQUIREMENTS_TABLE
-  }],
-# literal block
-["""\
 Test special characters { [ \\\\ ] } in literal block::
 
   { [ ( \\macro
@@ -872,77 +648,9 @@
   'requirements': '\\usepackage[T1]{fontenc}\n'
                   + REQUIREMENTS_TABLE
   }],
-
 ])
 
 
-samples['colwidths_auto'] = ({'table_style': ['colwidths-auto']}, [
-# borderless table with auto-width columns
-["""\
-.. table::
-   :class: borderless
-
-   +-----+-----+
-   |  1  |  2  |
-   +-----+-----+
-   |  3  |  4  |
-   +-----+-----+
-""",
- {'body': r"""
-\begin{longtable*}{ll}
-1 & 2 \\
-3 & 4 \\
-\end{longtable*}
-""",
-  'requirements': '\\usepackage[T1]{fontenc}\n'
-                  + REQUIREMENTS_TABLE
-  }],
-# booktabs style table with auto-width columns
-["""\
-.. table::
-   :class: booktabs
-
-   +-----+-+
-   |  1  |2|
-   +-----+-+
-""",
- {'body': r"""
-\begin{longtable*}{ll}
-\toprule
-1 & 2 \\
-\bottomrule
-\end{longtable*}
-""",
-  'requirements': '\\usepackage[T1]{fontenc}\n'
-                  '\\usepackage{booktabs}\n'
-                  + REQUIREMENTS_TABLE
-  }],
-# given width overrides "colwidth-auto"
-["""\
-.. table::
-   :widths: 15, 30
-
-   +-----+-----+
-   |  1  |  2  |
-   +-----+-----+
-""",
- {'body': """
-\\setlength{\\DUtablewidth}{\\linewidth}%
-\\begin{longtable*}{|p{0.191\\DUtablewidth}|p{0.365\\DUtablewidth}|}
-\\hline
-
-1
- & \n\
-2
- \\\\
-\\hline
-\\end{longtable*}
-""",
-  'requirements': '\\usepackage[T1]{fontenc}\n'
-                  + REQUIREMENTS_TABLE
-  }],
-])
-
 samples['Docutils ToC and sectnum'] = ({'use_latex_toc': False}, [
 ["""\
 .. contents:: Table of Contents

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.