Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegeus committed Mar 11, 2024
1 parent 5466fda commit 01ed8d8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
118 changes: 49 additions & 69 deletions tests/test_classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,31 @@


def test_equation():
text = r"""
texts = []

t = r"""
foo bar
\begin{equation}
\label{eq:foo}
a = 10
\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():
Expand All @@ -37,7 +36,6 @@ def test_section():
\label{sec:foo}
baz
"""

tex = texplain.TeX(text)
tex.format_labels()
assert str(tex).strip() == text.strip()
Expand All @@ -52,7 +50,6 @@ def test_figure():
\end{figure}
baz
"""

tex = texplain.TeX(text)
tex.format_labels()
assert str(tex).strip() == text.strip()
Expand All @@ -67,64 +64,51 @@ 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}
\label{misc:self-explenatory}
\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}
Expand All @@ -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}
Expand All @@ -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}
Expand All @@ -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}
Expand All @@ -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()
40 changes: 16 additions & 24 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 01ed8d8

Please sign in to comment.