def test_percent_sub(): obj = { "foo": {"__macro!": "foosub"} } exp = { "foo.foo": "the key was foo" } traverse_and_compare(obj, exp, macros)
def test_class_jq_template(): obj = { "foo": {"__macro": "foojq", "number": 7, "obj": {"bar": 7}} } exp = { "foo": {"foo": "the number is 7", "bar": {"bar": 7}}, } traverse_and_compare(obj, exp, macros)
def test_invalid_schema(): obj = { "foo": {"__macro": "fooinvalid"} } try: traverse_and_compare(obj, [], macros) assert False except ValidationError as err: assert err is not None
def test_file_object_simple(): obj = {"foo": {"__file_object": "files/a-json-object.json"}} exp = {"foo": {"a": "b"}} traverse_and_compare(obj, exp, macros)
def test_file_object_recursion(): obj = {"foo": {"__file_object": "files/a-json-object-with-refs.json"}} exp = {"foo": {"foo": {"a": "b"}}} traverse_and_compare(obj, exp, macros)
def test_file_string(): obj = {"foo": {"__file_string": "files/simple-string.txt"}} exp = {"foo": "word"} traverse_and_compare(obj, exp, macros)
def test_file_object_extend(): obj = {"foo": {"__file_object!": "files/a-json-object.json"}, "bar": "baz"} exp = {"a": "b", "bar": "baz"} traverse_and_compare(obj, exp, macros)
def test_jq_obj_in_str(): obj = "an obj: ${.foo}" exp = 'an obj: {"bar": 7}' traverse_and_compare(obj, exp, macros)
def test_jq_str(): obj = {"foo": "a number: ${.foo.bar}"} exp = {"foo": "a number: 7"} traverse_and_compare(obj, exp, macros)
def test_jq_nested(): obj = {"foo": {"__jq": ".foo"}} exp = {"foo": {"bar": 7}} traverse_and_compare(obj, exp, macros)
def test_jq(): obj = {"__jq": ".foo"} traverse_and_compare(obj, {"bar": 7}, macros)