Skip to content

Commit

Permalink
Move configuration tests from test_run to test_config
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed Jan 3, 2022
1 parent 80b2e3d commit 76e8df0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 63 deletions.
64 changes: 64 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from pathlib import Path

import pytest
Expand Down Expand Up @@ -54,3 +55,66 @@ def test_non_existing_options(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.chdir(CONFIG_DATA / "non_existing_options")
with pytest.raises(exceptions.UnrecognizedOption):
pydocstringformatter.run_docstring_formatter(["test_package"])


def test_no_write_argument(capsys: pytest.CaptureFixture[str], test_file: str) -> None:
"""Test that we print to stdout without the -w option"""
pydocstringformatter.run_docstring_formatter([test_file])

with open(test_file, encoding="utf-8") as file:
assert "".join(file.readlines()) == '"""A multi-line\ndocstring"""'

output = capsys.readouterr()
assert output.out == '"""A multi-line\ndocstring\n"""'
assert not output.err


def test_write_argument(capsys: pytest.CaptureFixture[str], test_file: str) -> None:
"""Test the -w argument"""
try:
expected_path = os.path.relpath(test_file)
except ValueError:
expected_path = test_file

pydocstringformatter.run_docstring_formatter([test_file, "-w"])

with open(test_file, encoding="utf-8") as file:
assert "".join(file.readlines()) == '"""A multi-line\ndocstring\n"""'

output = capsys.readouterr()
assert output.out == f"Formatted {expected_path} 📖\n"
assert not output.err


def test_long_write_argument(
capsys: pytest.CaptureFixture[str], test_file: str
) -> None:
"""Test the --write argument"""
try:
expected_path = os.path.relpath(test_file)
except ValueError:
expected_path = test_file

pydocstringformatter.run_docstring_formatter([test_file, "--write"])

with open(test_file, encoding="utf-8") as file:
assert "".join(file.readlines()) == '"""A multi-line\ndocstring\n"""'

output = capsys.readouterr()
assert output.out == f"Formatted {expected_path} 📖\n"
assert not output.err


def test_version_argument(capsys: pytest.CaptureFixture[str]) -> None:
"""Test the --version argument and its shorter variant"""
with pytest.raises(SystemExit):
pydocstringformatter.run_docstring_formatter(["--version"])
output = capsys.readouterr()
assert output.out == pydocstringformatter.__version__ + "\n"
assert not output.err

with pytest.raises(SystemExit):
pydocstringformatter.run_docstring_formatter(["-v"])
output = capsys.readouterr()
assert output.out == pydocstringformatter.__version__ + "\n"
assert not output.err
63 changes: 0 additions & 63 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,69 +32,6 @@ def test_sys_agv_as_arguments(
assert not output.err


def test_no_write_argument(capsys: pytest.CaptureFixture[str], test_file: str) -> None:
"""Test that we print to stdout without the -w option"""
pydocstringformatter.run_docstring_formatter([test_file])

with open(test_file, encoding="utf-8") as file:
assert "".join(file.readlines()) == '"""A multi-line\ndocstring"""'

output = capsys.readouterr()
assert output.out == '"""A multi-line\ndocstring\n"""'
assert not output.err


def test_write_argument(capsys: pytest.CaptureFixture[str], test_file: str) -> None:
"""Test the -w argument"""
try:
expected_path = os.path.relpath(test_file)
except ValueError:
expected_path = test_file

pydocstringformatter.run_docstring_formatter([test_file, "-w"])

with open(test_file, encoding="utf-8") as file:
assert "".join(file.readlines()) == '"""A multi-line\ndocstring\n"""'

output = capsys.readouterr()
assert output.out == f"Formatted {expected_path} 📖\n"
assert not output.err


def test_long_write_argument(
capsys: pytest.CaptureFixture[str], test_file: str
) -> None:
"""Test the --write argument"""
try:
expected_path = os.path.relpath(test_file)
except ValueError:
expected_path = test_file

pydocstringformatter.run_docstring_formatter([test_file, "--write"])

with open(test_file, encoding="utf-8") as file:
assert "".join(file.readlines()) == '"""A multi-line\ndocstring\n"""'

output = capsys.readouterr()
assert output.out == f"Formatted {expected_path} 📖\n"
assert not output.err


def test_version_argument(capsys: pytest.CaptureFixture[str]) -> None:
"""Test the --version argument and its shorter variant"""
with pytest.raises(SystemExit):
pydocstringformatter.run_docstring_formatter(["--version"])
output = capsys.readouterr()
assert output.out == pydocstringformatter.__version__ + "\n"
assert not output.err

with pytest.raises(SystemExit):
pydocstringformatter.run_docstring_formatter(["-v"])
output = capsys.readouterr()
assert output.out == pydocstringformatter.__version__ + "\n"
assert not output.err


def test_output_message_nothing_done(
capsys: pytest.CaptureFixture[str], test_file: str
) -> None:
Expand Down

0 comments on commit 76e8df0

Please sign in to comment.