Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run_processor / get_processor: do not pass (empty) ocrd_tool #1009

Merged
merged 3 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions ocrd/ocrd/processor/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def _get_workspace(workspace=None, resolver=None, mets_url=None, working_dir=Non

def run_processor(
processorClass,
ocrd_tool=None,
mets_url=None,
resolver=None,
workspace=None,
Expand All @@ -59,7 +58,6 @@ def run_processor(

Instantiate a Python object for :py:attr:`processorClass`, passing:
- the workspace,
- :py:attr:`ocrd_tool`
- :py:attr:`page_id`
- :py:attr:`input_file_grp`
- :py:attr:`output_file_grp`
Expand Down Expand Up @@ -88,7 +86,6 @@ def run_processor(
processor_class=processorClass,
parameter=parameter,
workspace=workspace,
ocrd_tool=ocrd_tool,
page_id=page_id,
input_file_grp=input_file_grp,
output_file_grp=output_file_grp,
Expand Down Expand Up @@ -303,7 +300,6 @@ def get_processor(
processor_class,
parameter: dict,
workspace: Workspace = None,
ocrd_tool: dict = None,
page_id: str = None,
input_file_grp: List[str] = None,
output_file_grp: List[str] = None,
Expand All @@ -322,7 +318,6 @@ def get_processor(
return cached_processor
return processor_class(
workspace=workspace,
ocrd_tool=ocrd_tool,
page_id=page_id,
input_file_grp=input_file_grp,
output_file_grp=output_file_grp,
Expand Down
14 changes: 7 additions & 7 deletions tests/processor/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from tempfile import TemporaryDirectory
from os.path import join
from tests.base import CapturingTestCase as TestCase, assets, main # pylint: disable=import-error, no-name-in-module
from tests.data import DummyProcessor, DummyProcessorWithRequiredParameters, DummyProcessorWithOutput, IncompleteProcessor, DUMMY_TOOL
from tests.data import DummyProcessor, DummyProcessorWithRequiredParameters, DummyProcessorWithOutput, IncompleteProcessor

from ocrd_utils import MIMETYPE_PAGE, pushd_popd, initLogging, disableLogging
from ocrd.resolver import Resolver
Expand Down Expand Up @@ -79,12 +79,12 @@ def test_params(self):

def test_run_agent(self):
no_agents_before = len(self.workspace.mets.agents)
run_processor(DummyProcessor, ocrd_tool=DUMMY_TOOL, workspace=self.workspace)
run_processor(DummyProcessor, workspace=self.workspace)
self.assertEqual(len(self.workspace.mets.agents), no_agents_before + 1, 'one more agent')
# print(self.workspace.mets.agents[no_agents_before])

def test_run_input(self):
run_processor(DummyProcessor, ocrd_tool=DUMMY_TOOL, workspace=self.workspace, input_file_grp="OCR-D-IMG")
run_processor(DummyProcessor, workspace=self.workspace, input_file_grp="OCR-D-IMG")
assert len(self.workspace.mets.agents) > 0
assert len(self.workspace.mets.agents[-1].notes) > 0
assert ({'{https://ocr-d.de}option': 'input-file-grp'}, 'OCR-D-IMG') in self.workspace.mets.agents[-1].notes
Expand All @@ -94,7 +94,7 @@ def test_run_output0(self):
ws = self.resolver.workspace_from_nothing(directory=tempdir)
ws.add_file('GRP1', mimetype=MIMETYPE_PAGE, ID='foobar1', pageId='phys_0001')
ws.add_file('GRP1', mimetype=MIMETYPE_PAGE, ID='foobar2', pageId='phys_0002')
run_processor(DummyProcessorWithOutput, ocrd_tool=DUMMY_TOOL, workspace=ws,
run_processor(DummyProcessorWithOutput, workspace=ws,
input_file_grp="GRP1",
output_file_grp="OCR-D-OUT")
assert len(ws.mets.find_all_files(fileGrp="OCR-D-OUT")) == 2
Expand All @@ -108,19 +108,19 @@ def test_run_output_overwrite(self):
ws.add_file('OCR-D-OUT', mimetype=MIMETYPE_PAGE, ID='OCR-D-OUT_phys_0001', pageId='phys_0001')
ws.overwrite_mode = False
with pytest.raises(Exception) as exc:
run_processor(DummyProcessorWithOutput, ocrd_tool=DUMMY_TOOL, workspace=ws,
run_processor(DummyProcessorWithOutput, workspace=ws,
input_file_grp="GRP1",
output_file_grp="OCR-D-OUT")
assert str(exc.value) == "File with ID='OCR-D-OUT_phys_0001' already exists"
ws.overwrite_mode = True
run_processor(DummyProcessorWithOutput, ocrd_tool=DUMMY_TOOL, workspace=ws,
run_processor(DummyProcessorWithOutput, workspace=ws,
input_file_grp="GRP1",
output_file_grp="OCR-D-OUT")
assert len(ws.mets.find_all_files(fileGrp="OCR-D-OUT")) == 2

def test_run_cli(self):
with TemporaryDirectory() as tempdir:
run_processor(DummyProcessor, ocrd_tool=DUMMY_TOOL, workspace=self.workspace)
run_processor(DummyProcessor, workspace=self.workspace)
run_cli(
'echo',
mets_url=assets.url_of('SBB0000F29300010000/data/mets.xml'),
Expand Down
6 changes: 1 addition & 5 deletions tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from os.path import join, exists

from tests.base import CapturingTestCase as TestCase, assets, main, copy_of_directory # pylint: disable=import-error, no-name-in-module
from tests.data import DummyProcessor, DUMMY_TOOL
from tests.data import DummyProcessor

from ocrd import Processor, Resolver
from ocrd.decorators import (
Expand Down Expand Up @@ -131,15 +131,13 @@ def test_overwrite_fail(self):
with self.assertRaisesRegex(Exception, 'already in METS'):
ocrd_cli_wrap_processor(
DummyProcessor,
ocrd_tool=DUMMY_TOOL,
mets=ws.mets_target,
input_file_grp='IN-GRP',
output_file_grp='OUT-GRP',
)
# with overwrite, it shouldn't fail
ocrd_cli_wrap_processor(
DummyProcessor,
ocrd_tool=DUMMY_TOOL,
mets=ws.mets_target,
input_file_grp='IN-GRP',
output_file_grp='OUT-GRP',
Expand All @@ -155,7 +153,6 @@ def test_overwrite_fail(self):
# self.assertTrue(exists(join(ws.directory, 'ID4.tif')), 'files exist')
# ocrd_cli_wrap_processor(
# DummyProcessor,
# ocrd_tool=DUMMY_TOOL,
# mets=ws.mets_target,
# parameter={"foo": 42},
# input_file_grp='IN-GRP',
Expand All @@ -177,7 +174,6 @@ def test_overwrite_fail(self):
# self.assertTrue(exists(join(ws.directory, 'ID4.tif')), 'files exist')
# ocrd_cli_wrap_processor(
# DummyProcessor,
# ocrd_tool=DUMMY_TOOL,
# mets=ws.mets_target,
# parameter={"foo": 42},
# input_file_grp='IN-GRP',
Expand Down