##// END OF EJS Templates
add some extra tests for row-first columnize
naught101 -
Show More
@@ -30,21 +30,35 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 """
56 for row_first in [True, False]:
43 for nitems in [random.randint(2,70) for i in range(2,20)]:
57 for nitems in [random.randint(2,70) for i in range(2,20)]:
44 displaywidth = random.randint(20,200)
58 displaywidth = random.randint(20,200)
45 rand_len = [random.randint(2,displaywidth) for i in range(nitems)]
59 rand_len = [random.randint(2,displaywidth) for i in range(nitems)]
46 items = ['x'*l for l in rand_len]
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 longer_line = max([len(x) for x in out.split('\n')])
62 longer_line = max([len(x) for x in out.split('\n')])
49 longer_element = max(rand_len)
63 longer_element = max(rand_len)
50 if longer_line > displaywidth:
64 if longer_line > displaywidth:
@@ -53,21 +67,23 b' def test_columnize_random():'
53 print("displaywidth : %s " % displaywidth)
67 print("displaywidth : %s " % displaywidth)
54 print("number of element : %s " % nitems)
68 print("number of element : %s " % nitems)
55 print("size of each element :\n %s" % rand_len)
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 def test_columnize_medium():
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 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