From 19e214e7706628fa4c38b4b9adf7aa55e8254712 2015-08-20 08:42:36 From: naught101 Date: 2015-08-20 08:42:36 Subject: [PATCH] add some extra tests for row-first columnize --- diff --git a/IPython/utils/tests/test_text.py b/IPython/utils/tests/test_text.py index a528e46..303e23a 100644 --- a/IPython/utils/tests/test_text.py +++ b/IPython/utils/tests/test_text.py @@ -30,44 +30,60 @@ from IPython.utils import text def test_columnize(): """Basic columnize tests.""" size = 5 - items = [l*size for l in 'abc'] + items = [l*size for l in 'abcd'] + out = text.columnize(items, displaywidth=80) - nt.assert_equal(out, 'aaaaa bbbbb ccccc\n') + nt.assert_equal(out, 'aaaaa bbbbb ccccc ddddd\n') + out = text.columnize(items, displaywidth=25) + nt.assert_equal(out, 'aaaaa ccccc\nbbbbb ddddd\n') out = text.columnize(items, displaywidth=12) - nt.assert_equal(out, 'aaaaa ccccc\nbbbbb\n') + nt.assert_equal(out, 'aaaaa ccccc\nbbbbb ddddd\n') out = text.columnize(items, displaywidth=10) - nt.assert_equal(out, 'aaaaa\nbbbbb\nccccc\n') + nt.assert_equal(out, 'aaaaa\nbbbbb\nccccc\nddddd\n') + + out = text.columnize(items, row_first=True, displaywidth=80) + nt.assert_equal(out, 'aaaaa bbbbb ccccc ddddd\n') + out = text.columnize(items, row_first=True, displaywidth=25) + nt.assert_equal(out, 'aaaaa bbbbb\nccccc ddddd\n') + out = text.columnize(items, row_first=True, displaywidth=12) + nt.assert_equal(out, 'aaaaa bbbbb\nccccc ddddd\n') + out = text.columnize(items, row_first=True, displaywidth=10) + nt.assert_equal(out, 'aaaaa\nbbbbb\nccccc\nddddd\n') + def test_columnize_random(): """Test with random input to hopfully catch edge case """ - for nitems in [random.randint(2,70) for i in range(2,20)]: - displaywidth = random.randint(20,200) - rand_len = [random.randint(2,displaywidth) for i in range(nitems)] - items = ['x'*l for l in rand_len] - out = text.columnize(items, displaywidth=displaywidth) - longer_line = max([len(x) for x in out.split('\n')]) - longer_element = max(rand_len) - if longer_line > displaywidth: - print("Columnize displayed something lager than displaywidth : %s " % longer_line) - print("longer element : %s " % longer_element) - print("displaywidth : %s " % displaywidth) - print("number of element : %s " % nitems) - print("size of each element :\n %s" % rand_len) - assert False + for row_first in [True, False]: + for nitems in [random.randint(2,70) for i in range(2,20)]: + displaywidth = random.randint(20,200) + rand_len = [random.randint(2,displaywidth) for i in range(nitems)] + items = ['x'*l for l in rand_len] + out = text.columnize(items, row_first=row_first, displaywidth=displaywidth) + longer_line = max([len(x) for x in out.split('\n')]) + longer_element = max(rand_len) + if longer_line > displaywidth: + print("Columnize displayed something lager than displaywidth : %s " % longer_line) + print("longer element : %s " % longer_element) + print("displaywidth : %s " % displaywidth) + print("number of element : %s " % nitems) + print("size of each element :\n %s" % rand_len) + assert False, "row_first={0}".format(row_first) def test_columnize_medium(): - """Test with inputs than shouldn't be wider tahn 80 """ + """Test with inputs than shouldn't be wider than 80""" size = 40 items = [l*size for l in 'abc'] - out = text.columnize(items, displaywidth=80) - nt.assert_equal(out, '\n'.join(items+[''])) + for row_first in [True, False]: + out = text.columnize(items, row_first=row_first, displaywidth=80) + nt.assert_equal(out, '\n'.join(items+['']), "row_first={0}".format(row_first)) def test_columnize_long(): """Test columnize with inputs longer than the display window""" size = 11 items = [l*size for l in 'abc'] - out = text.columnize(items, displaywidth=size-1) - nt.assert_equal(out, '\n'.join(items+[''])) + for row_first in [True, False]: + out = text.columnize(items, row_first=row_first, displaywidth=size-1) + nt.assert_equal(out, '\n'.join(items+['']), "row_first={0}".format(row_first)) def eval_formatter_check(f): ns = dict(n=12, pi=math.pi, stuff='hello there', os=os, u=u"café", b="café")