def test_loading_a_json_file_with_tabs_falls_back_to_json_loader(): """YAML is _mostly_ compatible with JSON. However, JSON allows tabs between tokens, whilst YAML does not. """ value = RefDict("tests/schemas/with-tabs.json") assert dict(value) == {"some": {"json": ["with", "tabs"]}}
def read_schema_files(schema_root, item): s_path = path.join(schema_path, schema_root + ".yaml#/" + item) # print(s_path) root_def = RefDict(s_path) exclude_keys = ["format", "examples"] return materialize(root_def, exclude_keys=exclude_keys)
def read_schema_files(schema_name, item, byc): s_f_p = get_schema_file_path(schema_name, byc) # print(schema_name, s_f_p) if not s_f_p is False: s_path = path.join(s_f_p, schema_name + ".yaml#/" + item) root_def = RefDict(s_path) exclude_keys = ["format", "examples"] s = materialize(root_def, exclude_keys=exclude_keys) # print(s) return s return False
def read_bycon_configs_by_name(name, byc): """podmd Reading the config from the same wrapper dir: module | |- lib - read_specs.py |- config - __name__.yaml podmd""" o = {} ofp = path.join( byc["pkg_path"], "config", name+".yaml" ) with open( ofp ) as od: o = yaml.load( od , Loader=yaml.FullLoader) byc.update({ name: o }) # TODO Move ... if name == "beacon": byc.update({ "beacon-schema": RefDict(ofp) }) return byc
def test_json_pointer_on_dict(): ref_dict = RefDict("base/reflist.json#/") pointer = JsonPointer("/definitions/foo/not/0") assert pointer.resolve(ref_dict) == {"type": "object"}
def test_absolute_references_are_detected(): url = "http://json.schemastore.org/azure-iot-edge-deployment-template-2.0" ref_dict = RefDict(url) assert ref_dict["definitions"]["moduleType"] == RefDict( "http://json.schemastore.org/azure-iot-edge-deployment-2.0#" "/definitions/moduleType")
def test_can_materialize_json_schema_ref(): schema = materialize(RefDict("https://json-schema.org/draft-07/schema#/")) assert isinstance(schema, dict)
def test_immediately_circular_reference_fails(): with pytest.raises(ReferenceParseError): _ = RefDict("tests/schemas/bad-circular.yaml#/definitions/foo")
def schema(request): return RefDict(request.param)
def test_loading_unknown_file_raises_document_parse_error(): with pytest.raises(DocumentParseError): _ = RefDict("tests/schemas/nonexistent.yaml#/definitions")
def test_dict_with_ref_to_primitive(): ref_dict = RefDict("base/ref-to-primitive.json#/") assert ref_dict["top"]["primitive"] == "foo" assert ref_dict["top"]["ref_to_primitive"] == "foo"
def test_from_uri_object(): ref_dict = RefDict.from_uri("base/ref-to-primitive.json#/") assert ref_dict == RefDict("base/ref-to-primitive.json#/")
def test_ref_dict_raises_when_target_is_not_object(reference: str): with pytest.raises(TypeError): _ = RefDict(reference)
def test_can_get_json_schema_ref(): assert RefDict("https://json-schema.org/draft-07/schema#/")
def test_get_non_ref_ref_key(): assert RefDict("base/nonref.json#/definitions")["$ref"] == { "type": "string" }
def test_direct_reference_retrieval_in_array(): assert RefDict("base/reflist.json#/definitions/foo/not/0") == { "type": "object" }
def test_references_propagate_through_arrays(): ref_dict = RefDict("base/reflist.json#/definitions") assert ref_dict["foo"]["not"][0] == {"type": "object"}
def ref_dict(): return RefDict(URI.from_string("base/file1.json#/definitions"))
def test_external_document_loads_correctly(uri: str): assert RefDict(uri)