コード例 #1
0
ファイル: data_source.py プロジェクト: joaovitor123jv/rontext
    def update_file_map(self, full_paths):
        self.map = {}
        duplicates = None
        if has_duplicates(full_paths):
            duplicates = get_duplicates(full_paths)

        for full_path in full_paths:
            full_path_str = str(full_path[0])
            if duplicates != None:
                if full_path_str in duplicates:
                    self.map[full_path_str.replace('/', '|')] = full_path_str
                else:
                    keys = full_path_str.split("/")
                    last_key = keys[
                        len(keys) -
                        1]  # Separate file name "/home/user/Documents/test" -> "test"
                    self.map[
                        last_key] = full_path_str  # Stores an 'object' with the filename as key and full_path as value
            else:
                keys = full_path_str.split("/")
                last_key = keys[
                    len(keys) -
                    1]  # Separate file name "/home/user/Documents/test" -> "test"
                self.map[
                    last_key] = full_path_str  # Stores an 'object' with the filename as key and full_path as value
コード例 #2
0
    def validate_image_directories(self, directories):
        """Carry out validation checks on the given image directories.

        :param directories: Directory paths for all content types.
        :type directories: dict
        """
        if not isinstance(directories, dict):
            sys.exit("Given directories must be an instance of a dictionary.")

        exit_msg = ""

        for content_type in ContentType:
            if directories.get(content_type.value):
                all_image_file_names = self.get_image_file_names(
                    directories, content_type.value)
                duplicate_file_names = get_duplicates(all_image_file_names)

                if duplicate_file_names:
                    exit_msg += (
                        f"Duplicate file names detected in directory for content type '{content_type.value}'. They "
                        f"are: {', '.join(duplicate_file_names)}.\n")

            else:
                exit_msg += f"No directory found for content type '{content_type.value}' within given directories.\n"

        if exit_msg:
            sys.exit(exit_msg)
コード例 #3
0
 def test_no_duplicates(self):
     assert get_duplicates([1, 2, 3, 4]) == []
コード例 #4
0
 def test_empty_list(self):
     assert get_duplicates([]) == []
コード例 #5
0
 def test_multiple_duplicate_of_two_values(self):
     assert get_duplicates([1, 1, 1, 2, 2, 2, 2, 3, 4]) == [1, 1, 2, 2, 2]
コード例 #6
0
 def test_one_duplicate_of_two_values(self):
     assert get_duplicates([1, 2, 2, 3, 3, 4]) == [2, 3]
コード例 #7
0
 def test_multiple_duplicates_of_one_value(self):
     assert get_duplicates([1, 2, 3, 4, 4, 4, 4]) == [4, 4, 4]
コード例 #8
0
 def test_one_duplicate_of_one_value(self):
     assert get_duplicates([1, 1, 2, 3, 4]) == [1]