##// END OF EJS Templates
add some extra tests for row-first columnize
naught101 -
Show More
@@ -30,44 +30,60 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 """
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)
57 71
58 72 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"""
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