diff --git a/.gitignore b/.gitignore index d931831..66d66bc 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ dmypy.json # User-specific stuff .idea +.*.swp # Build artifacts /build diff --git a/src/dinglehopper/line_dirs_test/basic/gt/a.gt.txt b/src/dinglehopper/tests/data/line_dirs/basic/gt/a.gt.txt similarity index 100% rename from src/dinglehopper/line_dirs_test/basic/gt/a.gt.txt rename to src/dinglehopper/tests/data/line_dirs/basic/gt/a.gt.txt diff --git a/src/dinglehopper/line_dirs_test/basic/gt/b.gt.txt b/src/dinglehopper/tests/data/line_dirs/basic/gt/b.gt.txt similarity index 100% rename from src/dinglehopper/line_dirs_test/basic/gt/b.gt.txt rename to src/dinglehopper/tests/data/line_dirs/basic/gt/b.gt.txt diff --git a/src/dinglehopper/line_dirs_test/basic/ocr/a.some-ocr.txt b/src/dinglehopper/tests/data/line_dirs/basic/ocr/a.some-ocr.txt similarity index 100% rename from src/dinglehopper/line_dirs_test/basic/ocr/a.some-ocr.txt rename to src/dinglehopper/tests/data/line_dirs/basic/ocr/a.some-ocr.txt diff --git a/src/dinglehopper/line_dirs_test/basic/ocr/b.some-ocr.txt b/src/dinglehopper/tests/data/line_dirs/basic/ocr/b.some-ocr.txt similarity index 100% rename from src/dinglehopper/line_dirs_test/basic/ocr/b.some-ocr.txt rename to src/dinglehopper/tests/data/line_dirs/basic/ocr/b.some-ocr.txt diff --git a/src/dinglehopper/line_dirs_test/merged/a/a.dummy.jpg b/src/dinglehopper/tests/data/line_dirs/merged/a/a.dummy.jpg similarity index 100% rename from src/dinglehopper/line_dirs_test/merged/a/a.dummy.jpg rename to src/dinglehopper/tests/data/line_dirs/merged/a/a.dummy.jpg diff --git a/src/dinglehopper/line_dirs_test/merged/a/a.gt.txt b/src/dinglehopper/tests/data/line_dirs/merged/a/a.gt.txt similarity index 100% rename from src/dinglehopper/line_dirs_test/merged/a/a.gt.txt rename to src/dinglehopper/tests/data/line_dirs/merged/a/a.gt.txt diff --git a/src/dinglehopper/line_dirs_test/merged/a/a.some-ocr.txt b/src/dinglehopper/tests/data/line_dirs/merged/a/a.some-ocr.txt similarity index 100% rename from src/dinglehopper/line_dirs_test/merged/a/a.some-ocr.txt rename to src/dinglehopper/tests/data/line_dirs/merged/a/a.some-ocr.txt diff --git a/src/dinglehopper/line_dirs_test/merged/b/b.dummy.jpg b/src/dinglehopper/tests/data/line_dirs/merged/b/b.dummy.jpg similarity index 100% rename from src/dinglehopper/line_dirs_test/merged/b/b.dummy.jpg rename to src/dinglehopper/tests/data/line_dirs/merged/b/b.dummy.jpg diff --git a/src/dinglehopper/line_dirs_test/merged/b/b.gt.txt b/src/dinglehopper/tests/data/line_dirs/merged/b/b.gt.txt similarity index 100% rename from src/dinglehopper/line_dirs_test/merged/b/b.gt.txt rename to src/dinglehopper/tests/data/line_dirs/merged/b/b.gt.txt diff --git a/src/dinglehopper/line_dirs_test/merged/b/b.some-ocr.txt b/src/dinglehopper/tests/data/line_dirs/merged/b/b.some-ocr.txt similarity index 100% rename from src/dinglehopper/line_dirs_test/merged/b/b.some-ocr.txt rename to src/dinglehopper/tests/data/line_dirs/merged/b/b.some-ocr.txt diff --git a/src/dinglehopper/line_dirs_test/subdirs/gt/a/a.gt.txt b/src/dinglehopper/tests/data/line_dirs/subdirs/gt/a/a.gt.txt similarity index 100% rename from src/dinglehopper/line_dirs_test/subdirs/gt/a/a.gt.txt rename to src/dinglehopper/tests/data/line_dirs/subdirs/gt/a/a.gt.txt diff --git a/src/dinglehopper/line_dirs_test/subdirs/gt/b/b.gt.txt b/src/dinglehopper/tests/data/line_dirs/subdirs/gt/b/b.gt.txt similarity index 100% rename from src/dinglehopper/line_dirs_test/subdirs/gt/b/b.gt.txt rename to src/dinglehopper/tests/data/line_dirs/subdirs/gt/b/b.gt.txt diff --git a/src/dinglehopper/line_dirs_test/subdirs/ocr/a/a.some-ocr.txt b/src/dinglehopper/tests/data/line_dirs/subdirs/ocr/a/a.some-ocr.txt similarity index 100% rename from src/dinglehopper/line_dirs_test/subdirs/ocr/a/a.some-ocr.txt rename to src/dinglehopper/tests/data/line_dirs/subdirs/ocr/a/a.some-ocr.txt diff --git a/src/dinglehopper/line_dirs_test/subdirs/ocr/b/b.some-ocr.txt b/src/dinglehopper/tests/data/line_dirs/subdirs/ocr/b/b.some-ocr.txt similarity index 100% rename from src/dinglehopper/line_dirs_test/subdirs/ocr/b/b.some-ocr.txt rename to src/dinglehopper/tests/data/line_dirs/subdirs/ocr/b/b.some-ocr.txt diff --git a/src/dinglehopper/line_dirs_test.py b/src/dinglehopper/tests/test_line_dirs.py similarity index 52% rename from src/dinglehopper/line_dirs_test.py rename to src/dinglehopper/tests/test_line_dirs.py index 9827f01..03966e1 100644 --- a/src/dinglehopper/line_dirs_test.py +++ b/src/dinglehopper/tests/test_line_dirs.py @@ -1,29 +1,30 @@ -import os.path -import itertools -from typing import Iterator, Tuple +import os +from ..cli_line_dirs import find_gt_and_ocr_files, find_gt_and_ocr_files_autodetect +data_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data") def test_basic(): """Test the dumb method: User gives directories and suffixes.""" pairs = list( find_gt_and_ocr_files( - "line_dirs_test/basic/gt", + os.path.join(data_dir, "line_dirs/basic/gt"), ".gt.txt", - "line_dirs_test/basic/ocr", + os.path.join(data_dir, "line_dirs/basic/ocr"), ".some-ocr.txt", ) ) assert len(pairs) == 2 + def test_basic_autodetect(): - """Test the autodetect method: User gives directories, suffixes are autodetected if possible""" + """Test autodetect: User gives directories, suffixes are autodetected if possible""" pairs = list( find_gt_and_ocr_files_autodetect( - "line_dirs_test/basic/gt", - "line_dirs_test/basic/ocr", + os.path.join(data_dir, "line_dirs/basic/gt"), + os.path.join(data_dir, "line_dirs/basic/ocr"), ) ) @@ -34,9 +35,9 @@ def test_subdirs(): """Test the dumb method: Should also work when subdirectories are involved.""" pairs = list( find_gt_and_ocr_files( - "line_dirs_test/subdirs/gt", + os.path.join(data_dir, "line_dirs/subdirs/gt"), ".gt.txt", - "line_dirs_test/subdirs/ocr", + os.path.join(data_dir, "line_dirs/subdirs/ocr"), ".some-ocr.txt", ) ) @@ -48,30 +49,23 @@ def test_subdirs_autodetect(): """Test the autodetect method: Should also work when subdirectories are involved.""" pairs = list( find_gt_and_ocr_files_autodetect( - "line_dirs_test/subdirs/gt", - "line_dirs_test/subdirs/ocr", + os.path.join(data_dir, "line_dirs/subdirs/gt"), + os.path.join(data_dir, "line_dirs/subdirs/ocr"), ) ) assert len(pairs) == 2 + def test_merged(): - """Test the dumb method: Should also work when GT and OCR texts are in the same directories.""" + """Test the dumb method: GT and OCR texts are in the same directories.""" pairs = list( find_gt_and_ocr_files( - "line_dirs_test/merged", + os.path.join(data_dir, "line_dirs/merged"), ".gt.txt", - "line_dirs_test/merged", + os.path.join(data_dir, "line_dirs/merged"), ".some-ocr.txt", ) ) assert len(pairs) == 2 - -if __name__ == "__main__": - test_basic() - test_subdirs() - test_merged() - - test_basic_autodetect() - test_subdirs_autodetect()