Beispiel #1
0
    def test_limit_with_40_chars_and_justify_sample4(self):
        # test parameter
        maxchars = 40
        # get fixtures
        sample = 'sample4.txt'
        file = open(self.fixtures_base + sample, 'r')
        text = file.read()
        # running service

        service = TextFormatter(text=text)
        result = service.limiter_and_justify(line_size_chars=maxchars)

        # assert size of each line
        all_lines = result.split(TextFormatter.BREAK_LINE)
        for line in all_lines:
            if line != TextFormatter.BREAK_PARAGRAPH:
                length_of_line = len(line)
                if length_of_line > 0:
                    self.assertTrue(len(line) == maxchars)
Beispiel #2
0
    def test_limit_with_80_chars_sample4(self):
        # test parameter
        maxchars = 80
        # get fixtures
        sample = 'sample4.txt'
        file = open(self.fixtures_base + sample, 'r')
        text = file.read()
        # running service
        service = TextFormatter(text=text)
        result = service.limiter(line_size_chars=maxchars)

        # assert result size
        total_of_source_words = self.count_words(text=text)
        total_of_result_words = self.count_words(text=result)
        self.assertEqual(total_of_source_words, total_of_result_words)
        # assert size of each line
        splited = result.split(TextFormatter.BREAK_LINE)
        for line in splited:
            self.assertTrue(len(line) <= maxchars)
Beispiel #3
0
 def test_justify_alignment(self):
     # test parameter
     maxchars = 40
     text = 'and the earth. Now the earth was'
     # running service
     service = TextFormatter(text=text)
     result = service.justify_text_line(text=text, line_size_chars=maxchars)
     self.assertEqual(maxchars, len(result))
     text = '"day," and the darkness he called'
     service = TextFormatter(text=text)
     result = service.justify_text_line(text=text, line_size_chars=maxchars)
     self.assertEqual(maxchars, len(result))