test_doc_understanding.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import pytest
  2. from paddleocr import DocUnderstanding
  3. from ..testing_utils import (
  4. TEST_DATA_DIR,
  5. check_simple_inference_result,
  6. check_wrapper_simple_inference_param_forwarding,
  7. )
  8. @pytest.fixture(scope="module")
  9. def ocr_engine() -> DocUnderstanding:
  10. return DocUnderstanding()
  11. @pytest.mark.resource_intensive
  12. @pytest.mark.parametrize(
  13. "input",
  14. [
  15. {
  16. "image": str(TEST_DATA_DIR / "medal_table.png"),
  17. "query": "识别这份表格的内容",
  18. },
  19. {
  20. "image": str(TEST_DATA_DIR / "table.jpg"),
  21. "query": "识别这份表格的内容",
  22. },
  23. ],
  24. )
  25. def test_predict(ocr_engine: DocUnderstanding, input: dict) -> None:
  26. """
  27. Test PaddleOCR's doc understanding functionality.
  28. Args:
  29. ocr_engine: An instance of `DocUnderstanding`.
  30. input: Input dict to be processed.
  31. """
  32. result = ocr_engine.predict(input)
  33. check_simple_inference_result(result)
  34. res = result[0]
  35. assert res["result"] is not None
  36. assert isinstance(res["result"], str)