def _validate_storage_map_list(options_list, id_provider, force_options): kwargs = validate.set_warning(report_codes.FORCE_OPTIONS, force_options) option_type = "storage-map" validators = [ validate.NamesIn(STORAGE_MAP_OPTIONS, option_type=option_type, **kwargs), validate.ValueId( "id", option_name_for_report="storage-map id", id_provider=id_provider, ), validate.IsRequiredSome( ["source-dir", "source-dir-root"], option_type=option_type, ), validate.MutuallyExclusive( ["source-dir", "source-dir-root"], option_type=option_type, ), validate.IsRequiredAll(["target-dir"], option_type=option_type), ] validator_all = validate.ValidatorAll(validators) report_list = [] for options in options_list: report_list.extend(validator_all.validate(options)) return report_list
def _validate_port_map_list(options_list, id_provider, force_options): kwargs = validate.set_warning(report_codes.FORCE_OPTIONS, force_options) option_type = "port-map" validators = [ validate.NamesIn(PORT_MAP_OPTIONS, option_type=option_type, **kwargs), validate.ValueId("id", option_name_for_report="port-map id", id_provider=id_provider), validate.DependsOnOption( ["internal-port"], "port", option_type=option_type, prerequisite_type=option_type, ), validate.IsRequiredSome(["port", "range"], option_type=option_type), validate.MutuallyExclusive(["port", "range"], option_type=option_type), validate.ValuePortNumber("port"), validate.ValuePortNumber("internal-port"), validate.ValuePortRange("range", **kwargs), ] validator_all = validate.ValidatorAll(validators) report_list = [] for options in options_list: report_list.extend(validator_all.validate(options)) return report_list
def test_returns_no_report_when_second_is_present(self): assert_report_item_list_equal( validate.IsRequiredSome(["first", "second"], "type").validate( {"second": "value"} ), [], )
def test_returns_report_when_missing(self): assert_report_item_list_equal( validate.IsRequiredSome(["first", "second"], "type").validate({"third": "value"}), [ fixture.error( report_codes.REQUIRED_OPTION_OF_ALTERNATIVES_IS_MISSING, option_names=["first", "second"], option_type="type", ), ])
def get_validators_required_parameters( self, force: bool = False, only_parameters: Optional[Iterable[str]] = None, ) -> List[validate.ValidatorInterface]: """ Return validators checking if required parameters were specified force -- if True, validators produce a warning instead of an error only_parameters -- if set, only specified parameters are checked """ validators: List[validate.ValidatorInterface] = [] severity = reports.item.get_severity(reports.codes.FORCE, force) only_parameters = only_parameters or set() required_not_obsoleting: Set[str] = set() all_params_deprecated_by = self._get_all_params_deprecated_by() for param in self.metadata.parameters: if not param.required or param.deprecated: continue deprecated_by_param = all_params_deprecated_by[param.name] if only_parameters and not ({param.name} | deprecated_by_param ).intersection(only_parameters): continue if deprecated_by_param: validators.append( validate.IsRequiredSome( {param.name} | deprecated_by_param, self._validator_option_type, deprecated_option_name_list=deprecated_by_param, severity=severity, )) else: required_not_obsoleting.add(param.name) if required_not_obsoleting: validators.append( validate.IsRequiredAll( required_not_obsoleting, self._validator_option_type, severity, )) return validators