CodeMind / tests /test_phi2.py
devjas1
(FEAT)[Enhance test suite for Phi-2 model]: add comprehensive tests for configuration loading, module imports, and fallback functionality in test_phi2.py.
198f016
raw
history blame
3.74 kB
"""
Test script for Phi-2 model loading and basic functionality.
Tests both embedding and generation models.
"""
import sys
import os
import warnings
warnings.filterwarnings("ignore")
# Add parent directory to path to import src modules
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
from src.config_loader import load_config
def test_config_loading():
"""Test configuration loading"""
try:
config = load_config("config.yaml")
print("βœ“ Configuration loaded successfully")
# Validate required keys
assert "embedding" in config
assert "generator" in config
assert "retrieval" in config
print("βœ“ Configuration structure is valid")
return config
except Exception as e:
print(f"βœ— Configuration test failed: {e}")
return None
def test_embedder_imports():
"""Test embedder module can be imported"""
try:
from src.embedder import embed_documents
print("βœ“ Embedder module imports successfully")
return True
except Exception as e:
print(f"βœ— Embedder import failed: {e}")
return False
def test_generator_imports():
"""Test generator module can be imported"""
try:
from src.generator import generate_commit_message, fallback_commit_message
print("βœ“ Generator module imports successfully")
return True
except Exception as e:
print(f"βœ— Generator import failed: {e}")
return False
def test_retriever_imports():
"""Test retriever module can be imported"""
try:
from src.retriever import search_documents
print("βœ“ Retriever module imports successfully")
return True
except Exception as e:
print(f"βœ— Retriever import failed: {e}")
return False
def test_diff_analyzer():
"""Test diff analyzer module"""
try:
from src.diff_analyzer import get_staged_diff_chunks
print("βœ“ Diff analyzer module imports successfully")
# Test basic functionality (should work even without git repo)
file_list, chunks = get_staged_diff_chunks()
print(
f"βœ“ Diff analyzer executes (found {len(file_list)} files, {len(chunks)} chunks)"
)
return True
except Exception as e:
print(f"βœ— Diff analyzer test failed: {e}")
return False
def test_fallback_functionality():
"""Test fallback functions work without models"""
try:
from src.generator import fallback_commit_message
# Test fallback message generation
message = fallback_commit_message(["file1.py", "file2.py"])
print(f"βœ“ Fallback commit message: '{message}'")
return True
except Exception as e:
print(f"βœ— Fallback functionality test failed: {e}")
return False
if __name__ == "__main__":
print("Running CodeMind functionality tests...\n")
# Run all tests
tests = [
test_config_loading,
test_embedder_imports,
test_generator_imports,
test_retriever_imports,
test_diff_analyzer,
test_fallback_functionality,
]
passed = 0
total = len(tests)
for test in tests:
try:
result = test()
if result:
passed += 1
except Exception as e:
print(f"βœ— Test {test.__name__} crashed: {e}")
print()
print(f"Tests passed: {passed}/{total}")
if passed == total:
print("πŸŽ‰ All tests passed! CodeMind is ready for use.")
else:
print("⚠️ Some tests failed. Check dependencies and configuration.")
sys.exit(0 if passed == total else 1)
# pylint: skip-file