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 )
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
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
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"
def test_ref_pointer_raises_on_no_match(uri: URI, document: Dict[str, Any]): with pytest.raises(JsonPointerException): _ = RefPointer(uri.get("nonexistent")).resolve(document)
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")
def test_re_pointer_path(uri: URI, path: Iterable[str], expected: str): pointer = RefPointer(uri.get("definitions", *path)) assert pointer.path == expected