示例#1
0
 def test_to_last(
     uri: URI,
     document: Dict[str, Any],
     path: Iterable[str],
     expected: Tuple[Any, Union[str, int]],
 ):
     pointer = RefPointer(uri.get("definitions", *path))
     assert pointer.to_last(document) == expected
示例#2
0
 def test_ref_pointer_returns_default_if_no_match(
     uri: URI, document: Dict[str, Any]
 ):
     default = "default"
     assert RefPointer(uri.get("nonexistent")).resolve(
         document, default=default
     )
示例#3
0
 def test_ref_pointer_resolve(
     uri: URI,
     document: Dict[str, Any],
     method: str,
     path: Iterable[str],
     expected: Any,
 ):
     pointer = RefPointer(uri.get("definitions", *path))
     assert getattr(pointer, method)(document) == expected
示例#4
0
 def test_ref_to_primitive():
     uri = URI.from_string(
         "base/ref-to-primitive.json#/top/ref_to_primitive")
     document = loader(uri.root)
     assert RefPointer(uri).resolve(document) == "foo"
示例#5
0
 def test_ref_pointer_returns_non_dict_values(uri: URI,
                                              document: Dict[str, Any]):
     uri = uri.get("definitions").get("foo").get("type")
     assert RefPointer(uri).resolve(document) == "string"
示例#6
0
 def test_ref_pointer_raises_on_no_match(uri: URI, document: Dict[str,
                                                                  Any]):
     with pytest.raises(JsonPointerException):
         _ = RefPointer(uri.get("nonexistent")).resolve(document)
示例#7
0
 def test_set_fails(uri: URI, document: Dict[str, Any],
                    path: Iterable[str]):
     pointer = RefPointer(uri.get("definitions", *path))
     with pytest.raises(NotImplementedError):
         pointer.set(document, "foo")
示例#8
0
 def test_re_pointer_path(uri: URI, path: Iterable[str], expected: str):
     pointer = RefPointer(uri.get("definitions", *path))
     assert pointer.path == expected