Skip to content

Commit

Permalink
Tidy some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz committed Jun 30, 2024
1 parent acffa03 commit c98972d
Showing 1 changed file with 62 additions and 38 deletions.
100 changes: 62 additions & 38 deletions tests/test_blacken_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,22 +403,26 @@ def test_format_src_latex_minted_opt():
def test_format_src_latex_minted_indented():
# Personaly I would have minted python code all flush left,
# with only the Python code's own four space indentation:
before = (
"hello\n"
" \\begin{minted}{python}\n"
" if True:\n"
" f(1,2,3)\n"
" \\end{minted}\n"
"world!"
before = dedent(
"""\
hello
\\begin{minted}{python}
if True:
f(1,2,3)
\\end{minted}
world!
"""
)
after, _ = blacken_docs.format_str(before, BLACK_MODE)
assert after == (
"hello\n"
" \\begin{minted}{python}\n"
" if True:\n"
" f(1, 2, 3)\n"
" \\end{minted}\n"
"world!"
assert after == dedent(
"""\
hello
\\begin{minted}{python}
if True:
f(1, 2, 3)
\\end{minted}
world!
"""
)


Expand Down Expand Up @@ -531,13 +535,29 @@ def test_format_src_rst():


def test_format_src_rst_literal_blocks():
before = "hello::\n" "\n" " f(1,2,3)\n" "\n" "world\n"
before = dedent(
"""\
hello::
f(1,2,3)
world
"""
)
after, _ = blacken_docs.format_str(
before,
BLACK_MODE,
rst_literal_blocks=True,
)
assert after == ("hello::\n" "\n" " f(1, 2, 3)\n" "\n" "world\n")
assert after == dedent(
"""\
hello::
f(1, 2, 3)
world
"""
)


def test_format_src_rst_literal_blocks_nested():
Expand Down Expand Up @@ -637,30 +657,34 @@ def test_format_src_rst_sphinx_doctest():


def test_format_src_rst_indented():
before = (
".. versionadded:: 3.1\n"
"\n"
" hello\n"
"\n"
" .. code-block:: python\n"
"\n"
" def hi():\n"
" f(1,2,3)\n"
"\n"
" world\n"
before = dedent(
"""\
.. versionadded:: 3.1
hello
.. code-block:: python
def hi():
f(1,2,3)
world
"""
)
after, _ = blacken_docs.format_str(before, BLACK_MODE)
assert after == (
".. versionadded:: 3.1\n"
"\n"
" hello\n"
"\n"
" .. code-block:: python\n"
"\n"
" def hi():\n"
" f(1, 2, 3)\n"
"\n"
" world\n"
assert after == dedent(
"""\
.. versionadded:: 3.1
hello
.. code-block:: python
def hi():
f(1, 2, 3)
world
"""
)


Expand Down

0 comments on commit c98972d

Please sign in to comment.