def test_format_string_list_to_columns_when_not_given_max_uses_shell_size( mocker, echo_output): terminal_size = mocker.patch("code42cli.util.shutil.get_terminal_size") max_width = 30 terminal_size.return_value = (max_width, None) # Cols, Rows columns = ["col1", "col2"] format_string_list_to_columns(columns) printed_row = echo_output.call_args_list[0][0][0] assert len(printed_row) == get_expected_row_width(4, max_width) assert printed_row == "col1 col2 "
def test_format_string_list_to_columns_when_given_small_max_width_prints_one_column_per_row( echo_output, ): max_width = 5 columns = ["col1", "col2"] format_string_list_to_columns(columns, max_width) expected_row_width = get_expected_row_width(4, max_width) printed_row = echo_output.call_args_list[0][0][0] assert len(printed_row) == expected_row_width assert printed_row == "col1 " printed_row = echo_output.call_args_list[1][0][0] assert len(printed_row) == expected_row_width assert printed_row == "col2 "
def test_format_string_list_to_columns_uses_width_of_longest_string( echo_output): max_width = 5 columns = ["col1", "col2_that_is_really_long"] format_string_list_to_columns(columns, max_width) expected_row_width = get_expected_row_width( len("col2_that_is_really_long"), max_width) printed_row = echo_output.call_args_list[0][0][0] assert len(printed_row) == expected_row_width assert printed_row == "col1 " printed_row = echo_output.call_args_list[1][0][0] assert len(printed_row) == expected_row_width assert printed_row == "col2_that_is_really_long "
def test_format_string_list_to_columns_when_given_no_string_list_does_not_echo( echo_output, ): format_string_list_to_columns([], None) format_string_list_to_columns(None, None) assert not echo_output.call_count
def _print_matter_members(username_list, member_type="active"): if username_list: echo("\n{} matter members:\n".format(member_type.capitalize())) format_string_list_to_columns(username_list) else: echo("No {} matter members.\n".format(member_type))