Add remaining test files: test_fixes, test_llm, test_generate, test_report, test_utils
This commit is contained in:
64
tests/test_utils.py
Normal file
64
tests/test_utils.py
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
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
|
||||||
Reference in New Issue
Block a user