import pytest from app.processing import process_text_input, process_file def test_process_text_input_success(pipeline): """ Test processing of valid text input. """ input_text = "This is a sample text for flashcard extraction." output_format = "JSON" expected_output = '{"flashcards": []}' result = process_text_input(input_text, output_format, pipeline) assert result == expected_output pipeline.generate_flashcards.assert_called_once() def test_process_text_input_empty(pipeline): """ Test processing of empty text input. """ input_text = " " output_format = "JSON" with pytest.raises(ValueError) as excinfo: process_text_input(input_text, output_format, pipeline) assert "No text provided." in str(excinfo.value) def test_process_file_unsupported_type(pipeline, tmp_path): """ Test processing of an unsupported file type. """ # Create a dummy unsupported file dummy_file = tmp_path / "dummy.unsupported" dummy_file.write_text("Unsupported content") with pytest.raises(ValueError) as excinfo: process_file(dummy_file, "JSON", pipeline) assert "Unsupported file type." in str(excinfo.value) def test_process_file_pdf(pipeline, tmp_path, mocker): """ Test processing of a PDF file. """ # Mock the process_pdf function mocker.patch('app.processing.process_pdf', return_value="Extracted PDF text.") # Create a dummy PDF file dummy_file = tmp_path / "test.pdf" dummy_file.write_text("PDF content") expected_output = '{"flashcards": []}' result = process_file(dummy_file, "JSON", pipeline) assert result == expected_output pipeline.generate_flashcards.assert_called_once() def test_process_file_txt(pipeline, tmp_path, mocker): """ Test processing of a TXT file. """ # Mock the read_text_file function mocker.patch('app.processing.read_text_file', return_value="Extracted TXT text.") # Create a dummy TXT file dummy_file = tmp_path / "test.txt" dummy_file.write_text("TXT content") expected_output = '{"flashcards": []}' result = process_file(dummy_file, "JSON", pipeline) assert result == expected_output pipeline.generate_flashcards.assert_called_once()