Coverage for tests / unit / tools / shellcheck / test_error_handling.py: 100%
13 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"""Unit tests for shellcheck plugin error handling and edge cases."""
3from __future__ import annotations
5import subprocess
6from pathlib import Path
7from unittest.mock import patch
9from assertpy import assert_that
11from lintro.tools.definitions.shellcheck import ShellcheckPlugin
13# Tests for timeout handling
16def test_check_with_timeout(
17 shellcheck_plugin: ShellcheckPlugin,
18 tmp_path: Path,
19) -> None:
20 """Check handles timeout correctly.
22 Args:
23 shellcheck_plugin: The ShellcheckPlugin instance to test.
24 tmp_path: Temporary directory path for test files.
25 """
26 test_file = tmp_path / "test_script.sh"
27 test_file.write_text('#!/bin/bash\necho "Hello"\n')
29 with patch.object(
30 shellcheck_plugin,
31 "_run_subprocess",
32 side_effect=subprocess.TimeoutExpired(cmd=["shellcheck"], timeout=30),
33 ):
34 result = shellcheck_plugin.check([str(test_file)], {})
36 assert_that(result.success).is_false()
37 # The timeout should be recorded in the output
38 assert_that(result.output).contains("timeout")