Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ repos:
- id: ty
additional_dependencies:
- coverage
- pre-commit
- pytest
- types-setuptools
- typing_extensions; python_version < '3.12'
Expand All @@ -37,6 +38,7 @@ repos:
- id: pyright
additional_dependencies:
- coverage
- pre-commit
- pytest
- types-setuptools
- typing_extensions; python_version < '3.12'
Expand All @@ -50,6 +52,7 @@ repos:
- id: mypy
additional_dependencies:
- coverage
- pre-commit
- pytest
- types-setuptools
- typing_extensions; python_version < '3.12'
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pyright = "pyright_pre_commit.__main__:main"
dev = [
"covdefaults>=2.1.0",
"coverage",
"pre-commit",
"pytest",
]

Expand Down
42 changes: 42 additions & 0 deletions tests/try_repo_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from __future__ import annotations

import os
import subprocess
import sys
import tempfile
from pathlib import Path

REPO_ROOT = Path(__file__).parent.parent


def test_try_repo(tmp_path):
# pre-commit relpaths the repo against cwd, which fails across Windows drives
with tempfile.TemporaryDirectory(dir=REPO_ROOT) as d:
target = Path(d)
(target / "good.py").write_text("x: int = 1\n")
(target / "bad.py").write_text('x: int = "a"\n')
subprocess.check_call(("git", "init", "-q", str(target)))
subprocess.check_call(("git", "-C", str(target), "add", "good.py", "bad.py"))

proc = subprocess.run(
(
sys.executable,
"-m",
"pre_commit",
"try-repo",
str(REPO_ROOT),
"pyright",
"--all-files",
),
check=False,
cwd=target,
env={**os.environ, "PRE_COMMIT_HOME": str(tmp_path / "pre-commit-home")},
capture_output=True,
text=True,
)
output = proc.stdout + proc.stderr

assert proc.returncode == 1, output
assert "bad.py:1:10 - error" in output
assert "good.py:" not in output
assert "1 error, 0 warnings" in output