File: test_summary.py

package info (click to toggle)
python-pyout 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 328 kB
  • sloc: python: 3,453; makefile: 3
file content (53 lines) | stat: -rw-r--r-- 1,615 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from pyout.summary import Summary


def eq(result, expect):
    """Unwrap summarize `result` and assert that it is equal to `expect`.
    """
    assert [r[0] for r in result] == expect


def test_summary_summarize_no_agg_columns():
    sm = Summary({"col1": {}})
    eq(sm.summarize(["col1"],
                    [{"col1": "a"},
                     {"col1": "b"}]),
       [])


def test_summary_summarize_atom_return():
    sm = Summary({"col1": {"aggregate": len}})
    eq(sm.summarize(["col1"],
                    [{"col1": "a"},
                     {"col1": "b"}]),
       [{"col1": 2}])


def test_summary_summarize_list_return():
    def unique_lens(xs):
        return list(sorted(set(map(len, xs))))

    sm = Summary({"col1": {"aggregate": unique_lens}})
    eq(sm.summarize(["col1"],
                    [{"col1": "a"},
                     {"col1": "bcd"},
                     {"col1": "ef"},
                     {"col1": "g"}]),
       [{"col1": 1},
        {"col1": 2},
        {"col1": 3}])


def test_summary_summarize_multicolumn_return():
    def unique_values(xs):
        return list(sorted(set(xs)))

    sm = Summary({"col1": {"aggregate": unique_values},
                  "col2": {"aggregate": len},
                  "col3": {"aggregate": unique_values}})
    eq(sm.summarize(["col1", "col2", "col3"],
                    [{"col1": "a", "col2": "x", "col3": "c"},
                     {"col1": "b", "col2": "y", "col3": "c"},
                     {"col1": "a", "col2": "z", "col3": "c"}]),
       [{"col1": "a", "col2": 3, "col3": "c"},
        {"col1": "b", "col2": "", "col3": ""}])