def test_resolve_dotsyntax(self): p = Predicate("name is 'Jack' and friend is 'Jill'") doc = { "sub": { "inner": { "val" : 42 } } } assert p.resolve_identifier(doc, "sub.inner.val") == 42
def test_resolve_custom(self): import random p = Predicate("name is 'Jack' and friend is 'Jill'") p.set_resolver("random", random.random) r1 = p.resolve_identifier({}, "random") r2 = p.resolve_identifier({}, "random") assert r1 != r2
def test_resolve_custom_fixed(self): p = Predicate("name is 'Jack' and friend is 'Jill'") p.set_resolver("answer", 42) r1 = p.resolve_identifier({}, "answer") assert r1 == 42
def test_resolve_quote(self): p = Predicate("name is 'Jack' and friend is 'Jill'") assert p.resolve_identifier({}, "'name'") == "name" assert p.resolve_identifier({}, "\"name\"") == "name"
def test_resolve_dotsyntax(self): p = Predicate("name is 'Jack' and friend is 'Jill'") doc = {"sub": {"inner": {"val": 42}}} assert p.resolve_identifier(doc, "sub.inner.val") == 42
def test_resolve_present(self): p = Predicate("name is 'Jack' and friend is 'Jill'") assert p.resolve_identifier({"name": "abc"}, "name") == "abc"
def test_resolve_missing(self): p = Predicate("name is 'Jack' and friend is 'Jill'") assert p.resolve_identifier({}, "name") == ast.Undefined()
def test_resolve_quote(self): p = Predicate("name is 'Jack' and friend is 'Jill'") assert p.resolve_identifier({}, "'name'") == "name" assert p.resolve_identifier({}, '"name"') == "name"