Files
courrier/tests/test_piece_ia.py
T

25 lines
830 B
Python

import io
import zipfile
import pytest
from app import piece_ia as p
def _docx(txt):
b = io.BytesIO()
with zipfile.ZipFile(b, "w") as z:
z.writestr("word/document.xml", '<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p><w:r><w:t>' + txt + "</w:t></w:r></w:p></w:body></w:document>")
return b.getvalue()
def test_texte_et_docx():
long = "Bon de commande numero 4500123 pour la livraison de dix ordinateurs avant le 30/11/2026."
assert "4500123" in p.extraire_texte("a.txt", long.encode())
assert "4500123" in p.extraire_texte("a.docx", _docx(long))
def test_type_inconnu_et_vide():
with pytest.raises(p.SansTexte):
p.extraire_texte("a.exe", b"x" * 100)
with pytest.raises(p.SansTexte):
p.extraire_texte("a.txt", b"court")