Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_parse_no_in(self):
task = ProcessorTask.parse('sample-processor')
with self.assertRaisesRegex(Exception, 'must have input file group'):
task.validate()
def test_validate_sequence(self):
resolver = Resolver()
with TemporaryDirectory() as tempdir:
workspace = resolver.workspace_from_url(assets.path_to('kant_aufklaerung_1784/data/mets.xml'), dst_dir=tempdir)
params_path = Path(tempdir, 'params.json')
params_path.write_text('{"param1": true}')
with self.assertRaisesRegex(Exception, "Input file group not contained in METS or produced by previous steps: FOO'"):
validate_tasks([ProcessorTask.parse(x) for x in [
'sample-processor-required-param -I OCR-D-IMG -O OUT1 -p %s' % params_path,
'sample-processor-required-param -I FOO -O OUT2 -p %s' % params_path
]], workspace)
with self.assertRaisesRegex(Exception, "Input fileGrp.@USE='IN'. not in METS!"):
validate_tasks([ProcessorTask.parse(x) for x in [
'sample-processor-required-param -I IN -O OUT1 -p %s' % params_path,
]], workspace)
def validate_process(tasks, workspace):
'''
Validate a sequence of tasks passable to 'ocrd process'
'''
if workspace:
_inform_of_result(validate_tasks([ProcessorTask.parse(t) for t in tasks], Workspace(Resolver(), directory=workspace)))
else:
for t in [ProcessorTask.parse(t) for t in tasks]:
_inform_of_result(t.validate())
def validate_process(tasks, workspace):
'''
Validate a sequence of tasks passable to 'ocrd process'
'''
if workspace:
_inform_of_result(validate_tasks([ProcessorTask.parse(t) for t in tasks], Workspace(Resolver(), directory=workspace)))
else:
for t in [ProcessorTask.parse(t) for t in tasks]:
_inform_of_result(t.validate())