|
import os |
|
import sys |
|
import unittest |
|
from pathlib import Path |
|
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent.parent / "src")) |
|
|
|
from image_processing_tool import ImageProcessor |
|
from file_processing_tool import FileIdentifier, process_image_file |
|
|
|
class TestImageProcessingTool(unittest.TestCase): |
|
def setUp(self): |
|
self.image_processor = ImageProcessor() |
|
self.file_identifier = FileIdentifier() |
|
self.test_image_path = str(Path(__file__).parent.parent / "data/downloaded_files" / "cca530fc-4052-43b2-b130-b30968d8aa44.png") |
|
|
|
|
|
self.assertTrue(os.path.exists(self.test_image_path), f"Test image not found: {self.test_image_path}") |
|
|
|
def test_file_identification(self): |
|
"""Test that the FileIdentifier correctly identifies the PNG image.""" |
|
file_info = self.file_identifier.identify_file(self.test_image_path) |
|
self.assertEqual(file_info.get('determined_type'), "image", "File should be identified as an image") |
|
self.assertEqual(file_info.get('suggested_action'), "image_processor", "Action should be image_processor") |
|
|
|
def test_image_details(self): |
|
"""Test getting basic image details.""" |
|
details = self.image_processor.get_image_details(self.test_image_path) |
|
self.assertIsNotNone(details, "Should return image details") |
|
self.assertIn("width", details, "Should include width in details") |
|
self.assertIn("height", details, "Should include height in details") |
|
self.assertIn("format", details, "Should include format in details") |
|
|
|
def test_image_processing(self): |
|
"""Test basic image processing functionality.""" |
|
result = self.image_processor.process_image(self.test_image_path) |
|
self.assertIsNotNone(result, "Should return processing result") |
|
self.assertIsInstance(result, str, "Result should be a string") |
|
|
|
def test_text_extraction(self): |
|
"""Test OCR text extraction functionality.""" |
|
text = self.image_processor.extract_text_from_image(self.test_image_path) |
|
self.assertIsNotNone(text, "Should return extracted text") |
|
self.assertIsInstance(text, str, "Extracted text should be a string") |
|
|
|
def test_chess_analysis(self): |
|
"""Test chess position analysis.""" |
|
analysis = self.image_processor.analyze_chess_position(self.test_image_path) |
|
self.assertIsNotNone(analysis, "Should return chess analysis") |
|
if isinstance(analysis, dict): |
|
self.assertIn("recommended_move", analysis, "Should include recommended move") |
|
self.assertEqual(analysis["recommended_move"], "Rd5", "Recommended move should be 'Rd5'") |
|
|
|
def test_process_image_file_function(self): |
|
"""Test the integrated process_image_file function.""" |
|
result = process_image_file(self.test_image_path) |
|
self.assertIsNotNone(result, "Should return processing result") |
|
self.assertIn("details", result, "Should include image details") |
|
self.assertIn("extracted_text", result, "Should include extracted text") |
|
|
|
if __name__ == '__main__': |
|
unittest.main() |
|
|