def test_center_padding(text, width): padded = humanreadable.pad_text(text, width, align='center') print('---1---') print(text) print('---2---') print(padded) print('-------') for original, changed in zip(text.split('\n'), padded.split('\n')): if not changed.strip(): assert len(changed) == width continue # Count the padding to the left of the line left_space = len(changed) - len(changed.lstrip(' ')) left_space -= len(original) - len(original.lstrip(' ')) # and the padding to the right_pad of the line right_space = len(changed) - len(changed.rstrip(' ')) assert abs(left_space - right_space) <= 1
def test_right_padding(text, width): padded = humanreadable.pad_text(text, width, align='right') print('---1---') print(text) print('---2---') print(padded) print('-------') spaces = [] for original, changed in zip(text.split('\n'), padded.split('\n')): if not original.strip(): assert len(changed) == width continue # Count the padding that was added to the right of the line right_space = len(changed) - len(changed.rstrip()) spaces.append(right_space) # Assert that all items are equal if spaces: assert spaces.count(spaces[0]) == len(spaces)
def tokenize(self, text): return text.split()