diff --git a/tests/test_run.py b/tests/test_run.py index 741c544..9528642 100644 --- a/tests/test_run.py +++ b/tests/test_run.py @@ -12,7 +12,7 @@ testdir = Path(__file__).parent.resolve() EYNOLLAH_MODELS = environ.get('EYNOLLAH_MODELS', str(testdir.joinpath('..', 'models_eynollah').resolve())) SBBBIN_MODELS = environ.get('SBBBIN_MODELS', str(testdir.joinpath('..', 'default-2021-03-09').resolve())) -def test_run_eynollah_layout(tmp_path, subtests, pytestconfig, caplog): +def test_run_eynollah_layout_filename(tmp_path, subtests, pytestconfig, caplog): infile = testdir.joinpath('resources/kant_aufklaerung_1784_0020.tif') outfile = tmp_path / 'kant_aufklaerung_1784_0020.xml' args = [ @@ -57,7 +57,30 @@ def test_run_eynollah_layout(tmp_path, subtests, pytestconfig, caplog): lines = tree.xpath("//page:TextLine", namespaces=NS) assert len(lines) == 31, "result is inaccurate" # 29 paragraph lines, 1 page and 1 catch-word line -def test_run_eynollah_binarization(tmp_path, subtests, pytestconfig, caplog): +def test_run_eynollah_layout_directory(tmp_path, pytestconfig, caplog): + indir = testdir.joinpath('resources') + outdir = tmp_path + args = [ + '-m', EYNOLLAH_MODELS, + '-di', str(indir), + '-o', str(outdir), + ] + if pytestconfig.getoption('verbose') > 0: + args.extend(['-l', 'DEBUG']) + caplog.set_level(logging.INFO) + def only_eynollah(logrec): + return logrec.name == 'eynollah' + runner = CliRunner() + with caplog.filtering(only_eynollah): + result = runner.invoke(layout_cli, args) + print(result) + assert result.exit_code == 0 + logmsgs = [logrec.message for logrec in caplog.records] + assert len([logmsg for logmsg in logmsgs if logmsg.startswith('Job done in')]) == 2 + assert any(logmsg for logmsg in logmsgs if logmsg.startswith('All jobs done in')) + assert len(list(outdir.iterdir())) == 2 + +def test_run_eynollah_binarization_filename(tmp_path, subtests, pytestconfig, caplog): infile = testdir.joinpath('resources/kant_aufklaerung_1784_0020.tif') outfile = tmp_path.joinpath('kant_aufklaerung_1784_0020.png') args = [ @@ -72,7 +95,6 @@ def test_run_eynollah_binarization(tmp_path, subtests, pytestconfig, caplog): for options in [ [], # defaults ["--no-patches"], - # --dir_in --dir_out ]: with subtests.test(#msg="test CLI", options=options): @@ -89,3 +111,22 @@ def test_run_eynollah_binarization(tmp_path, subtests, pytestconfig, caplog): binarized_size = binarized_img.size assert original_size == binarized_size +def test_run_eynollah_binarization_directory(tmp_path, subtests, pytestconfig, caplog): + indir = testdir.joinpath('resources') + outdir = tmp_path + args = [ + '-m', SBBBIN_MODELS, + '-di', str(indir), + '-do', str(outdir), + ] + caplog.set_level(logging.INFO) + def only_eynollah(logrec): + return logrec.name == 'SbbBinarizer' + runner = CliRunner() + with caplog.filtering(only_eynollah): + result = runner.invoke(binarization_cli, args) + print(result) + assert result.exit_code == 0 + logmsgs = [logrec.message for logrec in caplog.records] + assert len([logmsg for logmsg in logmsgs if logmsg.startswith('Predicting')]) == 2 + assert len(list(outdir.iterdir())) == 2