Merge remote-tracking branch 'origin/refactor' into refactoring-2024-08

This commit is contained in:
kba 2024-08-24 18:51:44 +02:00
commit 8ec9fc6da2
44 changed files with 2377 additions and 479 deletions

View file

@ -10,12 +10,14 @@ from unittest import TestCase as VanillaTestCase, skip, main as unittests_main
import pytest
from ocrd_utils import disableLogging, initLogging
def main(fn=None):
if fn:
sys.exit(pytest.main([fn]))
else:
unittests_main()
class TestCase(VanillaTestCase):
@classmethod
@ -26,6 +28,7 @@ class TestCase(VanillaTestCase):
disableLogging()
initLogging()
class CapturingTestCase(TestCase):
"""
A TestCase that needs to capture stderr/stdout and invoke click CLI.
@ -42,7 +45,7 @@ class CapturingTestCase(TestCase):
"""
self.capture_out_err() # XXX snapshot just before executing the CLI
code = 0
sys.argv[1:] = args # XXX necessary because sys.argv reflects pytest args not cli args
sys.argv[1:] = args # XXX necessary because sys.argv reflects pytest args not cli args
try:
cli.main(args=args)
except SystemExit as e:

View file

@ -1,5 +1,6 @@
from tests.base import main
from qurator.eynollah.utils.counter import EynollahIdCounter
from eynollah.eynollah.utils.counter import EynollahIdCounter
def test_counter_string():
c = EynollahIdCounter()
@ -11,6 +12,7 @@ def test_counter_string():
assert c.region_id(999) == 'region_0999'
assert c.line_id(999, 888) == 'region_0999_line_0888'
def test_counter_init():
c = EynollahIdCounter(region_idx=2)
assert c.get('region') == 2
@ -19,6 +21,7 @@ def test_counter_init():
c.reset()
assert c.get('region') == 2
def test_counter_methods():
c = EynollahIdCounter()
assert c.get('region') == 0
@ -29,5 +32,6 @@ def test_counter_methods():
c.inc('region', -9)
assert c.get('region') == 1
if __name__ == '__main__':
main(__file__)

View file

@ -1,11 +1,13 @@
import cv2
from pathlib import Path
from qurator.eynollah.utils.pil_cv2 import check_dpi
from eynollah.eynollah.utils.pil_cv2 import check_dpi
from tests.base import main
def test_dpi():
fpath = str(Path(__file__).parent.joinpath('resources', 'kant_aufklaerung_1784_0020.tif'))
assert 230 == check_dpi(cv2.imread(fpath))
if __name__ == '__main__':
main(__file__)

View file

@ -2,13 +2,14 @@ from os import environ
from pathlib import Path
from ocrd_utils import pushd_popd
from tests.base import CapturingTestCase as TestCase, main
from qurator.eynollah.cli import main as eynollah_cli
from eynollah.eynollah.cli import main as eynollah_cli
testdir = Path(__file__).parent.resolve()
# EYNOLLAH_MODELS = environ.get('EYNOLLAH_MODELS', str(testdir.joinpath('..', 'models_eynollah').resolve()))
EYNOLLAH_MODELS = environ['EYNOLLAH_MODELS']
class TestEynollahRun(TestCase):
def test_full_run(self):
@ -21,5 +22,6 @@ class TestEynollahRun(TestCase):
print(code, out, err)
assert not code
if __name__ == '__main__':
main(__file__)

View file

@ -1,7 +1,7 @@
def test_utils_import():
import qurator.eynollah.utils
import qurator.eynollah.utils.contour
import qurator.eynollah.utils.drop_capitals
import qurator.eynollah.utils.drop_capitals
import qurator.eynollah.utils.is_nan
import qurator.eynollah.utils.rotate
import eynollah.eynollah.utils
import eynollah.eynollah.utils.contour
import eynollah.eynollah.utils.drop_capitals
import eynollah.eynollah.utils.drop_capitals
import eynollah.eynollah.utils.is_nan
import eynollah.eynollah.utils.rotate

View file

@ -1,14 +1,16 @@
from pytest import main
from qurator.eynollah.utils.xml import create_page_xml
from eynollah.eynollah.utils.xml import create_page_xml
from ocrd_models.ocrd_page import to_xml
PAGE_2019 = 'http://schema.primaresearch.org/PAGE/gts/pagecontent/2019-07-15'
def test_create_xml():
pcgts = create_page_xml('/path/to/img.tif', 100, 100)
xmlstr = to_xml(pcgts)
assert 'xmlns:pc="%s"' % PAGE_2019 in xmlstr
assert 'Metadata' in xmlstr
if __name__ == '__main__':
main([__file__])