Пример #1
0
 def test_with_op(self):
     data = {
         'name': 'Fuu',
         'height': 1.8,
         'weight': 75.6,
     }
     imc = JsonPath.single('$.weight') / JsonPath.single('$.height') ** Const(2)
     self.assertEqual(imc(data), 75.6 / 1.8 ** 2)
Пример #2
0
 def test_mul_3(self):
     var = Const(2) * Const(3) * Const(4)
     value = var(None)
     self.assertEqual(value, 24)
Пример #3
0
 def test_mul(self):
     var = Const(2) * Const(3)
     value = var(None)
     self.assertEqual(value, 6)
Пример #4
0
 def test_le_when_equals_should_be_true(self):
     predicate = Const(2) <= Const(2)
     self.assertTrue(predicate(None))
Пример #5
0
 def test_le_false(self):
     predicate = Const(2) <= Const(1)
     self.assertFalse(predicate(None))
Пример #6
0
 def test_le_true(self):
     predicate = Const(0) <= Const(1)
     self.assertTrue(predicate(None))
Пример #7
0
 def test_concat(self):
     var = Const('fuu') + Const(' ') + Const('bar')
     value = var(None)
     self.assertEqual(value, 'fuu bar')
Пример #8
0
 def test_add(self):
     var = Const(2) + Const(3)
     value = var(None)
     self.assertEqual(value, 5)
Пример #9
0
 def test_gt_true(self):
     predicate = Const(1) > Const(0)
     self.assertTrue(predicate(None))
Пример #10
0
 def test_ne_diff_should_be_true(self):
     predicate = Const(1) != Const(2)
     self.assertTrue(predicate(None))
Пример #11
0
 def test_ne_same_should_be_false(self):
     predicate = Const(1) != Const(1)
     self.assertFalse(predicate(None))
Пример #12
0
 def test_cast_str_to_int(self):
     var = Const('1').cast(int)
     value = var(None)
     self.assertIsInstance(value, int)
Пример #13
0
 def test_eq_diff_should_be_false(self):
     predicate = Const(1) == Const(2)
     self.assertFalse(predicate(None))
Пример #14
0
 def test_sub_3(self):
     var = Const(2) - Const(3) - Const(5)
     value = var(None)
     self.assertEqual(value, -6)
Пример #15
0
 def test_eq_same_should_be_true(self):
     predicate = Const(1) == Const(1)
     self.assertTrue(predicate(None))
Пример #16
0
 def test_gt_false(self):
     predicate = Const(1) > Const(2)
     self.assertFalse(predicate(None))
Пример #17
0
 def test_truediv_3(self):
     var = Const(10) / Const(2) / Const(2)
     value = var(None)
     self.assertEqual(value, 2.5)
Пример #18
0
 def test_lt_when_equals_should_be_false(self):
     predicate = Const(2) < Const(2)
     self.assertFalse(predicate(None))
Пример #19
0
 def test_add_3(self):
     var = Const(2) + Const(3) + Const(5)
     value = var(None)
     self.assertEqual(value, 10)
Пример #20
0
class Predicates:
    ANY = Const(True)
    NONE = Const(False)