mirror of
				https://github.com/qurator-spk/dinglehopper.git
				synced 2025-10-31 17:34:15 +01:00 
			
		
		
		
	✔ Properly test line dir finding
This commit is contained in:
		
							parent
							
								
									0ccb61299a
								
							
						
					
					
						commit
						61c11531e4
					
				
					 16 changed files with 18 additions and 23 deletions
				
			
		
							
								
								
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							|  | @ -25,6 +25,7 @@ dmypy.json | ||||||
| 
 | 
 | ||||||
| # User-specific stuff | # User-specific stuff | ||||||
| .idea | .idea | ||||||
|  | .*.swp | ||||||
| 
 | 
 | ||||||
| # Build artifacts | # Build artifacts | ||||||
| /build | /build | ||||||
|  |  | ||||||
|  | @ -1,29 +1,30 @@ | ||||||
| import os.path | import os | ||||||
| import itertools |  | ||||||
| from typing import Iterator, Tuple |  | ||||||
| 
 | 
 | ||||||
|  | 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(): | def test_basic(): | ||||||
|     """Test the dumb method: User gives directories and suffixes.""" |     """Test the dumb method: User gives directories and suffixes.""" | ||||||
|     pairs = list( |     pairs = list( | ||||||
|         find_gt_and_ocr_files( |         find_gt_and_ocr_files( | ||||||
|             "line_dirs_test/basic/gt", |             os.path.join(data_dir, "line_dirs/basic/gt"), | ||||||
|             ".gt.txt", |             ".gt.txt", | ||||||
|             "line_dirs_test/basic/ocr", |             os.path.join(data_dir, "line_dirs/basic/ocr"), | ||||||
|             ".some-ocr.txt", |             ".some-ocr.txt", | ||||||
|         ) |         ) | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
|     assert len(pairs) == 2 |     assert len(pairs) == 2 | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def test_basic_autodetect(): | 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( |     pairs = list( | ||||||
|         find_gt_and_ocr_files_autodetect( |         find_gt_and_ocr_files_autodetect( | ||||||
|             "line_dirs_test/basic/gt", |             os.path.join(data_dir, "line_dirs/basic/gt"), | ||||||
|             "line_dirs_test/basic/ocr", |             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.""" |     """Test the dumb method: Should also work when subdirectories are involved.""" | ||||||
|     pairs = list( |     pairs = list( | ||||||
|         find_gt_and_ocr_files( |         find_gt_and_ocr_files( | ||||||
|             "line_dirs_test/subdirs/gt", |             os.path.join(data_dir, "line_dirs/subdirs/gt"), | ||||||
|             ".gt.txt", |             ".gt.txt", | ||||||
|             "line_dirs_test/subdirs/ocr", |             os.path.join(data_dir, "line_dirs/subdirs/ocr"), | ||||||
|             ".some-ocr.txt", |             ".some-ocr.txt", | ||||||
|         ) |         ) | ||||||
|     ) |     ) | ||||||
|  | @ -48,30 +49,23 @@ def test_subdirs_autodetect(): | ||||||
|     """Test the autodetect method: Should also work when subdirectories are involved.""" |     """Test the autodetect method: Should also work when subdirectories are involved.""" | ||||||
|     pairs = list( |     pairs = list( | ||||||
|         find_gt_and_ocr_files_autodetect( |         find_gt_and_ocr_files_autodetect( | ||||||
|             "line_dirs_test/subdirs/gt", |             os.path.join(data_dir, "line_dirs/subdirs/gt"), | ||||||
|             "line_dirs_test/subdirs/ocr", |             os.path.join(data_dir, "line_dirs/subdirs/ocr"), | ||||||
|         ) |         ) | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
|     assert len(pairs) == 2 |     assert len(pairs) == 2 | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def test_merged(): | 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( |     pairs = list( | ||||||
|         find_gt_and_ocr_files( |         find_gt_and_ocr_files( | ||||||
|             "line_dirs_test/merged", |             os.path.join(data_dir, "line_dirs/merged"), | ||||||
|             ".gt.txt", |             ".gt.txt", | ||||||
|             "line_dirs_test/merged", |             os.path.join(data_dir, "line_dirs/merged"), | ||||||
|             ".some-ocr.txt", |             ".some-ocr.txt", | ||||||
|         ) |         ) | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
|     assert len(pairs) == 2 |     assert len(pairs) == 2 | ||||||
| 
 |  | ||||||
| if __name__ == "__main__": |  | ||||||
|     test_basic() |  | ||||||
|     test_subdirs() |  | ||||||
|     test_merged() |  | ||||||
| 
 |  | ||||||
|     test_basic_autodetect() |  | ||||||
|     test_subdirs_autodetect() |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue