Files
config-auditor-cli/tests/test_utils.py
7000pctAUTO 1597fa5ee1
Some checks failed
CI / test (push) Failing after 10s
CI / build (push) Has been skipped
Add remaining test files: test_fixes, test_llm, test_generate, test_report, test_utils
2026-01-30 18:05:18 +00:00

65 lines
1.9 KiB
Python

import pytest
from pathlib import Path
import tempfile
from config_auditor.utils import (
find_config_file,
get_exit_code,
validate_path,
)
class TestUtils:
def test_find_config_file_exists(self):
with tempfile.TemporaryDirectory() as tmpdir:
(Path(tmpdir) / "package.json").write_text("{}")
result = find_config_file(Path(tmpdir), ["package.json"])
assert result is not None
assert result.name == "package.json"
def test_find_config_file_not_exists(self):
with tempfile.TemporaryDirectory() as tmpdir:
result = find_config_file(Path(tmpdir), ["nonexistent.json"])
assert result is None
def test_find_config_file_in_parent(self):
with tempfile.TemporaryDirectory() as tmpdir:
subdir = Path(tmpdir) / "subdir"
subdir.mkdir()
(Path(tmpdir) / "package.json").write_text("{}")
result = find_config_file(subdir, ["package.json"])
assert result is not None
def test_get_exit_code_no_issues(self):
result = get_exit_code(0, 0)
assert result == 0
def test_get_exit_code_has_issues(self):
result = get_exit_code(5, 0)
assert result == 4
def test_get_exit_code_critical(self):
result = get_exit_code(3, 2)
assert result == 4
def test_validate_path_exists(self):
with tempfile.TemporaryDirectory() as tmpdir:
result = validate_path(tmpdir)
assert result.exists()
def test_validate_path_not_exists(self):
with pytest.raises(SystemExit) as excinfo:
validate_path("/nonexistent/path")
assert excinfo.value.code == 2
def test_validate_path_is_file(self):
with tempfile.NamedTemporaryFile() as f:
with pytest.raises(SystemExit) as excinfo:
validate_path(f.name)
assert excinfo.value.code == 2