Coverage for tests / integration / tools / shellcheck / conftest.py: 93%
29 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"""Shared fixtures for ShellCheck integration tests.
3These tests require shellcheck to be installed and available in PATH.
4"""
6from __future__ import annotations
8import shutil
9from pathlib import Path
11import pytest
13# Path to test samples
14SAMPLE_DIR = Path(__file__).parent.parent.parent.parent.parent / "test_samples"
15SHELLCHECK_SAMPLES = SAMPLE_DIR / "tools" / "shell" / "shellcheck"
17# Validate sample paths exist at import time for clearer error messages
18if not SHELLCHECK_SAMPLES.exists():
19 raise FileNotFoundError(
20 f"ShellCheck test samples not found at: {SHELLCHECK_SAMPLES}",
21 )
23# Sample file paths
24VIOLATIONS_SAMPLE = SHELLCHECK_SAMPLES / "shellcheck_violations.sh"
25CLEAN_SAMPLE = SHELLCHECK_SAMPLES / "shellcheck_clean.sh"
26STYLE_ISSUES_SAMPLE = SHELLCHECK_SAMPLES / "shellcheck_style_issues.sh"
28# Validate sample files exist
29for sample in (VIOLATIONS_SAMPLE, CLEAN_SAMPLE, STYLE_ISSUES_SAMPLE):
30 if not sample.exists():
31 raise FileNotFoundError(f"ShellCheck sample file not found: {sample}")
34@pytest.fixture
35def shellcheck_violation_file(tmp_path: Path) -> str:
36 """Create a temporary copy of the shellcheck violations sample file.
38 Args:
39 tmp_path: Pytest fixture providing a temporary directory.
41 Returns:
42 Path to the copied file as a string.
43 """
44 dst = tmp_path / "shellcheck_violations.sh"
45 shutil.copy(VIOLATIONS_SAMPLE, dst)
46 return str(dst)
49@pytest.fixture
50def shellcheck_clean_file(tmp_path: Path) -> str:
51 """Create a temporary copy of the clean shellcheck sample file.
53 Args:
54 tmp_path: Pytest fixture providing a temporary directory.
56 Returns:
57 Path to the copied file as a string.
58 """
59 dst = tmp_path / "shellcheck_clean.sh"
60 shutil.copy(CLEAN_SAMPLE, dst)
61 return str(dst)
64@pytest.fixture
65def shellcheck_style_issues_file(tmp_path: Path) -> str:
66 """Create a temporary copy of the shellcheck style issues sample file.
68 Args:
69 tmp_path: Pytest fixture providing a temporary directory.
71 Returns:
72 Path to the copied file as a string.
73 """
74 dst = tmp_path / "shellcheck_style_issues.sh"
75 shutil.copy(STYLE_ISSUES_SAMPLE, dst)
76 return str(dst)