diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2db7c79..2025d21 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,7 +28,7 @@ repos: rev: 24.1.1 hooks: - id: black - args: [--safe, --quiet, --line-length=100] + args: [--safe, --quiet, --line-length=100, --preview] - repo: https://github.com/PyCQA/autoflake rev: v2.2.1 hooks: diff --git a/tests/test_classify.py b/tests/test_classify.py index ec31ae2..a857fb6 100644 --- a/tests/test_classify.py +++ b/tests/test_classify.py @@ -2,7 +2,9 @@ def test_equation(): - text = r""" + texts = [] + + t = r""" foo bar \begin{equation} \label{eq:foo} @@ -10,24 +12,21 @@ def test_equation(): \end{equation} baz """ + texts.append(t) - tex = texplain.TeX(text) - tex.format_labels() - assert str(tex).strip() == text.strip() - - # -- - - text = r""" + t = r""" My text \begin{equation} a = b \label{eq:qew} \end{equation} """ + texts.append(t) - tex = texplain.TeX(text) - tex.format_labels() - assert str(tex).strip() == text.strip() + for text in texts: + tex = texplain.TeX(text) + tex.format_labels() + assert str(tex).strip() == text.strip() def test_section(): @@ -37,7 +36,6 @@ def test_section(): \label{sec:foo} baz """ - tex = texplain.TeX(text) tex.format_labels() assert str(tex).strip() == text.strip() @@ -52,7 +50,6 @@ def test_figure(): \end{figure} baz """ - tex = texplain.TeX(text) tex.format_labels() assert str(tex).strip() == text.strip() @@ -67,14 +64,15 @@ def test_figure_b(): \end{figure*} baz """ - tex = texplain.TeX(text) tex.format_labels() assert str(tex).strip() == text.strip() def test_custom(): - text = r""" + texts = [] + + t0 = r""" \begin{example}[H] \begin{oframed} \caption{Self-explanatory vs documentation intensive} @@ -82,49 +80,35 @@ def test_custom(): \end{oframed} \end{example} """ + texts.append(t0) - tex = texplain.TeX(text) - tex.format_labels() - assert str(tex).strip() == text.strip() + texts.append("\n\n".join([r"\section{My section}"]) + t0) + texts.append("\n\n".join([r"\section{My section}", r"\label{sec:mysec}"]) + t0) + for text in texts: + tex = texplain.TeX(text) + tex.format_labels() + assert str(tex).strip() == text.strip() -def test_custom_nested(): - text = r""" -\section{My section} - -\begin{example}[H] - \begin{oframed} - \caption{Self-explanatory vs documentation intensive} - \label{misc:self-explenatory} - \end{oframed} -\end{example} -""" - tex = texplain.TeX(text) - tex.format_labels() - assert str(tex).strip() == text.strip() +def test_nested(): + texts = [] + t = r""" +\begin{appendices} -def test_custom_nested2(): - text = r""" -\section{My section} -\label{sec:mysec} + \section{My section} -\begin{example}[H] - \begin{oframed} + \begin{figure}[H] \caption{Self-explanatory vs documentation intensive} - \label{misc:self-explenatory} - \end{oframed} -\end{example} -""" - - tex = texplain.TeX(text) - tex.format_labels() - assert str(tex).strip() == text.strip() + \label{fig:self-explenatory} + \end{figure} +\end{appendices} +""" + texts.append(t) -def test_nested(): - text = r""" + t = r""" \begin{appendices} \section{My section} @@ -137,14 +121,9 @@ def test_nested(): \end{appendices} """ + texts.append(t) - tex = texplain.TeX(text) - tex.format_labels() - assert str(tex).strip() == text.strip() - - -def test_nested_custom(): - text = r""" + t = r""" \begin{appendices} \section{My section} @@ -159,14 +138,18 @@ def test_nested_custom(): \end{appendices} """ + texts.append(t) - tex = texplain.TeX(text) - tex.format_labels() - assert str(tex).strip() == text.strip() + for text in texts: + tex = texplain.TeX(text) + tex.format_labels() + assert str(tex).strip() == text.strip() def test_hybrid(): - text = r""" + texts = [] + + t = r""" \begin{itemize} \item \begin{referee} @@ -185,14 +168,9 @@ def test_hybrid(): \end{figure} \end{itemize} """ + texts.append(t) - tex = texplain.TeX(text) - tex.format_labels() - assert str(tex).strip() == text.strip() - - # --- - - text = r""" + t = r""" Foo bar \section{My section} @@ -210,7 +188,9 @@ def test_hybrid(): \label{fig:1} \end{figure} """ + texts.append(t) - tex = texplain.TeX(text) - tex.format_labels() - assert str(tex).strip() == text.strip() + for text in texts: + tex = texplain.TeX(text) + tex.format_labels() + assert str(tex).strip() == text.strip() diff --git a/tests/test_simple.py b/tests/test_simple.py index 19a677a..f53952b 100644 --- a/tests/test_simple.py +++ b/tests/test_simple.py @@ -453,31 +453,23 @@ def test_remove_command_d(): def test_fix_quote(): test = [] test.append(['This is text "with quotes".', "This is text ``with quotes''."]) - test.append( - [ - 'This is text "with quotes" but not matching".', - 'This is text "with quotes" but not matching".', - ] - ) + test.append([ + 'This is text "with quotes" but not matching".', + 'This is text "with quotes" but not matching".', + ]) test.append(["This is text 'with quotes'.", "This is text `with quotes'."]) - test.append( - [ - "This is text 'with quotes' but not matching'.", - "This is text 'with quotes' but not matching'.", - ] - ) - test.append( - [ - 'A text "with one quote", and "another one".', - "A text ``with one quote'', and ``another one''.", - ] - ) - test.append( - [ - 'A text "with one quote", and "another one"', - "A text ``with one quote'', and ``another one''", - ] - ) + test.append([ + "This is text 'with quotes' but not matching'.", + "This is text 'with quotes' but not matching'.", + ]) + test.append([ + 'A text "with one quote", and "another one".', + "A text ``with one quote'', and ``another one''.", + ]) + test.append([ + 'A text "with one quote", and "another one"', + "A text ``with one quote'', and ``another one''", + ]) test.append(['Foo bar "bar foo"', "Foo bar ``bar foo''"]) for source, expect in test: