tests.test_table module

tests.test_table.test_table_formats_definition()[source]

Check all table formats are accounted for and properly named.

tests.test_table.test_unrecognized_format(invoke, cmd_decorator, cmd_type)[source]
tests.test_table.test_corner_header()[source]
tests.test_table.test_all_table_formats_have_test_rendering()[source]

Check all table formats have a rendering test fixture defined.

tests.test_table.test_all_table_rendering(invoke, cmd_decorator, option_decorator, format_name, expected)[source]
tests.test_table.test_emoji_presentation_width_follows_the_terminal(monkeypatch, term_program, expected)[source]

An emoji-presentation sequence measures as its terminal advances it.

tests.test_table.test_emoji_presentation_gains_the_column_it_paints_into(monkeypatch)[source]

A terminal painting the glyph wider than it advances gets a column for it.

tests.test_table.test_emoji_presentation_padding_stays_out_of_markup(monkeypatch)[source]

A markup rendering outlives this terminal, so its cells keep their text.

tests.test_table.test_markup_pads_emoji_presentation_by_unicode_width(monkeypatch)[source]

A markup table pads an emoji-presentation sequence by the Unicode tables.

Whatever terminal renders it: a Markdown table is read by a formatter and a browser that never see that terminal, and mdformat pads it with wcswidth.

tests.test_table.test_print_table_pads_markup_by_unicode_width(monkeypatch, capsys)[source]

print_table measures a markup table like render_table does.

A narrow-emoji terminal must not leak into a Markdown table that a subcommand prints with ctx.print_table.

tests.test_table.test_table_rows_line_up_on_every_terminal_wcwidth_knows(monkeypatch, term_program)[source]

Rows advance the same width on each terminal, not just the default one.

Measured with wcwidth’s own per-terminal tables rather than with the measure the layout used, so a terminal whose correction Click Extra misses shows up as a ragged table instead of agreeing with itself.

tests.test_table.test_table_rows_are_uniform_under_a_narrow_emoji_terminal(monkeypatch)[source]

Every row of a rendered table advances the same width in that terminal.

Measured with the terminal’s own rule, which is the one deciding whether the table’s vertical rules line up on screen.

tests.test_table.test_markup_strips_ansi_by_default(invoke, format_id)[source]

Markup formats without native styling strip ANSI codes by default.

tests.test_table.test_markup_preserves_ansi_with_color_flag(invoke, format_id)[source]

--color overrides ANSI stripping for non-styled markup formats.

tests.test_table.test_color_flag_from_parent_group_preserves_ansi(invoke)[source]

A --color forced on a parent group reaches the subcommand’s table.

Mirrors the layout of the click-extra demo CLI: the color and table options live on the group, while the table is printed from a subcommand whose context does not own those parameters.

tests.test_table.STYLED_MARKUP_SAMPLES = {TableFormat.HTML: '<span style="color: red">hello</span>', TableFormat.JIRA: '{color:red}hello{color}', TableFormat.LATEX: '\\textcolor{red}{hello}', TableFormat.LATEX_BOOKTABS: '\\textcolor{red}{hello}', TableFormat.LATEX_LONGTABLE: '\\textcolor{red}{hello}', TableFormat.LATEX_RAW: '\\textcolor{red}{hello}', TableFormat.MEDIAWIKI: '<span style="color: red">hello</span>', TableFormat.TEXTILE: '%{color: red}hello%', TableFormat.UNSAFEHTML: '<span style="color: red">hello</span>'}

Expected native styling of a red hello cell, per styled format.

tests.test_table.test_styled_formats_all_have_samples()[source]
tests.test_table.test_styled_formats_translate_ansi(invoke, format_id, styled_cell, flags)[source]

Styled formats translate ANSI codes to native markup, by default and under a forced --color alike.

tests.test_table.test_styled_formats_strip_ansi_with_no_color(invoke, format_id)[source]

Disabling colors renders styled formats plain, with no translation.

tests.test_table.test_serialize_json_compatible(table_format, data)[source]
tests.test_table.test_serialize_roundtrip(table_format, data, loader)[source]
tests.test_table.test_serialize_toml_list_wrapping()[source]

Top-level lists are wrapped under a record key for TOML.

tests.test_table.test_serialize_strips_none(table_format)[source]

TOML and XML have no null type. None values are omitted.

tests.test_table.test_serialize_xml()[source]
tests.test_table.test_serialize_xml_list_wrapping()[source]

Top-level lists are wrapped under a record key for XML.

tests.test_table.test_serialize_xml_custom_root_element()[source]
tests.test_table.test_serialize_xml_respells_invalid_names()[source]

Keys XML does not accept as element names still give a well-formed document.

tests.test_table.test_serialize_default_callback()[source]

Custom types are converted via the default callback.

tests.test_table.test_serialize_unsupported_format_raises()[source]
tests.test_table.test_strip_none(data, expected)[source]
tests.test_table.test_apply_default_native_types_unchanged()[source]
tests.test_table.test_apply_default_custom_type_converted(data, expected)[source]
tests.test_table.test_missing_dependency_clean_error(monkeypatch, func, args, kwargs, message)[source]

Missing optional dependency produces a clean error, no traceback.

tests.test_table.test_render_table_sort(data, headers, sort_key, expected_fruits)[source]
tests.test_table.test_render_table_header_edge_cases(headers, data, expected)[source]

Edge cases for header handling in structured format rendering.

tests.test_table.test_render_table_xml_element_names(headers, expected)[source]

An XML table parses back with one element per cell, whatever its headers.

