Files
contracts-flask/tests/test_parse.py
T

29 lines
961 B
Python

"""Unit-тесты services/parse.py."""
from services.parse import parse_file, _parse_text
class TestParseText:
def test_plain(self):
r = parse_file("test.txt", "строка1\nстрока2\nстрока3".encode())
assert r["status"] == "parsed"
assert r["element_count"] == 3
def test_text_fn(self):
r = _parse_text(b"a\nb\nc")
assert r["status"] == "parsed"
assert r["element_count"] == 3
assert r["elements"][0]["text"] == "a"
def test_no_extension_falls_back_to_text(self):
r = parse_file("noext", b"line1\nline2")
assert r["status"] == "parsed"
assert r["element_count"] == 2
def test_docx_invalid_returns_error(self):
r = parse_file("test.docx", b"not a real docx")
assert r["status"] == "error"
def test_pdf_invalid_returns_error(self):
r = parse_file("test.pdf", b"not a real pdf")
assert r["status"] == "error"