Esempio n. 1
0
    def test_index_extra(self):
        ex1a, ex1b, ex2, ex3a, ex3b = (
            object(),
            object(),
            object(),
            object(),
            object(),
        )

        result = self._fixture(extras=[(ex1a, ex1b), (ex2,), (ex3a, ex3b,)])
        eq_(
            result.columns(ex2, ex3b).columns(ex3a).all(),
            [(1,), (2,), (2,), (2,)],
        )

        result = self._fixture(extras=[(ex1a, ex1b), (ex2,), (ex3a, ex3b,)])
        eq_([row._mapping[ex1b] for row in result], [1, 2, 1, 4])

        result = self._fixture(extras=[(ex1a, ex1b), (ex2,), (ex3a, ex3b,)])
        eq_(
            [
                dict(r)
                for r in result.columns(ex2, ex3b).columns(ex3a).mappings()
            ],
            [{"c": 1}, {"c": 2}, {"c": 2}, {"c": 2}],
        )
Esempio n. 2
0
    def test_columns_again(self):
        result = self._fixture()

        eq_(
            result.columns("b", "c", "a").columns(1, 2).all(),
            [(1, 1), (2, 2), (2, 1), (2, 4)],
        )
Esempio n. 3
0
    def test_scalars_mappings(self):
        result = self._fixture()

        eq_(
            list(result.columns(0).mappings()),
            [{"a": 1}, {"a": 2}, {"a": 1}, {"a": 4}],
        )
Esempio n. 4
0
    def test_columns(self, merge_fixture):
        r1, r2, r3, r4 = merge_fixture

        result = r1.merge(r2, r3, r4)
        eq_(
            result.columns("user_name").fetchmany(4),
            [("u1",), ("u2",), ("u3",), ("u4",)],
        )
        result.close()
Esempio n. 5
0
    def test_columns_unique_freeze(self):
        result = self._fixture()

        result = result.columns("b", "c").unique()

        frozen = result.freeze()

        r1 = frozen()
        eq_(r1.fetchall(), [(1, 1), (1, 2), (3, 2)])
Esempio n. 6
0
    def test_alt_row_transform(self):
        class AppleRow(Row):
            def apple(self):
                return "apple"

        result = self._fixture(alt_row=AppleRow)

        row = result.columns("c", "a").all()[2]
        eq_(row.apple(), "apple")
        eq_(row, (2, 1))
Esempio n. 7
0
 def test_columns_with_mappings(self):
     result = self._fixture()
     eq_(
         [dict(r) for r in result.columns("b", "c").mappings().all()],
         [
             {"b": 1, "c": 1},
             {"b": 1, "c": 2},
             {"b": 3, "c": 2},
             {"b": 1, "c": 2},
         ],
     )
Esempio n. 8
0
    def test_unique_default_filters_rearrange_twice(self):
        # test that the default uniqueness filter is reconfigured
        # each time columns() is called
        result = self._fixture(
            default_filters=[lambda x: x < 4, lambda x: x, lambda x: True])

        result = result.unique()

        # 1, 1, 1  ->   True, 1, True
        eq_(result.fetchone(), (1, 1, 1))

        # now rearrange for b, a, c
        # 1, 2, 2  ->   1, True, True
        # 3, 1, 2  ->   3, True, True
        result = result.columns("b", "a", "c")
        eq_(result.fetchone(), (3, 1, 2))

        # now rearrange for c, a
        # 2, 4  -> True, False
        result = result.columns("c", "a")
        eq_(result.fetchall(), [(2, 4)])
Esempio n. 9
0
    def test_columns_ints(self):
        result = self._fixture()

        eq_(result.columns(1, -2).all(), [(1, 1), (1, 1), (3, 3), (1, 1)])
Esempio n. 10
0
    def test_columns(self):
        result = self._fixture()

        result = result.columns("b", "c")
        eq_(result.keys(), ["b", "c"])
        eq_(result.all(), [(1, 1), (1, 2), (3, 2), (1, 2)])