##// END OF EJS Templates
fix compute_item_matrix doctest
Paul Ivanov -
Show More
@@ -639,7 +639,7 b' def _find_optimal(rlist, row_first=False, separator_size=2, displaywidth=80):'
639 if sumlength + separator_size * (ncols - 1) <= displaywidth:
639 if sumlength + separator_size * (ncols - 1) <= displaywidth:
640 break
640 break
641 return {'num_columns': ncols,
641 return {'num_columns': ncols,
642 'optimal_separator_width': (displaywidth - sumlength) / (ncols - 1) if (ncols - 1) else 0,
642 'optimal_separator_width': (displaywidth - sumlength) // (ncols - 1) if (ncols - 1) else 0,
643 'max_rows': max_rows,
643 'max_rows': max_rows,
644 'column_widths': col_widths
644 'column_widths': col_widths
645 }
645 }
@@ -698,17 +698,12 b' def compute_item_matrix(items, row_first=False, empty=None, *args, **kwargs) :'
698 ::
698 ::
699
699
700 In [1]: l = ['aaa','b','cc','d','eeeee','f','g','h','i','j','k','l']
700 In [1]: l = ['aaa','b','cc','d','eeeee','f','g','h','i','j','k','l']
701 ...: compute_item_matrix(l, displaywidth=12)
701 In [2]: list, info = compute_item_matrix(l, displaywidth=12)
702 Out[1]:
702 In [3]: list
703 ([['aaa', 'f', 'k'],
703 Out[3]: [['aaa', 'f', 'k'], ['b', 'g', 'l'], ['cc', 'h', None], ['d', 'i', None], ['eeeee', 'j', None]]
704 ['b', 'g', 'l'],
704 In [4]: ideal = {'num_columns': 3, 'column_widths': [5, 1, 1], 'optimal_separator_width': 2, 'max_rows': 5}
705 ['cc', 'h', None],
705 In [5]: all((info[k] == ideal[k] for k in ideal.keys()))
706 ['d', 'i', None],
706 Out[5]: True
707 ['eeeee', 'j', None]],
708 {'num_columns': 3,
709 'column_widths': [5, 1, 1],
710 'optimal_separator_width': 2,
711 'max_rows': 5})
712 """
707 """
713 info = _find_optimal(list(map(len, items)), row_first, *args, **kwargs)
708 info = _find_optimal(list(map(len, items)), row_first, *args, **kwargs)
714 nrow, ncol = info['max_rows'], info['num_columns']
709 nrow, ncol = info['max_rows'], info['num_columns']
General Comments 0
You need to be logged in to leave comments. Login now