def test_additional_props(self):
     self.ocrd_tool['not-allowed'] = 'YUP'
     report = OcrdToolValidator.validate(self.ocrd_tool)
     self.assertFalse(report.is_valid)
     self.assertIn(
         "Additional properties are not allowed ('not-allowed' was unexpected)",
         report.errors[0])
 def test_additional_props_in_tool(self):
     # XXX 'parameter' is the wrong key, should be 'parameters'
     self.ocrd_tool['tools']['ocrd-xyz']['parameter'] = {}
     report = OcrdToolValidator.validate(self.ocrd_tool)
     self.assertFalse(report.is_valid)
     self.assertIn(
         "Additional properties are not allowed ('parameter' was unexpected)",
         report.errors[0])
Exemple #3
0
def validate_ocrd_tool(ocrd_tool):
    '''
    Validate OCRD_TOOL as an ocrd-tool.json file.
    '''
    if not ocrd_tool:
        ocrd_tool = 'ocrd-tool.json'
    with codecs.open(ocrd_tool, encoding='utf-8') as f:
        ocrd_tool = loads(f.read())
    _inform_of_result(OcrdToolValidator.validate(ocrd_tool))
 def test_file_param_ok(self):
     ocrd_tool = json.loads(skeleton)
     ocrd_tool['tools']['ocrd-xyz']['parameters'] = {
         "file-param": {
             "description": "...",
             "type": "string",
             "content-type": 'application/rdf+xml'
         }
     }
     report = OcrdToolValidator.validate(ocrd_tool)
     self.assertEqual(report.is_valid, True)
Exemple #5
0
 def test_file_param_bad_content_types(self):
     bad_and_why = [
             [2, 'Number not string'],
             ['foo', 'No subtype'],
             ['foo/bar~300', 'Invalid char in subtype'],
             ['foo/bar 300', 'Invalid char in subtype'],
     ]
     for case in bad_and_why:
         ocrd_tool = json.loads(skeleton)
         ocrd_tool['tools']['ocrd-xyz']['parameters'] = {"file-param": {"description": "...", "type": "string", "content-type": case[0]}}
         report = OcrdToolValidator.validate(ocrd_tool)
         print('# %s: %s' % (case[0], case[1]))
         self.assertEqual(report.is_valid, False, case[1])
Exemple #6
0
def ocrd_tool_validate(ctx):
    report = OcrdToolValidator.validate(ctx.json)
    print(report.to_xml())
    if not report.is_valid:
        return 128
Exemple #7
0
 def test_something(self):
     report = OcrdToolValidator.validate(json.loads(skeleton))
     #  print(report.to_xml())
     self.assertEqual(report.is_valid, True)
 def test_smoke(self):
     report = OcrdToolValidator.validate(self.ocrd_tool)
     self.assertEqual(report.is_valid, True)