Esempio n. 1
0
def test_tabulate_list_of_dicts_sorted_ascending_by_columns_1_and_ascending_by_column_2(
):
    actual = tabulate(e, [0, 1], [], v_level_sort_keys=(asc(), asc()))
    expected = [[0, 'pour', 4], [0, 'serve', 5],
                [0, 'set', 3], [1, 'serve', 19], [1, 'set', 12],
                [1, 'volley', 9], [2, 'cast', 14], [2, 'pour', 1],
                [2, 'set', 98], [3, 'cast', 34], [3, 'fish',
                                                  8], [3, 'line', 18]]
    assert actual == expected
def test_multisort_with_specified_multiple_keys():
    items = [
        "Hello", "Hotel", "Hippopotamus", "Hero", "Hook", "Abacus", "Angel",
        "Angle", "Archway", "Arcuate", "Amazed"
    ]
    s = sorted(sorted(items, reverse=True), key=len)
    m = multisorted(items, asc(len), dec())
    assert m == s
Esempio n. 3
0
STUB_COLUMNS_OPTION = "stub-columns"
HEADER_ROWS_OPTION = "header-rows"
WIDTHS_OPTION = "widths"
TITLE_OPTION = "title"
H_LEVEL_TITLES_OPTION = "h-level-titles"
V_LEVEL_TITLES_OPTION = "v-level-titles"
V_LEVEL_SORT_ORDERS_OPTION = "v-level-sort-orders"
H_LEVEL_SORT_ORDERS_OPTION = "h-level-sort-orders"
V_LEVEL_VISIBILITY_OPTION = "v-level-visibility"
H_LEVEL_VISIBILITY_OPTION = "h-level-visibility"
V_LEVEL_INDEXES_OPTION = "v-level-indexes"
H_LEVEL_INDEXES_OPTION = "h-level-indexes"

_natural = natsort.natsort_keygen()

SORT_ORDERS = {"asc": asc(_natural), "dec": dec(_natural), "as-is": as_is()}

VISIBILITIES = {"show": True, "hide": False}


class ItemsTableDirective(Directive):
    """Format a data structure as a table.

    If the items of the sequence are themselves sequences, they will formatted as rows.
    """

    required_arguments = 1
    has_content = False
    option_spec = {
        TITLE_OPTION:
        unchanged_required,
Esempio n. 4
0
ENUMERATED_LIST_TYPE = "enumerated"
DEFINITION_LIST_TYPE = "definition"

LIST_TYPES_OPTION = "list-types"
KEY_FORMATS_OPTION = "key-formats"
SORT_ORDERS_OPTION = "sort-orders"
INTERNAL_FORMATS_OPTION = "internal-formats"
LEAF_FORMAT_OPTION = "leaf-format"
ORDINAL_BASES_OPTION = "ordinal-bases"

_natural = natsort.natsort_keygen()

ENUMERATOR_PATTERN = Body.patterns["enumerator"]

TEXT_SORT_ORDERS = {
    ASCENDING: asc(_natural),
    DECENDING: dec(_natural),
    AS_IS: as_is()
}

SORT_ORDERS = {ASCENDING: asc(), DECENDING: dec(), AS_IS: as_is()}

DEFAULT_KEY_FORMATS = {
    BULLET_LIST_TYPE: "*",
    ENUMERATED_LIST_TYPE: "1.",
    DEFINITION_LIST_TYPE: "{k}",
}

DEFAULT_INTERNAL_FORMAT = object()

DEFAULT_INTERNAL_FORMATS = {
def test_multisort_with_specified_ascending_key():
    items = [4, 7, 1, 3, 9, 4, 5, 2]
    assert multisorted(items, asc()) == sorted(items)