forked from OCR-D/core
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_model_factory.py
More file actions
51 lines (40 loc) · 2.12 KB
/
test_model_factory.py
File metadata and controls
51 lines (40 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from tests.base import TestCase, main, assets, create_ocrd_file, create_ocrd_file_with_defaults
from ocrd_utils import MIMETYPE_PAGE
from ocrd_models import OcrdMets
from ocrd_modelfactory import (
exif_from_filename,
page_from_image,
page_from_file
)
SAMPLE_IMG = assets.path_to('kant_aufklaerung_1784/data/OCR-D-IMG/INPUT_0017.tif')
SAMPLE_PAGE = assets.path_to('kant_aufklaerung_1784/data/OCR-D-GT-PAGE/PAGE_0017_PAGE.xml')
class TestModelFactory(TestCase):
def test_exif_from_filename(self):
exif_from_filename(SAMPLE_IMG)
with self.assertRaisesRegex(Exception, "Must pass 'image_filename' to 'exif_from_filename'"):
exif_from_filename(None)
def test_page_from_file(self):
f = create_ocrd_file_with_defaults(mimetype='image/tiff', local_filename=SAMPLE_IMG, ID='file1')
self.assertEqual(f.mimetype, 'image/tiff')
p = page_from_file(f)
self.assertEqual(p.pcGtsId, f.ID)
self.assertEqual(p.get_Page().imageWidth, 1457)
def test_page_from_file_page(self):
f = create_ocrd_file_with_defaults(mimetype=MIMETYPE_PAGE, local_filename=SAMPLE_PAGE)
p = page_from_file(f)
self.assertEqual(p.get_Page().imageWidth, 1457)
def test_page_from_file_no_local_filename(self):
with self.assertRaisesRegex(ValueError, "input_file must have 'local_filename' property"):
page_from_file(create_ocrd_file_with_defaults(mimetype='image/tiff'))
def test_page_from_file_no_existe(self):
with self.assertRaisesRegex(FileNotFoundError, "File not found: 'no-existe'"):
mets = OcrdMets.empty_mets()
ocrd_file = mets.add_file('FOO', ID='foo', local_filename='no-existe', mimetype='foo/bar')
page_from_file(ocrd_file)
def test_page_from_file_unsupported_mimetype(self):
with self.assertRaisesRegex(ValueError, "Unsupported mimetype"):
page_from_file(create_ocrd_file_with_defaults(local_filename=__file__, mimetype='foo/bar'))
def test_imports_from_generateds(self):
from ocrd_models.ocrd_page import MetadataItemType
if __name__ == '__main__':
main(__file__)