diff --git a/.gitignore b/.gitignore index 58549bc1..b1e5621a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ tmp/ log/ -*.pyc \ No newline at end of file +*.pyc +tests/output/ diff --git a/tests/resources/NOTE.md b/tests/resources/NOTE.md index aa48aad0..f4e70e72 100644 --- a/tests/resources/NOTE.md +++ b/tests/resources/NOTE.md @@ -1 +1,8 @@ -All test resources must come from public domain sources such as Wikimedia. +All test resources must come from free public domain sources for copyright reasons. + +Test files do not necessarily produce perfect (or even good) OCR results. + +File | Source +--------------------|--------- +graph.pdf | Wikimedia +c02-22.pdf | Project Gutenberg: https://www.gutenberg.org/files/76/76-h/images/c02-22.jpg \ No newline at end of file diff --git a/tests/resources/c02-22.pdf b/tests/resources/c02-22.pdf new file mode 100644 index 00000000..c9f77df4 Binary files /dev/null and b/tests/resources/c02-22.pdf differ diff --git a/tests/test_main.py b/tests/test_main.py index 8bc3305a..423a3d09 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -7,11 +7,19 @@ TESTS_ROOT = os.path.abspath(os.path.dirname(__file__)) PROJECT_ROOT = os.path.dirname(TESTS_ROOT) OCRMYPDF = os.path.join(PROJECT_ROOT, 'OCRmyPDF.sh') TEST_RESOURCES = os.path.join(PROJECT_ROOT, 'tests', 'resources') +TEST_OUTPUT = os.path.join(PROJECT_ROOT, 'tests', 'output') -def run_ocrmypdf(input_file, output_file, *args): +def setup_module(): + try: + os.mkdir(TEST_OUTPUT) + except FileExistsError: + pass + + +def run_ocrmypdf(input_file, *args): input_path = os.path.join(TEST_RESOURCES, input_file) - output_path = os.path.join(TEST_RESOURCES, output_file) + output_path = os.path.join(TEST_OUTPUT, input_file) sh_args = ['sh', './OCRmyPDF.sh'] + list(args) + [input_path, output_path] sh = Popen( @@ -21,10 +29,10 @@ def run_ocrmypdf(input_file, output_file, *args): return sh, out, err -def check_ocrmypdf(input_file, output_file, *args): - sh, _, err = run_ocrmypdf(input_file, output_file, *args) +def check_ocrmypdf(input_file, *args): + sh, _, err = run_ocrmypdf(input_file, *args) assert sh.returncode == 0, err def test_quick(): - check_ocrmypdf('graph.pdf', 'graph_out.pdf') + check_ocrmypdf('c02-22.pdf')