mirror of
https://github.com/qurator-spk/eynollah.git
synced 2025-11-10 06:34:11 +01:00
make --model-basedir and --model-overrides top-level CLI options
This commit is contained in:
parent
b6f82c72b9
commit
a913bdf7dc
18 changed files with 132 additions and 170 deletions
|
|
@ -1,15 +1,17 @@
|
|||
from typing import List
|
||||
from click import Command
|
||||
import pytest
|
||||
import logging
|
||||
|
||||
from click.testing import CliRunner, Result
|
||||
from eynollah.cli import main as eynollah_cli
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def run_eynollah_ok_and_check_logs(
|
||||
pytestconfig,
|
||||
caplog,
|
||||
model_dir,
|
||||
eynollah_subcommands,
|
||||
eynollah_log_filter,
|
||||
):
|
||||
"""
|
||||
|
|
@ -18,14 +20,23 @@ def run_eynollah_ok_and_check_logs(
|
|||
every fragment in `expected_logs`
|
||||
"""
|
||||
|
||||
def _run_click_ok_logs(cli: Command, args: List[str], expected_logs: List[str]) -> Result:
|
||||
args = ['-m', model_dir] + args
|
||||
def _run_click_ok_logs(
|
||||
subcommand: 'str',
|
||||
args: List[str],
|
||||
expected_logs: List[str],
|
||||
) -> Result:
|
||||
assert subcommand in eynollah_subcommands, f'subcommand {subcommand} must be one of {eynollah_subcommands}'
|
||||
args = [
|
||||
'-m', model_dir,
|
||||
subcommand,
|
||||
*args
|
||||
]
|
||||
if pytestconfig.getoption('verbose') > 0:
|
||||
args.extend(['-l', 'DEBUG'])
|
||||
caplog.set_level(logging.INFO)
|
||||
runner = CliRunner()
|
||||
with caplog.filtering(eynollah_log_filter):
|
||||
result = runner.invoke(cli, args, catch_exceptions=False)
|
||||
result = runner.invoke(eynollah_cli, args, catch_exceptions=False)
|
||||
assert result.exit_code == 0, result.stdout
|
||||
if expected_logs:
|
||||
logmsgs = [logrec.message for logrec in caplog.records]
|
||||
|
|
|
|||
|
|
@ -1,10 +1,5 @@
|
|||
import pytest
|
||||
from PIL import Image
|
||||
from eynollah.cli import (
|
||||
binarization as binarization_cli,
|
||||
)
|
||||
from ocrd_modelfactory import page_from_file
|
||||
from ocrd_models.constants import NAMESPACES as NS
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"options",
|
||||
|
|
@ -21,7 +16,7 @@ def test_run_eynollah_binarization_filename(
|
|||
infile = tests_dir.joinpath('resources/kant_aufklaerung_1784_0020.tif')
|
||||
outfile = tmp_path.joinpath('kant_aufklaerung_1784_0020.png')
|
||||
run_eynollah_ok_and_check_logs(
|
||||
binarization_cli,
|
||||
'binarization',
|
||||
[
|
||||
'-i', str(infile),
|
||||
'-o', str(outfile),
|
||||
|
|
@ -45,7 +40,7 @@ def test_run_eynollah_binarization_directory(
|
|||
):
|
||||
outdir = tmp_path
|
||||
run_eynollah_ok_and_check_logs(
|
||||
binarization_cli,
|
||||
'binarization',
|
||||
[
|
||||
'-di', str(resources_dir),
|
||||
'-o', str(outdir),
|
||||
|
|
|
|||
|
|
@ -1,10 +1,5 @@
|
|||
import pytest
|
||||
from PIL import Image
|
||||
from eynollah.cli import (
|
||||
enhancement as enhancement_cli,
|
||||
)
|
||||
from ocrd_modelfactory import page_from_file
|
||||
from ocrd_models.constants import NAMESPACES as NS
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"options",
|
||||
|
|
@ -21,7 +16,7 @@ def test_run_eynollah_enhancement_filename(
|
|||
infile = resources_dir / 'kant_aufklaerung_1784_0020.tif'
|
||||
outfile = tmp_path.joinpath('kant_aufklaerung_1784_0020.png')
|
||||
run_eynollah_ok_and_check_logs(
|
||||
enhancement_cli,
|
||||
'enhancement',
|
||||
[
|
||||
'-i', str(infile),
|
||||
'-o', str(outfile.parent),
|
||||
|
|
@ -44,7 +39,7 @@ def test_run_eynollah_enhancement_directory(
|
|||
):
|
||||
outdir = tmp_path
|
||||
run_eynollah_ok_and_check_logs(
|
||||
enhancement_cli,
|
||||
'enhancement',
|
||||
[
|
||||
'-di', str(resources_dir),
|
||||
'-o', str(outdir),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
import pytest
|
||||
from eynollah.cli import (
|
||||
layout as layout_cli,
|
||||
)
|
||||
from ocrd_modelfactory import page_from_file
|
||||
from ocrd_models.constants import NAMESPACES as NS
|
||||
|
||||
|
|
@ -30,11 +27,10 @@ def test_run_eynollah_layout_filename(
|
|||
resources_dir,
|
||||
options,
|
||||
):
|
||||
outdir = tmp_path
|
||||
infile = resources_dir / 'kant_aufklaerung_1784_0020.tif'
|
||||
outfile = tmp_path / 'kant_aufklaerung_1784_0020.xml'
|
||||
run_eynollah_ok_and_check_logs(
|
||||
layout_cli,
|
||||
'layout',
|
||||
[
|
||||
'-i', str(infile),
|
||||
'-o', str(outfile.parent),
|
||||
|
|
@ -68,7 +64,7 @@ def test_run_eynollah_layout_filename2(
|
|||
infile = resources_dir / 'euler_rechenkunst01_1738_0025.tif'
|
||||
outfile = tmp_path / 'euler_rechenkunst01_1738_0025.xml'
|
||||
run_eynollah_ok_and_check_logs(
|
||||
layout_cli,
|
||||
'layout',
|
||||
[
|
||||
'-i', str(infile),
|
||||
'-o', str(outfile.parent),
|
||||
|
|
@ -96,7 +92,7 @@ def test_run_eynollah_layout_directory(
|
|||
):
|
||||
outdir = tmp_path
|
||||
run_eynollah_ok_and_check_logs(
|
||||
layout_cli,
|
||||
'layout',
|
||||
[
|
||||
'-di', str(resources_dir),
|
||||
'-o', str(outdir),
|
||||
|
|
|
|||
|
|
@ -1,11 +1,6 @@
|
|||
from ocrd_modelfactory import page_from_file
|
||||
from ocrd_models.constants import NAMESPACES as NS
|
||||
|
||||
from eynollah.cli import (
|
||||
machine_based_reading_order as mbreorder_cli,
|
||||
)
|
||||
|
||||
|
||||
def test_run_eynollah_mbreorder_filename(
|
||||
tmp_path,
|
||||
resources_dir,
|
||||
|
|
@ -14,7 +9,7 @@ def test_run_eynollah_mbreorder_filename(
|
|||
infile = resources_dir / 'kant_aufklaerung_1784_0020.xml'
|
||||
outfile = tmp_path.joinpath('kant_aufklaerung_1784_0020.xml')
|
||||
run_eynollah_ok_and_check_logs(
|
||||
mbreorder_cli,
|
||||
'machine-based-reading-order',
|
||||
[
|
||||
'-i', str(infile),
|
||||
'-o', str(outfile.parent),
|
||||
|
|
@ -37,10 +32,9 @@ def test_run_eynollah_mbreorder_directory(
|
|||
resources_dir,
|
||||
run_eynollah_ok_and_check_logs,
|
||||
):
|
||||
outfile = tmp_path.joinpath('kant_aufklaerung_1784_0020.xml')
|
||||
outdir = tmp_path
|
||||
run_eynollah_ok_and_check_logs(
|
||||
mbreorder_cli,
|
||||
'machine-based-reading-order',
|
||||
[
|
||||
'-di', str(resources_dir),
|
||||
'-o', str(outdir),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
import pytest
|
||||
from eynollah.cli import (
|
||||
ocr as ocr_cli,
|
||||
)
|
||||
from ocrd_modelfactory import page_from_file
|
||||
from ocrd_models.constants import NAMESPACES as NS
|
||||
|
||||
|
|
@ -26,7 +23,7 @@ def test_run_eynollah_ocr_filename(
|
|||
if "-doit" in options:
|
||||
options.insert(options.index("-doit") + 1, str(outrenderfile.parent))
|
||||
run_eynollah_ok_and_check_logs(
|
||||
ocr_cli,
|
||||
'ocr',
|
||||
[
|
||||
'-i', str(infile),
|
||||
'-dx', str(infile.parent),
|
||||
|
|
@ -53,7 +50,7 @@ def test_run_eynollah_ocr_directory(
|
|||
):
|
||||
outdir = tmp_path
|
||||
run_eynollah_ok_and_check_logs(
|
||||
ocr_cli,
|
||||
'ocr',
|
||||
[
|
||||
'-di', str(resources_dir),
|
||||
'-dx', str(resources_dir),
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
import pytest
|
||||
from PIL import Image
|
||||
from eynollah.cli import (
|
||||
layout as layout_cli,
|
||||
binarization as binarization_cli,
|
||||
enhancement as enhancement_cli,
|
||||
)
|
||||
from ocrd_modelfactory import page_from_file
|
||||
from ocrd_models.constants import NAMESPACES as NS
|
||||
|
||||
|
|
@ -23,3 +23,15 @@ def image_resources(resources_dir):
|
|||
@pytest.fixture()
|
||||
def eynollah_log_filter():
|
||||
return lambda logrec: logrec.name.startswith('eynollah')
|
||||
|
||||
@pytest.fixture
|
||||
def eynollah_subcommands():
|
||||
return [
|
||||
'binarization',
|
||||
'layout',
|
||||
'ocr',
|
||||
'enhancement',
|
||||
'machine-based-reading-order'
|
||||
'models'
|
||||
]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue