def test_node_not_equals(self): assert not Root() == This() assert not This() == Index(2) assert not Index(2) == Root() assert not Len() == Avg() assert not Sum() == Len() assert not Avg() == Sorted() assert not Sorted() == Sum() assert not And(Root(), Fields("name")) == And(Root(), Fields("other")) assert not Or(Root(), Fields("name")) == Or(Root(), Fields("other")) assert not Or(Root(), Fields("name")) == And(Root(), Fields("name"))
def test_node_equals(self): assert Root() == Root() assert This() == This() assert Index(2) == Index(2) assert Len() == Len() assert Sum() == Sum() assert Avg() == Avg() assert Sorted() == Sorted() assert And(Root(), Fields("name")) == And(Root(), Fields("name")) assert Or(Root(), Fields("name")) == Or(Root(), Fields("name")) assert Child(Root(), Fields("name")) == Child(Root(), Fields("name")) assert Where(Root(), Fields("name")) == Where(Root(), Fields("name"))
def test_find_with_exception(self): extra = ( { "one": 1, "two": 2 }, ["this", "is", "sparta"], ["value", 3, False, "true", -5], ) assert_with_error(self, Sum(), JPathNodeError, extra_cases=extra)
def test_find(self): cases = [ ([2, 3, 4, 2, -5], [6]), ({ 1: "one", 2: "two" }, [3]), (list(), [0]), (dict(), [0]), (tuple(), [0]), ] for data, expected in cases: make_verification(self, Sum(), data, expected)
def test_repr_all_leaf(self): self.assertEqual(repr(Root()), "Root()") self.assertEqual(repr(This()), "This()") self.assertEqual(repr(Index(2)), "Index(2)") self.assertEqual(repr(AllIndex()), "AllIndex()") self.assertEqual(repr(Fields("name", "other")), "Fields('name','other')") self.assertEqual(repr(Slice(0, 3, 2)), "Slice(start=0,end=3,step=2)") self.assertEqual(repr(Len()), "Len()") self.assertEqual(repr(Sum()), "Sum()") self.assertEqual(repr(Avg()), "Avg()") self.assertEqual(repr(Sorted()), "Sorted()") self.assertEqual(repr(And(Fields("name"), Fields("id"))), "And(Fields('name'),Fields('id'))") self.assertEqual(repr(Or(Fields("name"), Fields("id"))), "Or(Fields('name'),Fields('id'))")
def test_str_all_leaf(self): self.assertEqual(str(Root()), "$") self.assertEqual(str(This()), "@") self.assertEqual(str(Index(1)), "[1]") self.assertEqual(str(Index("*")), "[*]") self.assertEqual(str(AllIndex()), "[*]") self.assertEqual(str(Fields("name", "other")), "name,other") self.assertEqual(str(Fields("name")), "name") self.assertEqual(str(Slice(0, 3, 2)), "[0:3:2]") self.assertEqual(str(Slice()), "[::]") self.assertEqual(str(Len()), "`len`") self.assertEqual(str(Sum()), "`sum`") self.assertEqual(str(Avg()), "`avg`") self.assertEqual(str(Sorted()), "`sorted`") self.assertEqual(str(And(Fields("name"), Fields("id"))), "name&id") self.assertEqual(str(Or(Fields("name"), Fields("id"))), "name|id")
def test_equal(self): assert Sum() == Sum()