Skip to content

Commit

Permalink
add agent in run_processor after process() and before save_mets(), #147
Browse files Browse the repository at this point in the history
  • Loading branch information
kba committed Oct 19, 2018
1 parent 44011c4 commit 85f9d30
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
16 changes: 12 additions & 4 deletions ocrd/processor/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def run_processor(
output_file_grp=None,
parameter=None,
working_dir=None,
):
): # pylint: disable=too-many-locals
"""
Create a workspace for mets_url and run processor through it
Expand Down Expand Up @@ -59,10 +59,18 @@ def run_processor(
output_file_grp=output_file_grp,
parameter=parameter
)
log.debug("Processor instance %s", processor)
log.debug('%s', ocrd_tool)
# print(processor.version)
name = '%s v%s' % (ocrd_tool['executable'], processor.version)
otherrole = ocrd_tool['steps'][0]
log.debug("Processor instance %s (%s doing %s)", processor, name, otherrole)
processor.process()
# workspace.add_agent(
workspace.mets.add_agent(
name=name,
_type='OTHER',
othertype='SOFTWARE',
role='OTHER',
otherrole=otherrole
)
workspace.save_mets()

# TODO not used as of 0.8.2
Expand Down
18 changes: 14 additions & 4 deletions test/processor/test_processor.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from test.base import TestCase, assets, main # pylint: disable=import-error, no-name-in-module

from ocrd.resolver import Resolver
from ocrd.processor.base import Processor
from ocrd.processor.base import Processor, run_processor

DUMMY_TOOL = {'executable': 'ocrd-test', 'steps': ['recognition/post-correction']}

class DummyProcessor(Processor):

def __init__(self, *args, **kwargs):
kwargs['ocrd_tool'] = {
'executable': 'ocrd-test'
}
kwargs['ocrd_tool'] = DUMMY_TOOL
kwargs['version'] = '0.0.1'
super(DummyProcessor, self).__init__(*args, **kwargs)

def process(self):
# print('# nope')
pass

class TestResolver(TestCase):

def setUp(self):
Expand All @@ -29,5 +33,11 @@ def test_params(self):
proc = Processor(workspace=self.workspace)
self.assertEqual(proc.parameter, {})

def test_run_agent(self):
no_agents_before = len(self.workspace.mets.agents)
run_processor(DummyProcessor, ocrd_tool=DUMMY_TOOL, 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])

if __name__ == "__main__":
main()

0 comments on commit 85f9d30

Please sign in to comment.