/
tsps
/
case_loader
Обзор
Документация
Войти
/
tsps
/
case_loader
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
tests/test_pdf_parser.py
43 строки
1 KB
Василий Петров
[43] PdfParser
05 окт 2025, 23:13
05 окт 2025, 23:13
423c8e0
Код
Авторство
О чём код?
import pytest from pathlib import Path from app.services.pdf_parser import PdfParser class TestPdfParser: @pytest.fixture def parser(self): return PdfParser() @pytest.fixture def sample_pdf_path(self): return Path("storage/test_files/result_1.pdf") @pytest.fixture def sample_pdf_bytes(self, sample_pdf_path): with open(sample_pdf_path, 'rb') as f: return f.read() def test_parse_from_path_returns_text(self, parser, sample_pdf_path): result = parser.parse(sample_pdf_path) assert isinstance(result, str) assert len(result) > 0 def test_parse_from_bytes_returns_text(self, parser, sample_pdf_bytes): result = parser.parse(sample_pdf_bytes) assert isinstance(result, str) assert len(result) > 0 def test_parse_from_path_and_bytes_return_same(self, parser, sample_pdf_path, sample_pdf_bytes): result_from_path = parser.parse(sample_pdf_path) result_from_bytes = parser.parse(sample_pdf_bytes) assert result_from_path == result_from_bytes def test_parse_nonexistent_file_raises_error(self, parser): with pytest.raises(FileNotFoundError): parser.parse("nonexistent.pdf") def test_parse_invalid_bytes_raises_error(self, parser): with pytest.raises(ValueError): parser.parse(b"invalid pdf data")