Coverage for mockslurm/utils.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2024-11-21 00:38 +0000

1import argparse 

2 

3from mockslurm.process_db import DB_DEFAULTS 

4 

5 

6def filter_dict_from_args(args: argparse.Namespace): 

7 # Transform the arguments values into a map {field: value, field2: [values], etc...} for filtering DB 

8 field_filter_values = {} 

9 for arg, value in vars(args).items(): 

10 if arg in DB_DEFAULTS.keys(): 

11 if isinstance(value, str): 

12 field_filter_values[arg] = value.encode() 

13 elif isinstance(value, list): 

14 field_filter_values[arg] = [v.encode() if isinstance(v, str) else v for v in value] 

15 elif value is not None: 

16 field_filter_values[arg] = value 

17 

18 return field_filter_values