Coverage for biobb_dna/utils/common.py: 60%
10 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-28 10:36 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-28 10:36 +0000
1from typing import Optional, Union
4# TODO: Move this function to biobb_common.tools.file_utils
5def _from_string_to_list(input_data: Optional[Union[str, list[str]]]) -> list[str]:
6 """
7 Converts a string to a list, splitting by commas or spaces. If the input is already a list, returns it as is.
8 Returns an empty list if input_data is None.
10 Parameters:
11 input_data (str, list, or None): The string, list, or None value to convert.
13 Returns:
14 list: A list of string elements or an empty list if input_data is None.
15 """
16 if input_data is None:
17 return []
19 if isinstance(input_data, list):
20 # If input is already a list, return it
21 return input_data
23 # If input is a string, determine the delimiter based on presence of commas
24 delimiter = "," if "," in input_data else " "
25 items = input_data.split(delimiter)
27 # Remove whitespace from each item and ignore empty strings
28 processed_items = [item.strip() for item in items if item.strip()]
30 return processed_items