HF_Agents_Final_Project / tests /test_chess_image.py
Yago Bolivar
feat: implement image processing and chess analysis tools with unit tests
8ff7d8f
import os
import sys
import json
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"))
# Import the module directly from the path
src_dir = str(Path(__file__).parent.parent / "src")
sys.path.insert(0, src_dir)
def main():
print("Testing chess image analysis")
# 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 file_processing_tool import process_image_file
# Process the image using our file processing tool
result = process_image_file(test_image)
# Display the result
chess_analysis = result.get("chess_analysis", None)
if chess_analysis and isinstance(chess_analysis, dict) and "recommended_move" in chess_analysis:
print("\nChess Position Analysis:")
print(f"Recommended move: {chess_analysis['recommended_move']}")
print(f"Explanation: {chess_analysis.get('explanation', 'No explanation provided')}")
# Demonstrate how this can be used to answer the question
question = "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"\nQuestion: {question}")
print(f"Answer: {chess_analysis['recommended_move']}")
else:
print("\nCould not determine the answer from the analysis.")
if result.get("error"):
print(f"Error: {result['error']}")
if __name__ == "__main__":
main()