def validate_schema(schema): """Validate schema against schema.org standard """ data_path = 'validation_schemas/model.schema.json' json_schema_path = LOADER.filename(data_path) json_schema = load_json(json_schema_path) return validate(schema, json_schema)
def validate_property_schema(schema): """Validate schema against SchemaORG property definition standard """ data_path = 'validation_schemas/property.schema.json' json_schema_path = LOADER.filename(data_path) json_schema = load_json(json_schema_path) return validate(schema, json_schema)
def validate_class_schema(schema): """Validate schema against SchemaORG class definition standard """ data_path = 'validation_schemas/class.schema.json' json_schema_path = LOADER.filename(data_path) json_schema = load_json(json_schema_path) return validate(schema, json_schema)
def validate_class_schema(self, schema): """Validate schema against SchemaORG class definition standard """ json_schema_path = os.path.join('validation_schemas', 'class_json_schema.json') json_schema = load_json(json_schema_path) return validate(schema, json_schema)
def test_json_load(self, tmpdir): json_file = tmpdir.join("example.json") json_file.write_text(json.dumps([ {'k1': 'v1'}, {'k2': 'v2'} ]), encoding="utf-8") with open(json_file, encoding='utf-8') as f: expected = json.load(f) local_result = io_utils.load_json(str(json_file)) assert local_result == expected
def test_json_load_online(self, mocker): mock_urlopen = mocker.patch( "urllib.request.urlopen", return_value=FakeResponse(data=json.dumps([{ "k1": "v1" }, { "k2": "v2" }]).encode("utf-8")), ) url_result = io_utils.load_json("http://example.com") assert url_result == [{"k1": "v1"}, {"k2": "v2"}] assert mock_urlopen.call_count == 1
def test_json_load_online(self, mocker): mock_urlopen = mocker.patch("urllib.request.urlopen", return_value = FakeResponse(data=json.dumps([ {'k1': 'v1'}, {'k2': 'v2'}] ).encode('utf-8')) ) url_result = io_utils.load_json("http://example.com") assert url_result == [ {'k1': 'v1'}, {'k2': 'v2'} ] assert mock_urlopen.call_count == 1
def test_json_load(self, tmpdir): json_file = tmpdir.join("example.json") json_file.write_text(json.dumps([{ "k1": "v1" }, { "k2": "v2" }]), encoding="utf-8") with open(json_file, encoding="utf-8") as f: expected = json.load(f) local_result = io_utils.load_json(str(json_file)) assert local_result == expected
def validate_property_schema(self, schema): """Validate schema against SchemaORG property definition standard""" json_schema_path = os.path.join("validation_schemas", "property_json_schema.json") json_schema = load_json(json_schema_path) return validate(schema, json_schema)
def load_schema(self, schema): """Load schema and convert it to networkx graph """ self.schema = load_json(schema) self.schema_nx = load_schema_into_networkx(self.schema)