def test_binding_schemas_id_is_unique(self): '''Test that all schema files under ./schemas/ validate against the DT metaschema''' ids = [] for filename in glob.iglob('schemas/**/*.yaml', recursive=True): with self.subTest(schema=filename): schema = dtschema.load_schema(filename) self.assertEqual(ids.count(schema['$id']), 0) ids.append(schema['$id'])
def test_binding_schemas_valid_draft7(self): '''Test that all schema files under ./schemas/ validate against the Draft7 metaschema The DT Metaschema is supposed to force all schemas to be valid against Draft7. This test makes absolutely sure that they are. ''' for filename in glob.iglob('schemas/**/*.yaml', recursive=True): with self.subTest(schema=filename): schema = dtschema.load_schema(filename) jsonschema.Draft7Validator.check_schema(schema)
def load_binding_schema(self, filename): try: schema = dtschema.load_schema(filename) except yaml.YAMLError as exc: print(filename + ": ignoring, error parsing file") return # Check that the validation schema is valid try: dtschema.DTValidator.check_schema(schema) except jsonschema.SchemaError as exc: print(filename + ": ignoring, error in schema '%s'" % exc.path[-1]) #print(exc.message) return # $validator and $select_validator are special properties that cache the # validator objects so the object doesn't need to be recreated on every node. schema["$validator"] = dtschema.DTValidator(schema) schema["$select_validator"] = jsonschema.Draft6Validator( get_select_schema(schema)) self.schemas.append(schema) schema["$filename"] = filename print(filename + ": loaded")
def test_binding_schemas_valid(self): '''Test that all schema files under ./schemas/ validate against the DT metaschema''' for filename in glob.iglob('schemas/**/*.yaml', recursive=True): with self.subTest(schema=filename): schema = dtschema.load_schema(filename) dtschema.DTValidator.check_schema(schema)
def test_all_metaschema_valid(self): '''The metaschema must all be a valid Draft7 schema''' for filename in glob.iglob('meta-schemas/**/*.yaml', recursive=True): with self.subTest(schema=filename): schema = dtschema.load_schema(filename) jsonschema.Draft7Validator.check_schema(schema)
def setUp(self): self.schema = dtschema.load_schema('test/schemas/good-example.yaml') self.bad_schema = dtschema.load_schema('test/schemas/bad-example.yaml')