import pytest

from qz.pdf_extractor import PDFExtractor


def test_pdf_extractor_initialization():
    extractor = PDFExtractor()
    assert isinstance(extractor, PDFExtractor)
    assert extractor.text_extractor is not None
    assert extractor.text_preprocessor is not None
    assert extractor.question_generator is not None
    assert extractor.fact_checker is not None


def test_generate_quiz(sample_pdf_path):
    extractor = PDFExtractor()
    quiz = extractor.generate_quiz(sample_pdf_path, num_questions=2)
    assert isinstance(quiz, list)
    if quiz:  # If questions were generated
        assert isinstance(quiz[0], dict)
        assert "text" in quiz[0]
        assert "options" in quiz[0]
        assert "correct_answer" in quiz[0]


def test_invalid_pdf_path():
    extractor = PDFExtractor()
    with pytest.raises(FileNotFoundError):
        extractor.generate_quiz("nonexistent.pdf")
