Ejemplo n.º 1
0
 def test_duplicates_no_exist_dir(self):
     """
     tests reaction on non existing directory
     """
     with self.assertRaises(ValueError) as raised_exception:
         similar_files_finder.duplicates_printer(similar_files_finder.check_for_duplicates('fake'))
     self.assertEqual(raised_exception.exception.args[0],
                      'Directory does non exist')
Ejemplo n.º 2
0
 def test_check_for_duplicates_for_empty_dir(self):
     """
     Verifies the search for duplicates in an empty dir
     :return: None
     """
     with TemporaryDirectory() as temp_dir:
         self.assertDictEqual(similar_files_finder.check_for_duplicates(temp_dir),
                              {}, 'dicts for unique files do not match')
Ejemplo n.º 3
0
 def test_check_for_duplicates_for_unique_files(self):
     """
     Verifies the search for duplicates in a directory
     in which there are no duplicate files
     :return: None
     """
     with TemporaryDirectory() as temp_dir:
         self.create_unique_files(temp_dir)
         self.assertDictEqual(similar_files_finder.check_for_duplicates(temp_dir),
                              {}, 'dicts for unique files do not match')
Ejemplo n.º 4
0
    def test_duplicates_printer_empty_dir(self):
        """
        tests the representation of the dictionary with duplicates,
        if the dictionary is empty
        """

        with patch('sys.stdout', new=StringIO()) as fake_out:
            with TemporaryDirectory() as temp_dir:
                similar_files_finder.duplicates_printer(similar_files_finder.check_for_duplicates(temp_dir))
        self.assertEqual(fake_out.getvalue().strip(),
                         'Duplicates not found!')
Ejemplo n.º 5
0
    def search(self):
        """Starts the same file search."""
        self.model.clear()
        self.model.setHorizontalHeaderLabels([self.tr("")])

        try:
            sim_files = similar_files_finder.check_for_duplicates(self.line_edit_with_buttons.get_text())
        except ValueError as e:
            QtWidgets.QMessageBox.about(self, 'Error!', f'{e}')
        else:
            if not sim_files:
                label = 'Duplicates not found!'
            else:
                label = 'Duplicates:'
            self.model.setHorizontalHeaderLabels([self.tr(label)])
            self.add_items(sim_files)
Ejemplo n.º 6
0
    def test_check_for_duplicates_for_only_non_unique_files(self):
        """
        Verifies the search for duplicates in a directory
        in which there are only duplicate files
        :return: None
        """

        with TemporaryDirectory() as temp_dir:
            non_unique_table = self.create_non_unique_files(temp_dir)
            non_unique_table_set = set((k, tuple(sorted(v)))
                                       for k, v, in non_unique_table.items())
            result_set = set((k, tuple(sorted(v)))
                             for k, v, in
                             similar_files_finder.check_for_duplicates(temp_dir).items())

            self.assertSetEqual(non_unique_table_set, result_set,
                                'dicts for unique files do not match')
Ejemplo n.º 7
0
    def test_duplicates_printer_unique_files(self):
        """
        tests the representation of the dictionary with duplicates,
        if the dictionary is non-empty
        """

        with patch('sys.stdout', new=StringIO()) as fake_out:
            with TemporaryDirectory() as temp_dir:
                file_path1 = os.path.join(temp_dir, '1')
                create_file_with_content(file_path1, 'hello')

                subdir = os.path.join(temp_dir, 'subdir')
                os.makedirs(subdir)
                file_path2 = os.path.join(subdir, '1')
                create_file_with_content(file_path2, 'hello')

                similar_files_finder.duplicates_printer(similar_files_finder.check_for_duplicates(temp_dir))
                output = 'Duplicates found:\n---\nWith hash 5d41402abc4b2a76b9719d911017c592\n'
                output += file_path1 + '\n'
                output += file_path2
            self.assertEqual(fake_out.getvalue().strip(), output)