Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 67870ae

Browse files
authored
Merge pull request #10029 from ivanov/doctest-utils-text
enable and fix doctests for IPython.utils
2 parents 6a5220d + 7315236 commit 67870ae

2 files changed

Lines changed: 8 additions & 13 deletions

File tree

IPython/testing/iptest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def run_iptest():
400400
SubprocessStreamCapturePlugin() ]
401401

402402
# we still have some vestigial doctests in core
403-
if (section.name.startswith(('core', 'IPython.core'))):
403+
if (section.name.startswith(('core', 'IPython.core', 'IPython.utils'))):
404404
plugins.append(IPythonDoctest())
405405
argv.extend([
406406
'--with-ipdoctest',

IPython/utils/text.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ def _find_optimal(rlist, row_first=False, separator_size=2, displaywidth=80):
635635
if sumlength + separator_size * (ncols - 1) <= displaywidth:
636636
break
637637
return {'num_columns': ncols,
638-
'optimal_separator_width': (displaywidth - sumlength) / (ncols - 1) if (ncols - 1) else 0,
638+
'optimal_separator_width': (displaywidth - sumlength) // (ncols - 1) if (ncols - 1) else 0,
639639
'max_rows': max_rows,
640640
'column_widths': col_widths
641641
}
@@ -694,17 +694,12 @@ def compute_item_matrix(items, row_first=False, empty=None, *args, **kwargs) :
694694
::
695695
696696
In [1]: l = ['aaa','b','cc','d','eeeee','f','g','h','i','j','k','l']
697-
...: compute_item_matrix(l, displaywidth=12)
698-
Out[1]:
699-
([['aaa', 'f', 'k'],
700-
['b', 'g', 'l'],
701-
['cc', 'h', None],
702-
['d', 'i', None],
703-
['eeeee', 'j', None]],
704-
{'num_columns': 3,
705-
'column_widths': [5, 1, 1],
706-
'optimal_separator_width': 2,
707-
'max_rows': 5})
697+
In [2]: list, info = compute_item_matrix(l, displaywidth=12)
698+
In [3]: list
699+
Out[3]: [['aaa', 'f', 'k'], ['b', 'g', 'l'], ['cc', 'h', None], ['d', 'i', None], ['eeeee', 'j', None]]
700+
In [4]: ideal = {'num_columns': 3, 'column_widths': [5, 1, 1], 'optimal_separator_width': 2, 'max_rows': 5}
701+
In [5]: all((info[k] == ideal[k] for k in ideal.keys()))
702+
Out[5]: True
708703
"""
709704
info = _find_optimal(list(map(len, items)), row_first, *args, **kwargs)
710705
nrow, ncol = info['max_rows'], info['num_columns']

0 commit comments

Comments
 (0)