From 1b0eac8fa0f4656b19e7e65ec799aae2d6c80f18 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Thu, 5 Feb 2026 11:53:21 +0000 Subject: [PATCH] fix: resolve CI linting and dependency issues --- tests/test_utils.py | 131 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 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..c78cf5c --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,131 @@ +"""Tests for utility modules.""" + +import tempfile +from pathlib import Path + +from src.auto_readme.utils.file_scanner import FileScanner +from src.auto_readme.utils.path_utils import PathUtils + + +class TestPathUtils: + """Tests for PathUtils.""" + + def test_normalize_path(self): + """Test path normalization.""" + path = PathUtils.normalize_path("./foo/bar") + assert path.is_absolute() + + def test_is_ignored_dir(self): + """Test ignored directory detection.""" + assert PathUtils.is_ignored_dir(Path("__pycache__")) + assert PathUtils.is_ignored_dir(Path(".git")) + assert PathUtils.is_ignored_dir(Path("node_modules")) + assert not PathUtils.is_ignored_dir(Path("src")) + + def test_is_ignored_file(self): + """Test ignored file detection.""" + assert PathUtils.is_ignored_file(Path(".gitignore")) + assert not PathUtils.is_ignored_file(Path("main.py")) + + def test_is_source_file(self): + """Test source file detection.""" + assert PathUtils.is_source_file(Path("main.py")) + assert PathUtils.is_source_file(Path("index.js")) + assert PathUtils.is_source_file(Path("main.go")) + assert PathUtils.is_source_file(Path("lib.rs")) + assert not PathUtils.is_source_file(Path("README.md")) + + def test_is_config_file(self): + """Test config file detection.""" + assert PathUtils.is_config_file(Path("config.json")) + assert PathUtils.is_config_file(Path("settings.yaml")) + assert PathUtils.is_config_file(Path("pyproject.toml")) + + def test_is_test_file(self): + """Test test file detection.""" + assert PathUtils.is_test_file(Path("test_main.py")) + assert PathUtils.is_test_file(Path("tests/utils.py")) + assert PathUtils.is_test_file(Path("example.test.js")) + assert not PathUtils.is_test_file(Path("main.py")) + + def test_is_hidden(self): + """Test hidden file detection.""" + assert PathUtils.is_hidden(Path(".gitignore")) + assert not PathUtils.is_hidden(Path("main.py")) + + def test_detect_project_root(self): + """Test project root detection.""" + with tempfile.TemporaryDirectory() as tmp_dir: + root = Path(tmp_dir) + subdir = root / "src" / "package" + subdir.mkdir(parents=True) + + (root / "pyproject.toml").touch() + + detected = PathUtils.detect_project_root(subdir) + assert detected == root + + def test_get_relative_path(self): + """Test relative path calculation.""" + base = Path("/home/user/project") + target = Path("/home/user/project/src/main.py") + relative = PathUtils.get_relative_path(target, base) + assert relative == Path("src/main.py") + + +class TestFileScanner: + """Tests for FileScanner.""" + + def test_scan_python_project(self, create_python_project): + """Test scanning a Python project.""" + scanner = FileScanner(create_python_project) + files = scanner.scan_and_create() + + file_names = {f.path.name for f in files} + assert "main.py" in file_names + assert "__init__.py" in file_names + assert "requirements.txt" in file_names + assert "pyproject.toml" in file_names + + def test_detect_project_type_python(self, create_python_project): + """Test project type detection for Python.""" + from src.auto_readme.models import ProjectType + + scanner = FileScanner(create_python_project) + project_type = scanner.detect_project_type() + + assert project_type == ProjectType.PYTHON + + def test_detect_project_type_javascript(self, create_javascript_project): + """Test project type detection for JavaScript.""" + from src.auto_readme.models import ProjectType + + scanner = FileScanner(create_javascript_project) + project_type = scanner.detect_project_type() + + assert project_type == ProjectType.JAVASCRIPT + + def test_detect_project_type_go(self, create_go_project): + """Test project type detection for Go.""" + from src.auto_readme.models import ProjectType + + scanner = FileScanner(create_go_project) + project_type = scanner.detect_project_type() + + assert project_type == ProjectType.GO + + def test_detect_project_type_rust(self, create_rust_project): + """Test project type detection for Rust.""" + from src.auto_readme.models import ProjectType + + scanner = FileScanner(create_rust_project) + project_type = scanner.detect_project_type() + + assert project_type == ProjectType.RUST + + def test_scan_mixed_project(self, create_mixed_project): + """Test scanning a project with multiple languages.""" + scanner = FileScanner(create_mixed_project) + files = scanner.scan_and_create() + + assert len(files) > 0