An element name cannot start with a digit, so a cell position or a numeric header gets a leading underscore and keeps its digits. A None cell is left out without shifting the position of the cells after it.

tests.test_table.test_wrappable_formats_definition()[source]

Wrapping is claimed by text layouts only, never by a data interchange.

tests.test_table.test_max_column_widths_never_breaks_a_format(format_id)[source]

Every format accepts a width: it either wraps on it or drops it.

Locks the invariant across the whole enum, so a format added later cannot silently raise or corrupt its output when handed a width.

tests.test_table.test_max_column_widths_keeps_data_formats_intact(format_id)[source]

A width never leaks a line break into a serialized cell.

tests.test_table.test_max_column_widths_scalar_applies_to_every_column()[source]

A single value stands in for a per-column list.

tests.test_table.test_max_column_widths_shorter_than_the_table()[source]

A list shorter than the table leaves the trailing columns unlimited.

tests.test_table.test_column_spec_max_width_is_the_default_source()[source]

A width declared on a ColumnSpec applies without any argument.

tests.test_table.test_max_column_widths_overrides_column_spec()[source]

An explicit argument wins over the ColumnSpec declaration.

tests.test_table.test_column_spec_max_width_follows_a_projection()[source]

A ColumnSpec width stays on its column when others are dropped.

tests.test_table.test_auto_width_fits_the_terminal(monkeypatch)[source]

An auto column absorbs the width left by the others.

tests.test_table.test_auto_width_shares_the_remainder(monkeypatch)[source]

Several auto columns split what is left evenly.

tests.test_table.test_auto_width_floors_at_min_column_width(monkeypatch)[source]

A terminal too narrow to fit the table still renders a usable column.

tests.test_table.test_auto_width_honors_context_width(invoke)[source]

auto reads the width a help screen would use, not the raw terminal.

tests.test_table.test_vertical_wrapping_keeps_the_label_gutter()[source]

Continuation lines of a wrapped cell align under the first one.

tests.test_table.test_vertical_labels_align_on_their_visible_width(headers)[source]

Labels are padded to the columns they occupy, not to their length.

Escape codes take no column and a double-width character takes two, so the separators and the continuation lines of a wrapped cell stay in one column.

tests.test_table.test_column_sort_key(header_defs, rows, sort_columns, cell_key, expected_first_col)[source]
tests.test_table.test_sort_by_option_choices_and_default(header_defs, expected_choices, expected_default)[source]

SortByOption choices and default are derived from column definitions.

tests.test_table.test_sort_by_option_wires_context(invoke)[source]

SortByOption publishes the sort key that ctx.print_table applies.

tests.test_table.test_print_table_from_subcommand_context(invoke)[source]

A group-level –table-format reaches ctx.print_table in subcommands.

ctx.meta is shared along the context chain, so the print_table context method works from a subcommand without reaching for the root context.

tests.test_table.test_print_table_without_table_option(invoke)[source]

ctx.print_table works with no –table-format in the chain.

Falls back to the default rendering format, like the module-level print_table() invoked without an explicit format.

tests.test_table.test_render_table_context_method_honors_sort_by(invoke)[source]

ctx.render_table applies the –sort-by selection, like ctx.print_table.

tests.test_table.test_sort_by_option_multi_column(invoke)[source]

Multiple –sort-by options define sort priority.

tests.test_table.test_sort_by_option_decorator(invoke)[source]

The sort_by_option decorator wires sorting like a direct SortByOption.

tests.test_table.test_sort_by_option_decorator_in_option_group(invoke)[source]

The sort_by_option decorator composes with @option_group.

tests.test_table.test_sort_by_option_columns_registry(invoke)[source]

A ColumnSpec registry passed via columns= drives choices and ordering.

tests.test_table.test_sort_by_option_accepts_column_spec_varargs()[source]

ColumnSpec instances also work positionally, normalized to (label, id).

tests.test_table.test_sort_by_option_rejects_positional_and_columns()[source]

Column definitions cannot be passed both positionally and via columns=.

tests.test_table.test_columns_type_matches_ids_exactly()[source]

Column IDs are identifiers: a comma list, matched with their case.

tests.test_table.test_sort_by_and_columns_share_registry()[source]

The same ColumnSpec registry configures both –columns and –sort-by.

tests.test_table.test_column_sort_key_field_mapping(header_defs, sort_columns, rows, expected_first_col)[source]

The public key builder maps requested fields onto the carried columns.

tests.test_table.test_column_sort_key_none_when_not_carried(sort_columns)[source]

No requested field carried by the table: rows must keep their order.

tests.test_table.test_render_table_rich_headers_render_labels()[source]

ColumnSpec and plain label header entries render their labels.

tests.test_table.test_unsortable_column_keeps_its_place()[source]

sortable=False keeps a column in the layout, out of the sort choices.

tests.test_table.test_sort_by_option_field_vocabulary()[source]

Bare column IDs declare a table-less field vocabulary.

tests.test_table.test_sort_by_option_labeled_defs_not_vocabulary()[source]

Labeled definitions keep the declaration-time baked-sort behavior.

tests.test_table.test_sort_by_option_rejects_mixed_defs()[source]

Bare IDs and labeled definitions cannot be mixed.

tests.test_table.test_sort_by_group_heterogeneous_tables(invoke)[source]

A group-level field vocabulary sorts each subcommand’s table independently.

Each table sorts by the selected fields it carries; a table carrying none of them keeps its original row order.

tests.test_table.test_print_table_explicit_sort_key_wins(invoke)[source]

An explicit sort_key bypasses the context --sort-by resolution.