Ejemplo n.º 1
0
 def test_many_calls(self):
     '''Tests that the code work for any max line length between 0 and 100.'''
     n = 100
     for i in range(n):
         with self.subTest(i):
             output = word_wrap_text(self.input,
                                     max_line_len=i,
                                     justify=False)
             self.assertGreater(len(output), 0)
         with self.subTest(n + i):
             output = word_wrap_text(self.input,
                                     max_line_len=i,
                                     justify=False)
             self.assertGreater(len(output), 0)
Ejemplo n.º 2
0
    def test_lorem_sample_part3(self):
        '''Tests that the part 3 of the lorem-ipsum sample performs correctly.
        That means, test if using values of max line length equal to 0 or 1
        will always break the text to have one word per line.
        '''

        for i in range(2):
            with self.subTest(i):
                output = word_wrap_text(self.lorem,
                                        max_line_len=i,
                                        justify=False)
                self.assertEqual(output, self.lorem_output3)
            with self.subTest(2 + i):
                output = word_wrap_text(self.lorem,
                                        max_line_len=i,
                                        justify=True)
                self.assertEqual(output, self.lorem_output3)
Ejemplo n.º 3
0
from stringutils import word_wrap_text

with open('input.txt', mode='r', encoding='utf-8') as file:
    _input = file.read()

max_len = 80
print(f'Quebra em {max_len} colunas sem justificar:')
print('-' * max_len)
_output = word_wrap_text(_input, max_line_len=max_len, justify=False)
print(_output)
print('-' * max_len)

print('')

print(f'Quebra em {max_len} colunas justificando:')
print('-' * max_len)
_output = word_wrap_text(_input, max_line_len=max_len, justify=True)
print(_output)
print('-' * max_len)
Ejemplo n.º 4
0
    def test_lorem_sample_part2(self):
        '''Tests that the part 2 of the lorem-ipsum sample performs correctly.'''

        output = word_wrap_text(self.lorem, max_line_len=80, justify=True)
        self.assertEqual(output, self.lorem_output2)
Ejemplo n.º 5
0
    def test_input_sample_part2(self):
        '''Tests that the part 2 of the sample test performs correctly.'''

        output = word_wrap_text(self.input, justify=True)
        self.assertEqual(output, self.output_part2)
Ejemplo n.º 6
0
    def test_empty_string(self):
        '''Tests that empty strings are unchanged.'''

        output = word_wrap_text('')
        self.assertEqual(output, '')