Skip to content

Commit

Permalink
Improve Python source tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz committed Jun 30, 2024
1 parent f4606c7 commit acffa03
Showing 1 changed file with 51 additions and 22 deletions.
73 changes: 51 additions & 22 deletions tests/test_blacken_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,35 +980,64 @@ def test_format_src_rst_jupyter_sphinx_with_directive():
)


def test_works_on_python_docstrings():
before = '''\
def f():
"""hello world
def test_format_src_python_docstring_markdown():
before = dedent(
'''\
def f():
"""
hello world
.. code-block:: python
```python
f(1,2,3)
```
"""
pass
'''
)
after, _ = blacken_docs.format_str(before, BLACK_MODE)
assert after == dedent(
'''\
def f():
"""
hello world
f(1,2,3)
```python
f(1, 2, 3)
```
"""
pass
'''
)

```python
f(1,2,3)
```
"""
'''
expected = '''\
def f():
"""hello world

.. code-block:: python
def test_format_src_python_docstring_rst():
before = dedent(
'''\
def f():
"""
hello world
f(1, 2, 3)
.. code-block:: python
```python
f(1, 2, 3)
```
"""
'''
f(1,2,3)
"""
pass
'''
)
after, _ = blacken_docs.format_str(before, BLACK_MODE)
assert after == expected
assert after == dedent(
'''\
def f():
"""
hello world
.. code-block:: python
f(1, 2, 3)
"""
pass
'''
)


def test_format_src_rst_pycon():
Expand Down

0 comments on commit acffa03

Please sign in to comment.