HF_Agents_Final_Project / tests /test_chess_analysis.py
Yago Bolivar
feat: implement image processing and chess analysis tools with unit tests
8ff7d8f
#!/usr/bin/env python3
# filepath: /Users/yagoairm2/Desktop/agents/final project/HF_Agents_Final_Project/tests/test_chess_analysis.py
"""
Test the non-hardcoded chess image analysis implementation
"""
import os
import sys
from pathlib import Path
# Add the src directory to the path so we can import the modules
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
def main():
"""Test the chess image analysis with our new implementation"""
print("Testing chess image analysis with OpenCV and chess engine")
# Path to the test chess image
test_image = str(Path(__file__).parent.parent / "data/downloaded_files" / "cca530fc-4052-43b2-b130-b30968d8aa44.png")
if not os.path.exists(test_image):
print(f"Error: Test image not found at {test_image}")
return
print(f"Processing chess image: {test_image}")
# Import here to avoid dependency issues
from image_processing_tool import ImageProcessor
# Create image processor
processor = ImageProcessor()
# Process the image directly with our new implementation
result = processor.analyze_chess_position(test_image)
# Display the results
if isinstance(result, dict):
print("\nChess Position Analysis Results:")
for key, value in result.items():
print(f"{key}: {value}")
# Extract the move recommendation for the question answer
if "recommended_move" in result:
print("\nQuestion: Review the chess position provided in the image. It is black's turn. Provide the correct next move for black which guarantees a win. Please provide your response in algebraic notation.")
print(f"Answer: {result['recommended_move']}")
else:
print("\nUnexpected result format:")
print(result)
if __name__ == "__main__":
main()