Skip to content

Commit

Permalink
Switching to pytest (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegeus authored Dec 13, 2023
1 parent 3c811fa commit 0d5b528
Show file tree
Hide file tree
Showing 14 changed files with 1,650 additions and 1,610 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
run: python -m pip install . -v --no-build-isolation --no-deps

- name: Run tests
run: python -m unittest discover tests -v
run: pytest -sv

- name: Build docs
working-directory: docs
Expand Down
1 change: 1 addition & 0 deletions environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dependencies:
- click
- furo
- numpy
- pytest
- python
- setuptools_scm
- sphinx
Expand Down
85 changes: 39 additions & 46 deletions tests/test_align.py
Original file line number Diff line number Diff line change
@@ -1,109 +1,102 @@
import unittest

import texplain


class TestAlignTabular(unittest.TestCase):
"""
Alignment of tabular environments.
"""

def test_align_no_newline(self):
text = r"""
def test_tabular_align_no_newline():
text = r"""
\begin{tabular}{ccc}
a & b & c \\
1 & 2 & 3 \\
40 & 50 & 60
\end{tabular}
"""
"""

formatted = r"""
formatted = r"""
\begin{tabular}{ccc}
a & b & c \\
1 & 2 & 3 \\
40 & 50 & 60
\end{tabular}
"""
"""

ret = texplain.indent(text)
self.assertEqual(ret.strip(), formatted.strip())
ret = texplain.indent(text)
assert ret.strip() == formatted.strip()

def test_align_empty(self):
text = r"""

def test_tabular_align_empty():
text = r"""
\begin{tabular}[t]{c}%
\@author
\end{tabular}
"""
"""

formatted = r"""
formatted = r"""
\begin{tabular}[t]{c}%
\@author
\end{tabular}
"""
"""

ret = texplain.indent(text)
assert ret.strip() == formatted.strip()

ret = texplain.indent(text)
self.assertEqual(ret.strip(), formatted.strip())

def test_align_nested(self):
text = r"""
def test_tabular_align_nested():
text = r"""
{
\begin{tabular}[t]{c}%
\@author % foo
\end{tabular}
}
"""
"""

formatted = r"""
formatted = r"""
{
\begin{tabular}[t]{c}%
\@author % foo
\end{tabular}
}
"""
"""

ret = texplain.indent(text)
self.assertEqual(ret.strip(), formatted.strip())
ret = texplain.indent(text)
assert ret.strip() == formatted.strip()

def test_align_empty_leading_column(self):
text = r"""

def test_tabular_align_empty_leading_column():
text = r"""
\begin{tabular}[t]{ccc}
& foo & foobar \\
1 & 2 & 3 \\
4 & 5 & 6
\end{tabular}
"""
"""

formatted = r"""
formatted = r"""
\begin{tabular}[t]{ccc}
& foo & foobar \\
1 & 2 & 3 \\
4 & 5 & 6
\end{tabular}
"""
"""

ret = texplain.indent(text)
assert ret.strip() == formatted.strip()

ret = texplain.indent(text)
self.assertEqual(ret.strip(), formatted.strip())

def test_align_empty_column(self):
text = r"""
def test_tabular_align_empty_column():
text = r"""
\begin{tabular}[t]{ccc}
& foo & foobar \\
& 2 & 3 \\
& 5 & 6
\end{tabular}
"""
"""

formatted = r"""
formatted = r"""
\begin{tabular}[t]{ccc}
& foo & foobar \\
& 2 & 3 \\
& 5 & 6
\end{tabular}
"""

ret = texplain.indent(text)
self.assertEqual(ret.strip(), formatted.strip())

"""

if __name__ == "__main__":
unittest.main()
ret = texplain.indent(text)
assert ret.strip() == formatted.strip()
35 changes: 13 additions & 22 deletions tests/test_bibtex.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
import unittest

import texplain


class MyTests(unittest.TestCase):
def test_bib(self):
bib = {
"foo": ["@article{foo,", "author = {b a},", "title = {b a},", "journal = {b a},", "}"],
"bar": ["@article{bar,", "author = {a b},", "title = {a b},", "journal = {a b},", "}"],
}

bibfile = "\n\n".join(["\n".join(bib[key]) for key in ["foo", "bar"]])
self.assertEqual(texplain.bib_select(bibfile, ["bar", "foo"]).strip(), bibfile.strip())

bibfile = "\n\n".join(["\n".join(bib[key]) for key in ["foo", "bar"]])
reduced = "\n\n".join(["\n".join(bib[key]) for key in ["bar"]])
self.assertEqual(texplain.bib_select(bibfile, ["bar"]).strip(), reduced.strip())
def test_bib():
bib = {
"foo": ["@article{foo,", "author = {b a},", "title = {b a},", "journal = {b a},", "}"],
"bar": ["@article{bar,", "author = {a b},", "title = {a b},", "journal = {a b},", "}"],
}

bibfile = "\n\n".join(["\n".join(bib[key]) for key in ["foo", "bar"]])
reorder = "\n\n".join(["\n".join(bib[key]) for key in ["bar", "foo"]])
self.assertEqual(
texplain.bib_select(bibfile, ["bar", "foo"], reorder=True).strip(), reorder.strip()
)
bibfile = "\n\n".join(["\n".join(bib[key]) for key in ["foo", "bar"]])
assert texplain.bib_select(bibfile, ["bar", "foo"]).strip() == bibfile.strip()

bibfile = "\n\n".join(["\n".join(bib[key]) for key in ["foo", "bar"]])
reduced = "\n\n".join(["\n".join(bib[key]) for key in ["bar"]])
assert texplain.bib_select(bibfile, ["bar"]).strip() == reduced.strip()

if __name__ == "__main__":
unittest.main()
bibfile = "\n\n".join(["\n".join(bib[key]) for key in ["foo", "bar"]])
reorder = "\n\n".join(["\n".join(bib[key]) for key in ["bar", "foo"]])
assert texplain.bib_select(bibfile, ["bar", "foo"], reorder=True).strip() == reorder.strip()
Loading

0 comments on commit 0d5b528

Please sign in to comment.