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

test: exec the codespell executable consistently #3267

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions codespell_lib/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import sys
from io import StringIO
from pathlib import Path
from shutil import copyfile
from typing import Any, Generator, Optional, Tuple, Union
from shutil import copyfile, copytree
from typing import Any, Generator, Tuple, Union

import pytest

Expand Down Expand Up @@ -64,13 +64,15 @@ def main(


def run_codespell(
args: Tuple[Any, ...] = (),
cwd: Optional[Path] = None,
args: Tuple[Any, ...],
cwd: Path,
) -> int:
"""Run codespell."""
lib = "codespell_lib"
copytree(lib, cwd / lib, dirs_exist_ok=True)
DimitriPapadopoulos marked this conversation as resolved.
Show resolved Hide resolved
args = tuple(str(arg) for arg in args)
proc = subprocess.run(
["codespell", "--count", *args], # noqa: S603, S607
[sys.executable, "-m", lib, "-S", lib, "--count", *args], # noqa: S603, S607
cwd=cwd,
capture_output=True,
encoding="utf-8",
Expand All @@ -83,9 +85,9 @@ def run_codespell(
def test_command(tmp_path: Path) -> None:
"""Test running the codespell executable."""
# With no arguments does "."
assert run_codespell(cwd=tmp_path) == 0
assert run_codespell(args=(), cwd=tmp_path) == 0
(tmp_path / "bad.txt").write_text("abandonned\nAbandonned\nABANDONNED\nAbAnDoNnEd")
assert run_codespell(cwd=tmp_path) == 4
assert run_codespell(args=(), cwd=tmp_path) == 4


def test_basic(
Expand Down Expand Up @@ -1196,11 +1198,13 @@ def FakeStdin(text: str) -> Generator[None, None, None]:
def run_codespell_stdin(
text: str,
args: Tuple[Any, ...],
cwd: Optional[Path] = None,
cwd: Path,
) -> int:
"""Run codespell in stdin mode and return number of lines in output."""
lib = "codespell_lib"
copytree(lib, cwd / lib, dirs_exist_ok=True)
proc = subprocess.run(
["codespell", *args, "-"], # noqa: S603, S607
[sys.executable, "-m", lib, "-S", lib, *args, "-"], # noqa: S603, S607
cwd=cwd,
input=text,
capture_output=True,
Expand Down
Loading