summaryrefslogtreecommitdiffstats
path: root/tests/tabular_output/test_vertical_table_adapter.py
blob: 359d9d971f7c5f31c59183ea8ef14d7ac7ee48ab (plain)
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
# -*- coding: utf-8 -*-
"""Test the vertical table formatter."""

from textwrap import dedent

from cli_helpers.compat import text_type
from cli_helpers.tabular_output import vertical_table_adapter


def test_vertical_table():
    """Test the default settings for vertical_table()."""
    results = [("hello", text_type(123)), ("world", text_type(456))]

    expected = dedent(
        """\
        ***************************[ 1. row ]***************************
        name | hello
        age  | 123
        ***************************[ 2. row ]***************************
        name | world
        age  | 456"""
    )
    assert expected == "\n".join(
        vertical_table_adapter.adapter(results, ("name", "age"))
    )


def test_vertical_table_customized():
    """Test customized settings for vertical_table()."""
    results = [("john", text_type(47)), ("jill", text_type(50))]

    expected = dedent(
        """\
        -[ PERSON 1 ]-----
        name | john
        age  | 47
        -[ PERSON 2 ]-----
        name | jill
        age  | 50"""
    )
    assert expected == "\n".join(
        vertical_table_adapter.adapter(
            results,
            ("name", "age"),
            sep_title="PERSON {n}",
            sep_character="-",
            sep_length=(1, 5),
        )
    )