Coverage for tests / integration / tools / tsc / conftest.py: 88%
33 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Pytest configuration for tsc integration tests."""
3from __future__ import annotations
5import shutil
6import subprocess
7from pathlib import Path
9import pytest
12def tsc_is_available() -> bool:
13 """Check if tsc is installed and actually works.
15 This checks both that the command exists AND that it executes successfully,
16 which handles cases where a wrapper script exists but the underlying
17 tool isn't installed (e.g., Docker image not yet rebuilt).
19 Returns:
20 True if tsc is installed and working, False otherwise.
21 """
22 if shutil.which("tsc") is None:
23 return False
24 try:
25 result = subprocess.run(
26 ["tsc", "--version"],
27 capture_output=True,
28 timeout=10,
29 check=False,
30 )
31 return result.returncode == 0
32 except (subprocess.TimeoutExpired, OSError):
33 return False
36def _find_project_root() -> Path:
37 """Find project root by looking for pyproject.toml.
39 Returns:
40 Path to the project root directory.
42 Raises:
43 RuntimeError: If pyproject.toml is not found in any parent directory.
44 """
45 path = Path(__file__).resolve()
46 for parent in path.parents:
47 if (parent / "pyproject.toml").exists():
48 return parent
49 raise RuntimeError("pyproject.toml not found in parent directories")
52# Paths to test samples
53SAMPLE_DIR = _find_project_root() / "test_samples"
54TSC_SAMPLES = SAMPLE_DIR / "tools" / "typescript" / "tsc"
55CLEAN_SAMPLE = TSC_SAMPLES / "tsc_clean.ts"
56VIOLATION_SAMPLE = TSC_SAMPLES / "tsc_violations.ts"
59@pytest.fixture
60def tsc_violation_file(tmp_path: Path) -> str:
61 """Copy the tsc violation sample to a temp directory.
63 Args:
64 tmp_path: Pytest fixture providing a temporary directory.
66 Returns:
67 Path to the copied file as a string.
68 """
69 dst = tmp_path / "tsc_violations.ts"
70 shutil.copy(VIOLATION_SAMPLE, dst)
71 return str(dst)
74@pytest.fixture
75def tsc_clean_file(tmp_path: Path) -> str:
76 """Copy the tsc clean sample to a temp directory.
78 Args:
79 tmp_path: Pytest fixture providing a temporary directory.
81 Returns:
82 Path to the copied file as a string.
83 """
84 dst = tmp_path / "tsc_clean.ts"
85 shutil.copy(CLEAN_SAMPLE, dst)
86 return str(dst)