From f6638265293f61c6ae29f571784615154eef3723 Mon Sep 17 00:00:00 2001 From: bosd Date: Fri, 24 Feb 2023 23:40:22 +0100 Subject: [PATCH] Test if ocrmypdf is (un)/available --- tests/test_lib.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/test_lib.py b/tests/test_lib.py index 7ebf3047..9c595582 100644 --- a/tests/test_lib.py +++ b/tests/test_lib.py @@ -17,9 +17,10 @@ except ImportError: from io import StringIO # noqa: F401 import unittest +from unittest import mock from invoice2data.main import extract_data -from invoice2data.input import pdftotext, tesseract, pdfminer_wrapper, pdfplumber +from invoice2data.input import pdftotext, tesseract, pdfminer_wrapper, pdfplumber, ocrmypdf from invoice2data.output import to_csv, to_json, to_xml from .common import get_sample_files @@ -112,6 +113,18 @@ def test_tesseract_for_return(self): else: self.assertTrue(True) + def test_have_ocrmypdf_unavailable(self): + with mock.patch.dict('sys.modules', {'ocrmypdf': None}): + have = ocrmypdf.have_ocrmypdf() + print("ocrmypdf should not be available have is %s" % have) + self.assertFalse(have, "ocrmypdf is NOT installed") + + def test_haveocrmypdf_available(self): + with mock.patch.dict('sys.modules', {'ocrmypdf': True}): + have = ocrmypdf.have_ocrmypdf() + print("ocrmypdf should be available have is %s" % have) + self.assertTrue(have, "ocrmypdf is installed") + if __name__ == '__main__': unittest.main()