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

Skip to content

Commit 19e214e

Browse files
committed
add some extra tests for row-first columnize
1 parent 6b3ae1b commit 19e214e

File tree

1 file changed

+39
-23
lines changed

1 file changed

+39
-23
lines changed

IPython/utils/tests/test_text.py

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,44 +30,60 @@
3030
def test_columnize():
3131
"""Basic columnize tests."""
3232
size = 5
33-
items = [l*size for l in 'abc']
33+
items = [l*size for l in 'abcd']
34+
3435
out = text.columnize(items, displaywidth=80)
35-
nt.assert_equal(out, 'aaaaa bbbbb ccccc\n')
36+
nt.assert_equal(out, 'aaaaa bbbbb ccccc ddddd\n')
37+
out = text.columnize(items, displaywidth=25)
38+
nt.assert_equal(out, 'aaaaa ccccc\nbbbbb ddddd\n')
3639
out = text.columnize(items, displaywidth=12)
37-
nt.assert_equal(out, 'aaaaa ccccc\nbbbbb\n')
40+
nt.assert_equal(out, 'aaaaa ccccc\nbbbbb ddddd\n')
3841
out = text.columnize(items, displaywidth=10)
39-
nt.assert_equal(out, 'aaaaa\nbbbbb\nccccc\n')
42+
nt.assert_equal(out, 'aaaaa\nbbbbb\nccccc\nddddd\n')
43+
44+
out = text.columnize(items, row_first=True, displaywidth=80)
45+
nt.assert_equal(out, 'aaaaa bbbbb ccccc ddddd\n')
46+
out = text.columnize(items, row_first=True, displaywidth=25)
47+
nt.assert_equal(out, 'aaaaa bbbbb\nccccc ddddd\n')
48+
out = text.columnize(items, row_first=True, displaywidth=12)
49+
nt.assert_equal(out, 'aaaaa bbbbb\nccccc ddddd\n')
50+
out = text.columnize(items, row_first=True, displaywidth=10)
51+
nt.assert_equal(out, 'aaaaa\nbbbbb\nccccc\nddddd\n')
52+
4053

4154
def test_columnize_random():
4255
"""Test with random input to hopfully catch edge case """
43-
for nitems in [random.randint(2,70) for i in range(2,20)]:
44-
displaywidth = random.randint(20,200)
45-
rand_len = [random.randint(2,displaywidth) for i in range(nitems)]
46-
items = ['x'*l for l in rand_len]
47-
out = text.columnize(items, displaywidth=displaywidth)
48-
longer_line = max([len(x) for x in out.split('\n')])
49-
longer_element = max(rand_len)
50-
if longer_line > displaywidth:
51-
print("Columnize displayed something lager than displaywidth : %s " % longer_line)
52-
print("longer element : %s " % longer_element)
53-
print("displaywidth : %s " % displaywidth)
54-
print("number of element : %s " % nitems)
55-
print("size of each element :\n %s" % rand_len)
56-
assert False
56+
for row_first in [True, False]:
57+
for nitems in [random.randint(2,70) for i in range(2,20)]:
58+
displaywidth = random.randint(20,200)
59+
rand_len = [random.randint(2,displaywidth) for i in range(nitems)]
60+
items = ['x'*l for l in rand_len]
61+
out = text.columnize(items, row_first=row_first, displaywidth=displaywidth)
62+
longer_line = max([len(x) for x in out.split('\n')])
63+
longer_element = max(rand_len)
64+
if longer_line > displaywidth:
65+
print("Columnize displayed something lager than displaywidth : %s " % longer_line)
66+
print("longer element : %s " % longer_element)
67+
print("displaywidth : %s " % displaywidth)
68+
print("number of element : %s " % nitems)
69+
print("size of each element :\n %s" % rand_len)
70+
assert False, "row_first={0}".format(row_first)
5771

5872
def test_columnize_medium():
59-
"""Test with inputs than shouldn't be wider tahn 80 """
73+
"""Test with inputs than shouldn't be wider than 80"""
6074
size = 40
6175
items = [l*size for l in 'abc']
62-
out = text.columnize(items, displaywidth=80)
63-
nt.assert_equal(out, '\n'.join(items+['']))
76+
for row_first in [True, False]:
77+
out = text.columnize(items, row_first=row_first, displaywidth=80)
78+
nt.assert_equal(out, '\n'.join(items+['']), "row_first={0}".format(row_first))
6479

6580
def test_columnize_long():
6681
"""Test columnize with inputs longer than the display window"""
6782
size = 11
6883
items = [l*size for l in 'abc']
69-
out = text.columnize(items, displaywidth=size-1)
70-
nt.assert_equal(out, '\n'.join(items+['']))
84+
for row_first in [True, False]:
85+
out = text.columnize(items, row_first=row_first, displaywidth=size-1)
86+
nt.assert_equal(out, '\n'.join(items+['']), "row_first={0}".format(row_first))
7187

7288
def eval_formatter_check(f):
7389
ns = dict(n=12, pi=math.pi, stuff='hello there', os=os, u=u"café", b="café")

0 commit comments

Comments
 (0)