Esempio n. 1
0
 def test_launch_missing(self):
     setOverrideLogLevel('ERROR', True)
     with self.assertLogs('ocrd_browser.util.launcher.Launcher.launch',
                          level='ERROR') as log_watch:
         process = self.launcher.launch('missingtool', self.doc, self.file)
     self.assertIsNone(process)
     self.assertEqual(3, len(log_watch.records))
     self.assertEqual(
         'Tool "missingtool" not found in your config, to fix place the following section in your ocrd-browser.conf',
         log_watch.records[0].getMessage())
     setOverrideLogLevel('OFF', True)
Esempio n. 2
0
 def test_setOverrideLogLevel(self):
     initLogging()
     rootLogger = logging.getLogger('')
     somelogger = getLogger('foo.bar')
     somelogger.setLevel(getLevelName('ERROR'))
     setOverrideLogLevel('ERROR')
     self.assertEqual(rootLogger.getEffectiveLevel(), logging.ERROR)
     self.assertEqual(somelogger.getEffectiveLevel(), logging.ERROR)
     notherlogger = getLogger('bar.foo')
     self.assertEqual(notherlogger.getEffectiveLevel(), logging.ERROR)
     setOverrideLogLevel('INFO')
     somelogger = getLogger('foo.bar')
Esempio n. 3
0
def main(image, out, model, save_images, save_layout, save_deskewed, save_all,
         enable_plotting, allow_enhancement, curved_line, full_layout, tables,
         input_binary, allow_scaling, headers_off, log_level):
    if log_level:
        setOverrideLogLevel(log_level)
    initLogging()
    if not enable_plotting and (save_layout or save_deskewed or save_all
                                or save_images or allow_enhancement):
        print(
            "Error: You used one of -sl, -sd, -sa, -si or -ae but did not enable plotting with -ep"
        )
        sys.exit(1)
    elif enable_plotting and not (save_layout or save_deskewed or save_all
                                  or save_images or allow_enhancement):
        print(
            "Error: You used -ep to enable plotting but set none of -sl, -sd, -sa, -si or -ae"
        )
        sys.exit(1)
    eynollah = Eynollah(
        image_filename=image,
        dir_out=out,
        dir_models=model,
        dir_of_cropped_images=save_images,
        dir_of_layout=save_layout,
        dir_of_deskewed=save_deskewed,
        dir_of_all=save_all,
        enable_plotting=enable_plotting,
        allow_enhancement=allow_enhancement,
        curved_line=curved_line,
        full_layout=full_layout,
        tables=tables,
        input_binary=input_binary,
        allow_scaling=allow_scaling,
        headers_off=headers_off,
    )
    pcgts = eynollah.run()
    eynollah.writer.write_pagexml(pcgts)
Esempio n. 4
0
def _set_root_logger_version(ctx, param, value):  # pylint: disable=unused-argument
    setOverrideLogLevel(value)
    return value
Esempio n. 5
0
from unittest import TestCase  # noqa F401
import gi
from pathlib import Path
from ocrd_utils import initLogging, setOverrideLogLevel

gi.require_version('Gtk', '3.0')
gi.require_version('GdkPixbuf', '2.0')
try:
    gi.require_version('GtkSource', '4')
except ValueError:
    gi.require_version('GtkSource', '3.0')

gi.require_version('WebKit2', '4.0')

initLogging()
setOverrideLogLevel('OFF', True)

TEST_BASE_PATH = (Path(__file__).parent).absolute()
ASSETS_PATH = (TEST_BASE_PATH / 'assets').absolute()
if not ASSETS_PATH.exists():
    raise RuntimeError(
        'Assset path {} not found, please run: make tests/assets first')


# @see http://melp.nl/2011/02/phpunit-style-dataprovider-in-python-unit-test/
def data_provider(fn_data_provider):
    """Data provider decorator, allows another callable to provide the data for the test"""
    def test_decorator(fn):
        def repl(self, *args):
            for i in fn_data_provider():
                try:
Esempio n. 6
0
from os import walk
from os.path import join, exists, abspath, basename, dirname
from tempfile import TemporaryDirectory, mkdtemp
from shutil import copyfile
from pathlib import Path

from tests.base import TestCase, assets, main, copy_of_directory

from ocrd.resolver import Resolver
from ocrd.workspace import Workspace

from ocrd_utils import setOverrideLogLevel
setOverrideLogLevel('DEBUG')

TMP_FOLDER = '/tmp/test-core-workspace'
SRC_METS = assets.path_to('kant_aufklaerung_1784/data/mets.xml')

SAMPLE_FILE_FILEGRP = 'OCR-D-IMG'
SAMPLE_FILE_ID = 'INPUT_0017'
SAMPLE_FILE_URL = join(SAMPLE_FILE_FILEGRP, '%s.tif' % SAMPLE_FILE_ID)


class TestWorkspace(TestCase):
    def setUp(self):
        self.resolver = Resolver()

    def test_workspace_add_file(self):
        with TemporaryDirectory() as tempdir:
            ws1 = self.resolver.workspace_from_nothing(directory=tempdir)
            fpath = join(tempdir, 'ID1.tif')
            ws1.add_file('GRP',