示例#1
6
 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
示例#2
0
 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
示例#3
0
 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
示例#4
0
 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
示例#5
0
 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"
示例#6
0
 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
示例#7
0
 def test_resolve_present(self):
     p = Predicate("name is 'Jack' and friend is 'Jill'")
     assert p.resolve_identifier({"name": "abc"}, "name") == "abc"
示例#8
0
 def test_resolve_missing(self):
     p = Predicate("name is 'Jack' and friend is 'Jill'")
     assert p.resolve_identifier({}, "name") == ast.Undefined()
示例#9
0
 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
示例#10
0
 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"
示例#11
0
 def test_resolve_present(self):
     p = Predicate("name is 'Jack' and friend is 'Jill'")
     assert p.resolve_identifier({"name": "abc"}, "name") == "abc"
示例#12
0
 def test_resolve_missing(self):
     p = Predicate("name is 'Jack' and friend is 'Jill'")
     assert p.resolve_identifier({}, "name") == ast.Undefined()