예제 #1
0
    def test_where_or(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        lr = [("nom", 10), ("jean", 40), ("jeanne", 2)]
        schema = [("nom", str), ("age", int)]
        tbl = IterRow(schema, lr)
        iter = tbl.where(
            (tbl.age == 2).Or(
                tbl.age == 40),
            append_condition=True)
        res = list(iter)
        exp = [{'nom': 'jean', 'age': 40, '__unk__': True},
               {'nom': "jeanne", 'age': 2, '__unk__': True}, ]
        if res != exp:
            raise ValueError(str(res) + "\n\n" + iter.print_schema())

        iter = tbl.where((tbl.age == 10).Not())
        res = list(iter)
        assert len(res) == 2
예제 #2
0
    def test_where2(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        lr = [("nom", 10), ("jean", 40), ("jeanne", 2)]
        schema = [("nom", str), ("age", int)]
        tbl = IterRow(schema, lr)

        iter = tbl.where(tbl.age >= 40)
        res = list(iter)
        exp = [{'nom': "jean", 'age': 40}]
        if res != exp:
            raise ValueError(str(res))

        iter = tbl.where(tbl.age <= 2)
        res = list(iter)
        exp = [{'nom': "jeanne", 'age': 2}]
        if res != exp:
            raise ValueError(str(res))

        iter = tbl.where(tbl.age < 2)
        res = list(iter)
        exp = []
        if res != exp:
            raise ValueError(str(res))

        iter = tbl.where(tbl.age > 20)
        res = list(iter)
        exp = [{'nom': "jean", 'age': 40}]
        if res != exp:
            raise ValueError(str(res))

        iter = tbl.where(tbl.age != 10)
        res = list(iter)
        assert len(res) == 2