| """ |
| Testes básicos para o AgentPDF. |
| |
| Este módulo contém testes unitários básicos para verificar |
| o funcionamento dos componentes principais. |
| """ |
|
|
| import unittest |
| import os |
| import sys |
| from pathlib import Path |
|
|
| |
| root_dir = Path(__file__).parent.parent |
| sys.path.insert(0, str(root_dir)) |
|
|
| from utils.config import Config |
| from utils.logger import setup_logger |
| from agents.state import PDFState, ProcessingStatus |
|
|
|
|
| class TestConfig(unittest.TestCase): |
| """Testes para a configuração.""" |
| |
| def test_config_attributes(self): |
| """Testa se os atributos de configuração existem.""" |
| self.assertTrue(hasattr(Config, 'DEFAULT_MODEL')) |
| self.assertTrue(hasattr(Config, 'CHUNK_SIZE')) |
| self.assertTrue(hasattr(Config, 'TOP_K_DOCUMENTS')) |
| |
| def test_model_config(self): |
| """Testa a configuração do modelo.""" |
| model_config = Config.get_model_config() |
| self.assertIn('model', model_config) |
| self.assertIn('temperature', model_config) |
| self.assertIn('max_tokens', model_config) |
| |
| def test_text_splitter_config(self): |
| """Testa a configuração do text splitter.""" |
| splitter_config = Config.get_text_splitter_config() |
| self.assertIn('chunk_size', splitter_config) |
| self.assertIn('chunk_overlap', splitter_config) |
|
|
|
|
| class TestState(unittest.TestCase): |
| """Testes para as estruturas de estado.""" |
| |
| def test_processing_status(self): |
| """Testa os status de processamento.""" |
| self.assertEqual(ProcessingStatus.IDLE, "idle") |
| self.assertEqual(ProcessingStatus.LOADING_PDF, "loading_pdf") |
| self.assertEqual(ProcessingStatus.ERROR, "error") |
| |
| def test_pdf_state_structure(self): |
| """Testa a estrutura do PDFState.""" |
| |
| self.assertTrue(hasattr(PDFState, '__annotations__')) |
| |
| |
| annotations = PDFState.__annotations__ |
| self.assertIn('messages', annotations) |
| self.assertIn('pdf_path', annotations) |
| self.assertIn('processing_status', annotations) |
|
|
|
|
| class TestLogger(unittest.TestCase): |
| """Testes para o sistema de logging.""" |
| |
| def test_logger_creation(self): |
| """Testa a criação do logger.""" |
| logger = setup_logger("test", "INFO") |
| self.assertIsNotNone(logger) |
| self.assertEqual(logger.name, "test") |
|
|
|
|
| class TestDirectories(unittest.TestCase): |
| """Testes para estrutura de diretórios.""" |
| |
| def test_required_directories_exist(self): |
| """Testa se os diretórios necessários existem.""" |
| required_dirs = [ |
| 'agents', |
| 'nodes', |
| 'utils', |
| 'gradio', |
| 'uploaded_data' |
| ] |
| |
| for dir_name in required_dirs: |
| self.assertTrue( |
| os.path.exists(dir_name), |
| f"Diretório {dir_name} não encontrado" |
| ) |
|
|
|
|
| class TestImports(unittest.TestCase): |
| """Testa se todos os módulos podem ser importados.""" |
| |
| def test_import_config(self): |
| """Testa importação do módulo config.""" |
| try: |
| from utils.config import Config |
| self.assertTrue(True) |
| except ImportError as e: |
| self.fail(f"Erro ao importar config: {e}") |
| |
| def test_import_state(self): |
| """Testa importação do módulo state.""" |
| try: |
| from agents.state import PDFState |
| self.assertTrue(True) |
| except ImportError as e: |
| self.fail(f"Erro ao importar state: {e}") |
| |
| def test_import_main_graph(self): |
| """Testa importação do grafo principal.""" |
| try: |
| from main_graph import AgentPDFGraph |
| self.assertTrue(True) |
| except ImportError as e: |
| self.fail(f"Erro ao importar main_graph: {e}") |
|
|
|
|
| if __name__ == '__main__': |
| |
| setup_logger("AgentPDF.Tests", "WARNING") |
| |
| |
| unittest.main(verbosity=2) |
|
|