Show More
@@ -30,21 +30,35 b' from IPython.utils import text' | |||
|
30 | 30 | def test_columnize(): |
|
31 | 31 | """Basic columnize tests.""" |
|
32 | 32 | size = 5 |
|
33 | items = [l*size for l in 'abc'] | |
|
33 | items = [l*size for l in 'abcd'] | |
|
34 | ||
|
34 | 35 | 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') | |
|
36 | 39 | 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') | |
|
38 | 41 | 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 | ||
|
40 | 53 | |
|
41 | 54 | def test_columnize_random(): |
|
42 | 55 | """Test with random input to hopfully catch edge case """ |
|
56 | for row_first in [True, False]: | |
|
43 | 57 | for nitems in [random.randint(2,70) for i in range(2,20)]: |
|
44 | 58 | displaywidth = random.randint(20,200) |
|
45 | 59 | rand_len = [random.randint(2,displaywidth) for i in range(nitems)] |
|
46 | 60 | items = ['x'*l for l in rand_len] |
|
47 | out = text.columnize(items, displaywidth=displaywidth) | |
|
61 | out = text.columnize(items, row_first=row_first, displaywidth=displaywidth) | |
|
48 | 62 | longer_line = max([len(x) for x in out.split('\n')]) |
|
49 | 63 | longer_element = max(rand_len) |
|
50 | 64 | if longer_line > displaywidth: |
@@ -53,21 +67,23 b' def test_columnize_random():' | |||
|
53 | 67 | print("displaywidth : %s " % displaywidth) |
|
54 | 68 | print("number of element : %s " % nitems) |
|
55 | 69 | print("size of each element :\n %s" % rand_len) |
|
56 | assert False | |
|
70 | assert False, "row_first={0}".format(row_first) | |
|
57 | 71 | |
|
58 | 72 | def test_columnize_medium(): |
|
59 |
"""Test with inputs than shouldn't be wider t |
|
|
73 | """Test with inputs than shouldn't be wider than 80""" | |
|
60 | 74 | size = 40 |
|
61 | 75 | 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)) | |
|
64 | 79 | |
|
65 | 80 | def test_columnize_long(): |
|
66 | 81 | """Test columnize with inputs longer than the display window""" |
|
67 | 82 | size = 11 |
|
68 | 83 | 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)) | |
|
71 | 87 | |
|
72 | 88 | def eval_formatter_check(f): |
|
73 | 89 | ns = dict(n=12, pi=math.pi, stuff='hello there', os=os, u=u"café", b="café") |
General Comments 0
You need to be logged in to leave comments.
Login now