CoolFace
Apppublic

Akshanshsensei/PDF-Constrained-Conversational-Agent

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes
test_null_guard.py22 linesDownload Raw Back to tests
1import unittest2from unittest.mock import patch, MagicMock3from app import chat_inference4 5class TestNullGuard(unittest.TestCase):6    @patch('app.SessionMemory')7    def test_null_metadata_aborts(self, mock_session_memory_cls):8        mock_memory = MagicMock()9        mock_memory.get_metadata.return_value = None10        mock_session_memory_cls.return_value = mock_memory11 12        generator = chat_inference("what is the page count?", [], "test_session")13        first_ui_update = next(generator) # The chat_history.append update (user, empty assistant)14        response = next(generator) # The actual null guard yield15        16        self.assertEqual(len(response), 3) # user, empty assistant, system warning17        self.assertEqual(response[-1]["role"], "assistant")18        self.assertIn("Document metadata not found", response[-1]["content"])19 20if __name__ == '__main__':21    unittest.main()22