fix: resolve CI import and type mismatch issues
Some checks failed
Some checks failed
This commit is contained in:
65
tests/test_scanner.py
Normal file
65
tests/test_scanner.py
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
"""Tests for code scanner."""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from src.core.scanner import CodeScanner
|
||||||
|
from src.core.models import IssueCategory, SeverityLevel
|
||||||
|
|
||||||
|
|
||||||
|
class TestCodeScanner:
|
||||||
|
"""Tests for CodeScanner class."""
|
||||||
|
|
||||||
|
def test_scanner_initialization(self):
|
||||||
|
"""Test scanner creates empty issue list."""
|
||||||
|
scanner = CodeScanner()
|
||||||
|
assert scanner.issues == []
|
||||||
|
|
||||||
|
def test_supported_extensions(self):
|
||||||
|
"""Test supported file extensions."""
|
||||||
|
scanner = CodeScanner()
|
||||||
|
assert ".py" in scanner.SUPPORTED_EXTENSIONS
|
||||||
|
assert ".js" in scanner.SUPPORTED_EXTENSIONS
|
||||||
|
assert ".ts" in scanner.SUPPORTED_EXTENSIONS
|
||||||
|
|
||||||
|
def test_scan_single_file(self, tmp_path):
|
||||||
|
"""Test scanning a single file."""
|
||||||
|
test_file = tmp_path / "test.py"
|
||||||
|
test_file.write_text("""
|
||||||
|
def hello():
|
||||||
|
# TODO: implement
|
||||||
|
print("Hello")
|
||||||
|
""")
|
||||||
|
|
||||||
|
scanner = CodeScanner()
|
||||||
|
result = scanner.scan(test_file)
|
||||||
|
|
||||||
|
assert result.files_scanned == 1
|
||||||
|
assert len(result.issues) == 1
|
||||||
|
assert result.issues[0].category == IssueCategory.MAINTAINABILITY
|
||||||
|
assert result.issues[0].severity == SeverityLevel.LOW
|
||||||
|
|
||||||
|
def test_scan_directory(self, tmp_path):
|
||||||
|
"""Test scanning a directory."""
|
||||||
|
test_dir = tmp_path / "project"
|
||||||
|
test_dir.mkdir()
|
||||||
|
|
||||||
|
(test_dir / "test.py").write_text("# TODO: test")
|
||||||
|
(test_dir / "test.js").write_text("// FIXME: fix")
|
||||||
|
|
||||||
|
scanner = CodeScanner()
|
||||||
|
result = scanner.scan(test_dir)
|
||||||
|
|
||||||
|
assert result.files_scanned == 2
|
||||||
|
assert len(result.issues) == 2
|
||||||
|
|
||||||
|
def test_unsupported_file(self, tmp_path):
|
||||||
|
"""Test skipping unsupported files."""
|
||||||
|
test_file = tmp_path / "test.txt"
|
||||||
|
test_file.write_text("TODO: something")
|
||||||
|
|
||||||
|
scanner = CodeScanner()
|
||||||
|
result = scanner.scan(test_file)
|
||||||
|
|
||||||
|
assert result.files_scanned == 0
|
||||||
|
assert len(result.issues) == 0
|
||||||
Reference in New Issue
Block a user