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