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

1"""Shared fixtures for ShellCheck integration tests. 

2 

3These tests require shellcheck to be installed and available in PATH. 

4""" 

5 

6from __future__ import annotations 

7 

8import shutil 

9from pathlib import Path 

10 

11import pytest 

12 

13# Path to test samples 

14SAMPLE_DIR = Path(__file__).parent.parent.parent.parent.parent / "test_samples" 

15SHELLCHECK_SAMPLES = SAMPLE_DIR / "tools" / "shell" / "shellcheck" 

16 

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 ) 

22 

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" 

27 

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}") 

32 

33 

34@pytest.fixture 

35def shellcheck_violation_file(tmp_path: Path) -> str: 

36 """Create a temporary copy of the shellcheck violations sample file. 

37 

38 Args: 

39 tmp_path: Pytest fixture providing a temporary directory. 

40 

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) 

47 

48 

49@pytest.fixture 

50def shellcheck_clean_file(tmp_path: Path) -> str: 

51 """Create a temporary copy of the clean shellcheck sample file. 

52 

53 Args: 

54 tmp_path: Pytest fixture providing a temporary directory. 

55 

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) 

62 

63 

64@pytest.fixture 

65def shellcheck_style_issues_file(tmp_path: Path) -> str: 

66 """Create a temporary copy of the shellcheck style issues sample file. 

67 

68 Args: 

69 tmp_path: Pytest fixture providing a temporary directory. 

70 

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)