Ejemplo n.º 1
0
 def test_tf_analyze_file(self):
     text_formatter = TextFormatter(self.main_dir,
                                    "lorem_different_indents.txt", 4)
     res = text_formatter.analyze_file()
     spaces_len = len(res[0])
     tabs_len = len(res[1])
     self.assertEqual(spaces_len, 11) and self.assertEqual(tabs_len, 10)
Ejemplo n.º 2
0
    def test_tf_print_edited_rows(self):
        text_formatter = TextFormatter(self.main_dir,
                                       "lorem_different_indents.txt", 4)

        with patch('sys.stdout', new=StringIO()) as fakeOutput:
            text_formatter.print_edited_rows([1, 2, 3, 4, 5])
            self.assertEqual(fakeOutput.getvalue().strip(),
                             'The program edited 5 rows')
Ejemplo n.º 3
0
 def test_tf_space_to_tab_1(self):
     text_formatter = TextFormatter(self.main_dir,
                                    "lorem_different_indents.txt", 1)
     text_formatter.space_to_tab()
     edited_file = self.main_dir + "/lorem_different_indents.txt"
     correct_edited_file = os.path.abspath(
         __file__ +
         "/../correct_edited_files/lorem_different_indents_space_to_tab_1.txt"
     )
     self.assertEqual(True, filecmp.cmp(edited_file, correct_edited_file))
Ejemplo n.º 4
0
    def test_tf_print_analyze_file(self):
        text_formatter = TextFormatter(self.main_dir,
                                       "lorem_different_indents.txt", 4)
        res = text_formatter.analyze_file()

        with patch('sys.stdout', new=StringIO()) as fakeOutput:
            text_formatter.print_analyze_file(res[0], res[1])
            x = fakeOutput.getvalue().strip().split("\n")
            self.assertEqual(
                x[0],
                'The program founded 11 spaces in rows:  4, 6, 8, 12, 14, 17, 19, 23, 25, 34, 43, '
            )
            self.assertEqual(
                x[1],
                "The program founded 10 tabs in rows:  2, 10, 16, 21, 26, 28, 30, 32, 37, 41, "
            )
Ejemplo n.º 5
0
 def test_tf_get_all_file_lines(self):
     text_formatter = TextFormatter(self.main_dir,
                                    "lorem_different_indents.txt", 4)
     lines_len = len(text_formatter.lines)
     self.assertEqual(lines_len, 43)
Ejemplo n.º 6
0
    def test_tf_get_empty_space_from_tab_value_1(self):
        text_formatter = TextFormatter(self.main_dir,
                                       "lorem_different_indents_tab_3.txt", 3)
        res = text_formatter.get_empty_space_from_tab_value(1)

        self.assertEqual(res, " ")
    def convert_text(self):

        files_to_format = self.get_file_to_format()
        print("Number of files to edit: " + str(len(files_to_format)))
        print("List of files to edit: " + str(files_to_format))
        self.print_space(50)
        for file in files_to_format:
            if not self.from_:
                text_formatter = TextFormatter(self.path, file, 4)
            else:
                if not self.chars:
                    self.chars = 4
                text_formatter = TextFormatter(self.path, file, self.chars)
            print("I am editing the file: " + str(file))
            if self.from_:
                if not self.replace:
                    file_copier = FileCopier(self.path, file)
                    file_copier.copy_file()

            if self.from_ == FromOptions.SPACES.value:
                text_formatter.space_to_tab()
            elif self.from_ == FromOptions.TABS.value:
                text_formatter.tab_to_space()
            else:
                res = text_formatter.analyze_file()
                text_formatter.print_analyze_file(res[0], res[1])