def test_ok_one_word_whitespace(self): input_string = 'Требуется:' expect_string = ' Требуется:' str_len = len(input_string) + 3 formatter = Formatter(str_len=str_len) out_str = formatter._white_space_extend(input_string.split()) self.assertEqual(out_str, expect_string)
def test_ok_format_to_10_chars_str_len(self): formatter = Formatter(str_len=10, input_file_name=self.input_file, output_file_name=self.output_file_name) formatter.format_text() out_form_file = open(self.output_file_name) formatted_text = out_form_file.read() expected_text = \ """1 задание. Дано: произвольн ый текстовый файл и ограничени е по ширине страницы (указано кол-во символов). Требуется: создать""" self.assertEqual(formatted_text, expected_text)
def test_ok_cut_non_round_word(self): word = 'машиностроительный' expected_array = ['маши', 'ност', 'роит', 'ельн', 'ый'] str_len = 4 formatter = Formatter(str_len) sliced_word = formatter._word_cutter(word) self.assertEqual(len(expected_array), len(sliced_word)) self.assertListEqual(sliced_word, expected_array)
def test_ok_cut_round_word(self): word = 'список' expected_array = ['спи', 'сок'] str_len = 3 formatter = Formatter(str_len) sliced_word = formatter._word_cutter(word) self.assertEqual(len(expected_array), len(sliced_word)) self.assertListEqual(sliced_word, expected_array)
class TestSpaceExpected(unittest.TestCase): def setUp(self): self.formatter = Formatter(30) def test_ok_test_cout_exp_space(self): out_string_words = ['one', 'two', 'three'] word = 'four' expected_string = 'one two three four' expected_string_length = self.formatter._count_expected_space( out_string_words, word) self.assertEqual(expected_string_length, len(expected_string))
def test_ok_no_add_whitespace(self): expect_string = 'Требуется: создать отформатированный текстовый файл,' str_len = len(self.input_string) formatter = Formatter(str_len=str_len) out_str = formatter._white_space_extend(self.input_string.split()) self.assertEqual(out_str, expect_string)
def setUp(self): self.formatter = Formatter(30)