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)
def test_mul_3(self): var = Const(2) * Const(3) * Const(4) value = var(None) self.assertEqual(value, 24)
def test_mul(self): var = Const(2) * Const(3) value = var(None) self.assertEqual(value, 6)
def test_le_when_equals_should_be_true(self): predicate = Const(2) <= Const(2) self.assertTrue(predicate(None))
def test_le_false(self): predicate = Const(2) <= Const(1) self.assertFalse(predicate(None))
def test_le_true(self): predicate = Const(0) <= Const(1) self.assertTrue(predicate(None))
def test_concat(self): var = Const('fuu') + Const(' ') + Const('bar') value = var(None) self.assertEqual(value, 'fuu bar')
def test_add(self): var = Const(2) + Const(3) value = var(None) self.assertEqual(value, 5)
def test_gt_true(self): predicate = Const(1) > Const(0) self.assertTrue(predicate(None))
def test_ne_diff_should_be_true(self): predicate = Const(1) != Const(2) self.assertTrue(predicate(None))
def test_ne_same_should_be_false(self): predicate = Const(1) != Const(1) self.assertFalse(predicate(None))
def test_cast_str_to_int(self): var = Const('1').cast(int) value = var(None) self.assertIsInstance(value, int)
def test_eq_diff_should_be_false(self): predicate = Const(1) == Const(2) self.assertFalse(predicate(None))
def test_sub_3(self): var = Const(2) - Const(3) - Const(5) value = var(None) self.assertEqual(value, -6)
def test_eq_same_should_be_true(self): predicate = Const(1) == Const(1) self.assertTrue(predicate(None))
def test_gt_false(self): predicate = Const(1) > Const(2) self.assertFalse(predicate(None))
def test_truediv_3(self): var = Const(10) / Const(2) / Const(2) value = var(None) self.assertEqual(value, 2.5)
def test_lt_when_equals_should_be_false(self): predicate = Const(2) < Const(2) self.assertFalse(predicate(None))
def test_add_3(self): var = Const(2) + Const(3) + Const(5) value = var(None) self.assertEqual(value, 10)
class Predicates: ANY = Const(True) NONE = Const(False)