Validate mutually exclusive groups in the parsed args.
(parsed_args, *groups)
| 97 | |
| 98 | |
| 99 | def validate_mutually_exclusive(parsed_args, *groups): |
| 100 | """Validate mutually exclusive groups in the parsed args.""" |
| 101 | args_dict = vars(parsed_args) |
| 102 | all_args = set(arg for group in groups for arg in group) |
| 103 | if not any(k in all_args for k in args_dict if args_dict[k] is not None): |
| 104 | # If none of the specified args are in a mutually exclusive group |
| 105 | # there is nothing left to validate. |
| 106 | return |
| 107 | current_group = None |
| 108 | for key in [k for k in args_dict if args_dict[k] is not None]: |
| 109 | key_group = _get_group_for_key(key, groups) |
| 110 | if key_group is None: |
| 111 | # If they key is not part of a mutex group, we can move on. |
| 112 | continue |
| 113 | if current_group is None: |
| 114 | current_group = key_group |
| 115 | elif not key_group == current_group: |
| 116 | raise ParamValidationError( |
| 117 | 'The key "%s" cannot be specified when one ' |
| 118 | 'of the following keys are also specified: ' |
| 119 | '%s' % (key, ', '.join(current_group)) |
| 120 | ) |
| 121 | |
| 122 | |
| 123 | def _get_group_for_key(key, groups): |
no test coverage detected