示例#1
0
 def test_find_where(self):
     # "([*] where spam ge 2).bacon"
     jsonpath = Child(
         Where(Slice(), Cmp(Fields('spam'), ge, 2)),
         Fields('bacon')
     )
     matches = jsonpath.find(MENU)
     self.assertEqual(len(matches), 2)  # There are two menu items with bacon where spam >= 2
示例#2
0
 def test_cmp_list(self):
     jsonpath = Cmp(Root(), eq, 1)  # "[*] eq 1"
     matches = jsonpath.find(MENU)
     self.assertEqual(len(matches), 0)
示例#3
0
 def test_find_many(self):
     jsonpath = Cmp(Child(Slice(), Fields('spam')), gt, 0)  # "[*].spam gt 0"
     self.assertEqual(str(jsonpath), '[*].spam gt 0')
     values = [match.value for match in jsonpath.find(MENU)]
     self.assertEqual(values, [1, 1, 1, 2, 4, 4, 10])
示例#4
0
 def test_find_one(self):
     max_spam = MENU[-1]
     jsonpath = Cmp(Fields('spam'), gt, 0)  # "spam gt 0"
     values = [match.value for match in jsonpath.find(max_spam)]
     self.assertEqual(values, [10])
示例#5
0
 def test_union(self):
     jsonpath = self.get_jsonpath("c1f455e7-3f10-11e4-adec-0800271c1b75")
     matches = jsonpath.find(self.patient)
     patient_value = matches[0].value
     self.assertEqual(patient_value, "c1fc20ab-3f10-11e4-adec-0800271c1b75")
示例#6
0
 def test_where_not(self):
     jsonpath = self.get_jsonpath("c1f4239f-3f10-11e4-adec-0800271c1b75")
     matches = jsonpath.find(self.patient)
     patient_value = matches[0].value
     self.assertEqual(patient_value, "janajati")