Show More
@@ -77,6 +77,7 b' def test_spaces():' | |||
|
77 | 77 | ('\tx', 1), |
|
78 | 78 | ('\t x', 2), |
|
79 | 79 | ] |
|
80 | with pytest.warns(PendingDeprecationWarning): | |
|
80 | 81 | tt.check_pairs(isp.num_ini_spaces, tests) |
|
81 | 82 | |
|
82 | 83 |
@@ -26,37 +26,93 b' from IPython.utils import text' | |||
|
26 | 26 | # Globals |
|
27 | 27 | #----------------------------------------------------------------------------- |
|
28 | 28 | |
|
29 | def test_columnize(): | |
|
29 | ||
|
30 | @pytest.mark.parametrize( | |
|
31 | "expected, width, row_first, spread", | |
|
32 | ( | |
|
33 | ( | |
|
34 | "aaaaa bbbbb ccccc ddddd\n", | |
|
35 | 80, | |
|
36 | False, | |
|
37 | False, | |
|
38 | ), | |
|
39 | ( | |
|
40 | "aaaaa ccccc\nbbbbb ddddd\n", | |
|
41 | 25, | |
|
42 | False, | |
|
43 | False, | |
|
44 | ), | |
|
45 | ( | |
|
46 | "aaaaa ccccc\nbbbbb ddddd\n", | |
|
47 | 12, | |
|
48 | False, | |
|
49 | False, | |
|
50 | ), | |
|
51 | ( | |
|
52 | "aaaaa\nbbbbb\nccccc\nddddd\n", | |
|
53 | 10, | |
|
54 | False, | |
|
55 | False, | |
|
56 | ), | |
|
57 | ( | |
|
58 | "aaaaa bbbbb ccccc ddddd\n", | |
|
59 | 80, | |
|
60 | True, | |
|
61 | False, | |
|
62 | ), | |
|
63 | ( | |
|
64 | "aaaaa bbbbb\nccccc ddddd\n", | |
|
65 | 25, | |
|
66 | True, | |
|
67 | False, | |
|
68 | ), | |
|
69 | ( | |
|
70 | "aaaaa bbbbb\nccccc ddddd\n", | |
|
71 | 12, | |
|
72 | True, | |
|
73 | False, | |
|
74 | ), | |
|
75 | ( | |
|
76 | "aaaaa\nbbbbb\nccccc\nddddd\n", | |
|
77 | 10, | |
|
78 | True, | |
|
79 | False, | |
|
80 | ), | |
|
81 | ( | |
|
82 | "aaaaa bbbbb ccccc ddddd\n", | |
|
83 | 40, | |
|
84 | False, | |
|
85 | True, | |
|
86 | ), | |
|
87 | ( | |
|
88 | "aaaaa ccccc\nbbbbb ddddd\n", | |
|
89 | 20, | |
|
90 | False, | |
|
91 | True, | |
|
92 | ), | |
|
93 | ( | |
|
94 | "aaaaa ccccc\nbbbbb ddddd\n", | |
|
95 | 12, | |
|
96 | False, | |
|
97 | True, | |
|
98 | ), | |
|
99 | ( | |
|
100 | "aaaaa\nbbbbb\nccccc\nddddd\n", | |
|
101 | 10, | |
|
102 | False, | |
|
103 | True, | |
|
104 | ), | |
|
105 | ), | |
|
106 | ) | |
|
107 | def test_columnize(expected, width, row_first, spread): | |
|
30 | 108 | """Basic columnize tests.""" |
|
31 | 109 | size = 5 |
|
32 | 110 | items = [l*size for l in 'abcd'] |
|
33 | ||
|
34 |
out = text.columnize( |
|
|
35 | assert out == "aaaaa bbbbb ccccc ddddd\n" | |
|
36 | out = text.columnize(items, displaywidth=25) | |
|
37 | assert out == "aaaaa ccccc\nbbbbb ddddd\n" | |
|
38 | out = text.columnize(items, displaywidth=12) | |
|
39 | assert out == "aaaaa ccccc\nbbbbb ddddd\n" | |
|
40 | out = text.columnize(items, displaywidth=10) | |
|
41 | assert out == "aaaaa\nbbbbb\nccccc\nddddd\n" | |
|
42 | ||
|
43 | out = text.columnize(items, row_first=True, displaywidth=80) | |
|
44 | assert out == "aaaaa bbbbb ccccc ddddd\n" | |
|
45 | out = text.columnize(items, row_first=True, displaywidth=25) | |
|
46 | assert out == "aaaaa bbbbb\nccccc ddddd\n" | |
|
47 | out = text.columnize(items, row_first=True, displaywidth=12) | |
|
48 | assert out == "aaaaa bbbbb\nccccc ddddd\n" | |
|
49 | out = text.columnize(items, row_first=True, displaywidth=10) | |
|
50 | assert out == "aaaaa\nbbbbb\nccccc\nddddd\n" | |
|
51 | ||
|
52 | out = text.columnize(items, displaywidth=40, spread=True) | |
|
53 | assert out == "aaaaa bbbbb ccccc ddddd\n" | |
|
54 | out = text.columnize(items, displaywidth=20, spread=True) | |
|
55 | assert out == "aaaaa ccccc\nbbbbb ddddd\n" | |
|
56 | out = text.columnize(items, displaywidth=12, spread=True) | |
|
57 | assert out == "aaaaa ccccc\nbbbbb ddddd\n" | |
|
58 | out = text.columnize(items, displaywidth=10, spread=True) | |
|
59 | assert out == "aaaaa\nbbbbb\nccccc\nddddd\n" | |
|
111 | with pytest.warns(PendingDeprecationWarning): | |
|
112 | out = text.columnize( | |
|
113 | items, displaywidth=width, row_first=row_first, spread=spread | |
|
114 | ) | |
|
115 | assert out == expected | |
|
60 | 116 | |
|
61 | 117 | |
|
62 | 118 | def test_columnize_random(): |
@@ -66,8 +122,11 b' def test_columnize_random():' | |||
|
66 | 122 | displaywidth = random.randint(20,200) |
|
67 | 123 | rand_len = [random.randint(2,displaywidth) for i in range(nitems)] |
|
68 | 124 | items = ['x'*l for l in rand_len] |
|
69 | out = text.columnize(items, row_first=row_first, displaywidth=displaywidth) | |
|
70 | longer_line = max([len(x) for x in out.split('\n')]) | |
|
125 | with pytest.warns(PendingDeprecationWarning): | |
|
126 | out = text.columnize( | |
|
127 | items, row_first=row_first, displaywidth=displaywidth | |
|
128 | ) | |
|
129 | longer_line = max([len(x) for x in out.split("\n")]) | |
|
71 | 130 | longer_element = max(rand_len) |
|
72 | 131 | assert longer_line <= displaywidth, ( |
|
73 | 132 | f"Columnize displayed something lager than displaywidth : {longer_line}\n" |
@@ -84,6 +143,7 b' def test_columnize_medium(row_first):' | |||
|
84 | 143 | """Test with inputs than shouldn't be wider than 80""" |
|
85 | 144 | size = 40 |
|
86 | 145 | items = [l*size for l in 'abc'] |
|
146 | with pytest.warns(PendingDeprecationWarning): | |
|
87 | 147 | out = text.columnize(items, row_first=row_first, displaywidth=80) |
|
88 | 148 | assert out == "\n".join(items + [""]), "row_first={0}".format(row_first) |
|
89 | 149 | |
@@ -93,6 +153,7 b' def test_columnize_long(row_first):' | |||
|
93 | 153 | """Test columnize with inputs longer than the display window""" |
|
94 | 154 | size = 11 |
|
95 | 155 | items = [l*size for l in 'abc'] |
|
156 | with pytest.warns(PendingDeprecationWarning): | |
|
96 | 157 | out = text.columnize(items, row_first=row_first, displaywidth=size - 1) |
|
97 | 158 | assert out == "\n".join(items + [""]), "row_first={0}".format(row_first) |
|
98 | 159 |
General Comments 0
You need to be logged in to leave comments.
Login now