Test with random input to hopefully catch edge case
()
| 60 | |
| 61 | |
| 62 | def test_columnize_random(): |
| 63 | """Test with random input to hopefully catch edge case """ |
| 64 | for row_first in [True, False]: |
| 65 | for nitems in [random.randint(2,70) for i in range(2,20)]: |
| 66 | displaywidth = random.randint(20,200) |
| 67 | rand_len = [random.randint(2,displaywidth) for i in range(nitems)] |
| 68 | 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')]) |
| 71 | longer_element = max(rand_len) |
| 72 | if longer_line > displaywidth: |
| 73 | print("Columnize displayed something lager than displaywidth : %s " % longer_line) |
| 74 | print("longer element : %s " % longer_element) |
| 75 | print("displaywidth : %s " % displaywidth) |
| 76 | print("number of element : %s " % nitems) |
| 77 | print("size of each element :\n %s" % rand_len) |
| 78 | assert False, "row_first={0}".format(row_first) |
| 79 | |
| 80 | def test_columnize_medium(): |
| 81 | """Test with inputs than shouldn't be wider than 80""" |