def make_config() -> Union[AwsConfig, GcpConfig]: config = load_yaml_from_file(NIMBO_CONFIG_FILE) # Provider field validation is postponed. If cloud_provider is not specified, # assume AwsConfig for running commands like --help and generate-config. if "cloud_provider" not in config: return AwsConfig(**config) else: config["cloud_provider"] = config["cloud_provider"].upper() try: cloud_provider = CloudProvider(config["cloud_provider"]) except ValueError: permitted_values = ", ".join([f"'{p.value}'" for p in CloudProvider]) raise pydantic.ValidationError( [ pydantic.error_wrappers.ErrorWrapper( Exception( f"value is not a valid enumeration member; permitted: " f"{permitted_values}" ), "cloud_provider", ) ], AwsConfig, ) if cloud_provider == CloudProvider.AWS: return AwsConfig(**config) return GcpConfig(**config)
def _validate_pinned_values_cannot_be_changed(self, new_value) -> None: if not self.pinned or self.value is None: return if new_value != self.value: error = ValueError( f"value of pinned settings cannot be changed: assigned value {repr(new_value)} is not equal to existing value {repr(self.value)}" ) error_ = pydantic.error_wrappers.ErrorWrapper(error, loc="value") raise pydantic.ValidationError([error_], self.__class__)
def parse_base_config(cls, v): if isinstance(v, dict): try: return train.Configuration(**v) except pydantic.error_wrappers.ValidationError as e: logger.info(str(e)) if 'defaults' in str(e): raise pydantic.ValidationError( f'{e}. Configuration field `defaults` from the training ' 'config is not supported in the search config. Either specify ' 'the data fields in the regular way, or put the config in ' 'a separate file and point to the path.') else: return Path(v)
def test_create_response_body_converter_invalid_response( self, mocker, pydantic_model_mock): data = {"quick": "fox"} _, model = pydantic_model_mock parse_obj_mock = mocker.patch.object( model, "parse_obj", side_effect=pydantic.ValidationError([], model)) converter = converters.PydanticConverter() c = converter.create_response_body_converter(model) with pytest.raises(pydantic.ValidationError): c.convert(data) parse_obj_mock.assert_called_once_with(data)
def w(cls, *args, **kwargs): try: return f(cls, *args, **kwargs) except (TypeError, ValueError, AssertionError) as exc: raise pydantic.ValidationError([ErrorWrapper(exc, loc)], cls)
def all_zones_available(cls, v): count_not_in_keys = [count not in v.keys() for count in range(0, 12)] if sum(count_not_in_keys) > 0: raise pydantic.ValidationError( "Values for some packing counts are missing.") return v