示例#1
0
    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"]}}
示例#2
0
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)
示例#3
0
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
示例#4
0
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
示例#5
0
 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"}
示例#6
0
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")
示例#7
0
def test_can_materialize_json_schema_ref():
    schema = materialize(RefDict("https://json-schema.org/draft-07/schema#/"))
    assert isinstance(schema, dict)
示例#8
0
def test_immediately_circular_reference_fails():
    with pytest.raises(ReferenceParseError):
        _ = RefDict("tests/schemas/bad-circular.yaml#/definitions/foo")
示例#9
0
 def schema(request):
     return RefDict(request.param)
示例#10
0
 def test_loading_unknown_file_raises_document_parse_error():
     with pytest.raises(DocumentParseError):
         _ = RefDict("tests/schemas/nonexistent.yaml#/definitions")
示例#11
0
 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"
示例#12
0
 def test_from_uri_object():
     ref_dict = RefDict.from_uri("base/ref-to-primitive.json#/")
     assert ref_dict == RefDict("base/ref-to-primitive.json#/")
示例#13
0
 def test_ref_dict_raises_when_target_is_not_object(reference: str):
     with pytest.raises(TypeError):
         _ = RefDict(reference)
示例#14
0
def test_can_get_json_schema_ref():
    assert RefDict("https://json-schema.org/draft-07/schema#/")
示例#15
0
 def test_get_non_ref_ref_key():
     assert RefDict("base/nonref.json#/definitions")["$ref"] == {
         "type": "string"
     }
示例#16
0
 def test_direct_reference_retrieval_in_array():
     assert RefDict("base/reflist.json#/definitions/foo/not/0") == {
         "type": "object"
     }
示例#17
0
 def test_references_propagate_through_arrays():
     ref_dict = RefDict("base/reflist.json#/definitions")
     assert ref_dict["foo"]["not"][0] == {"type": "object"}
示例#18
0
 def ref_dict():
     return RefDict(URI.from_string("base/file1.json#/definitions"))
示例#19
0
def test_external_document_loads_correctly(uri: str):
    assert RefDict(uri)