From 1597fa5ee1010a7310ab84ec2dda0ce0c202bddf Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Fri, 30 Jan 2026 18:05:18 +0000 Subject: [PATCH] Add remaining test files: test_fixes, test_llm, test_generate, test_report, test_utils --- tests/test_utils.py | 64 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/test_utils.py diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..eb6fa87 --- /dev/null +++ b/tests/test_utils.py @@ -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