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
| """ | |
| 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 | |