File size: 1,018 Bytes
c1b16e4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import unittest
from app import normalizar_texto, extrair_texto
import os
class TestUnit(unittest.TestCase):
def test_normalizar_texto(self):
self.assertEqual(normalizar_texto("Olá Mundo!"), "ola mundo")
self.assertEqual(normalizar_texto("Ação e Reação"), "acao e reacao")
self.assertEqual(normalizar_texto(""), "")
self.assertEqual(normalizar_texto(None), "")
def test_extrair_texto_txt(self):
test_file = "test.txt"
with open(test_file, "w", encoding="utf-8") as f:
f.write("Conteúdo de teste")
try:
texto = extrair_texto(test_file)
self.assertEqual(texto, "Conteúdo de teste")
finally:
if os.path.exists(test_file):
os.remove(test_file)
def test_extrair_texto_invalido(self):
resultado = extrair_texto("arquivo_inexistente.pdf")
self.assertTrue(resultado.startswith("Erro ao extrair texto"))
if __name__ == "__main__":
unittest.main()
|