Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move from tmpdir pytest fixture to tmp_path #206

Merged
merged 1 commit into from Jan 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 36 additions & 36 deletions tests/blacken_docs_test.py
Expand Up @@ -157,7 +157,7 @@ def test_format_src_latex_minted_pycon_indented():
)


def test_src_pythontex(tmpdir):
def test_src_pythontex():
before = (
'hello\n'
'\\begin{pyblock}\n'
Expand Down Expand Up @@ -305,49 +305,49 @@ def test_format_src_rst_python_inside_non_python_code_block():
assert after == before


def test_integration_ok(tmpdir, capsys):
f = tmpdir.join('f.md')
f.write(
def test_integration_ok(tmp_path, capsys):
f = tmp_path / 'f.md'
f.write_text(
'```python\n'
'f(1, 2, 3)\n'
'```\n',
)
assert not blacken_docs.main((str(f),))
assert not capsys.readouterr()[1]
assert f.read() == (
assert f.read_text() == (
'```python\n'
'f(1, 2, 3)\n'
'```\n'
)


def test_integration_modifies(tmpdir, capsys):
f = tmpdir.join('f.md')
f.write(
def test_integration_modifies(tmp_path, capsys):
f = tmp_path / 'f.md'
f.write_text(
'```python\n'
'f(1,2,3)\n'
'```\n',
)
assert blacken_docs.main((str(f),))
out, _ = capsys.readouterr()
assert out == f'{f}: Rewriting...\n'
assert f.read() == (
assert f.read_text() == (
'```python\n'
'f(1, 2, 3)\n'
'```\n'
)


def test_integration_line_length(tmpdir):
f = tmpdir.join('f.md')
f.write(
def test_integration_line_length(tmp_path):
f = tmp_path / 'f.md'
f.write_text(
'```python\n'
'foo(very_very_very_very_very_very_very, long_long_long_long_long)\n'
'```\n',
)
assert not blacken_docs.main((str(f), '--line-length=80'))
assert blacken_docs.main((str(f), '--line-length=50'))
assert f.read() == (
assert f.read_text() == (
'```python\n'
'foo(\n'
' very_very_very_very_very_very_very,\n'
Expand All @@ -357,9 +357,9 @@ def test_integration_line_length(tmpdir):
)


def test_integration_py36(tmpdir):
f = tmpdir.join('f.md')
f.write(
def test_integration_py36(tmp_path):
f = tmp_path / 'f.md'
f.write_text(
'```python\n'
'def very_very_long_function_name(\n'
' very_very_very_very_very_very,\n'
Expand All @@ -371,7 +371,7 @@ def test_integration_py36(tmpdir):
)
assert not blacken_docs.main((str(f),))
assert blacken_docs.main((str(f), '--target-version=py36'))
assert f.read() == (
assert f.read_text() == (
'```python\n'
'def very_very_long_function_name(\n'
' very_very_very_very_very_very,\n'
Expand All @@ -383,9 +383,9 @@ def test_integration_py36(tmpdir):
)


def test_integration_filename_last(tmpdir):
f = tmpdir.join('f.md')
f.write(
def test_integration_filename_last(tmp_path):
f = tmp_path / 'f.md'
f.write_text(
'```python\n'
'def very_very_long_function_name(\n'
' very_very_very_very_very_very,\n'
Expand All @@ -397,7 +397,7 @@ def test_integration_filename_last(tmpdir):
)
assert not blacken_docs.main((str(f),))
assert blacken_docs.main(('--target-version', 'py36', str(f)))
assert f.read() == (
assert f.read_text() == (
'```python\n'
'def very_very_long_function_name(\n'
' very_very_very_very_very_very,\n'
Expand All @@ -409,9 +409,9 @@ def test_integration_filename_last(tmpdir):
)


def test_integration_multiple_target_version(tmpdir):
f = tmpdir.join('f.md')
f.write(
def test_integration_multiple_target_version(tmp_path):
f = tmp_path / 'f.md'
f.write_text(
'```python\n'
'def very_very_long_function_name(\n'
' very_very_very_very_very_very,\n'
Expand All @@ -427,41 +427,41 @@ def test_integration_multiple_target_version(tmpdir):
)


def test_integration_skip_string_normalization(tmpdir):
f = tmpdir.join('f.md')
f.write(
def test_integration_skip_string_normalization(tmp_path):
f = tmp_path / 'f.md'
f.write_text(
'```python\n'
"f('hi')\n"
'```\n',
)
assert not blacken_docs.main((str(f), '--skip-string-normalization'))
assert f.read() == (
assert f.read_text() == (
'```python\n'
"f('hi')\n"
'```\n'
)


def test_integration_syntax_error(tmpdir, capsys):
f = tmpdir.join('f.md')
f.write(
def test_integration_syntax_error(tmp_path, capsys):
f = tmp_path / 'f.md'
f.write_text(
'```python\n'
'f(\n'
'```\n',
)
assert blacken_docs.main((str(f),))
out, _ = capsys.readouterr()
assert out.startswith(f'{f}:1: code block parse error')
assert f.read() == (
assert f.read_text() == (
'```python\n'
'f(\n'
'```\n'
)


def test_integration_ignored_syntax_error(tmpdir, capsys):
f = tmpdir.join('f.md')
f.write(
def test_integration_ignored_syntax_error(tmp_path, capsys):
f = tmp_path / 'f.md'
f.write_text(
'```python\n'
'f( )\n'
'```\n'
Expand All @@ -472,7 +472,7 @@ def test_integration_ignored_syntax_error(tmpdir, capsys):
)
assert blacken_docs.main((str(f), '--skip-errors'))
out, _ = capsys.readouterr()
assert f.read() == (
assert f.read_text() == (
'```python\n'
'f()\n'
'```\n'
Expand Down