def is_valid_float(self, n): # print(type(n)) # if type(n) == str: # raise exceptions.ValidationError("Not a valid float.") if n < 0.01 or n > 50: raise exceptions.ValidationError("Value out of range.") if len(str(n)) > 5: raise exceptions.ValidationError("Allowed no more than two digits after decimal point.")
def validate_auth_info(self, data): key_file = data.get('key_file') username = data.get('username') if key_file and username: raise exceptions.ValidationError( 'a "key_file" or a "username" and "password" must be specified', ) if key_file or username: return raise exceptions.ValidationError( 'a "key_file" or a "username" and "password" must be specified', )
def add_coo_data(self, data, **kwargs): """Convert ROIs to coo format, which is used by the croissant FeatureExtractor. Input includes 'x' and 'y' fields which designate the cartesian coordinates of the top right corner, the width and height of the bounding box, and boolean values for whether the mask pixel is contained. The returned coo_matrix will contain all the data in the mask in the proper shape, but essentially discards the 'x' and 'y' information (the cartesian position of the masks is not important for the below methods). Represented as a dense array, the mask data would be "cropped" to the bounding box. Note: If the methods were updated such that the position of the mask relative to the input data *were* important (say, if necessary to align the masks to the movie from which they were created), then this function would require the dimensions of the source movie. """ shape = (data["height"], data["width"]) arr = np.array(data["mask_matrix"]).astype("int") if data["height"] + data["width"] == 0: warnings.warn("Input data contains empty ROI. " "This may cause problems.") elif arr.shape != shape: raise exceptions.ValidationError( "Data in mask matrix did not correspond to " "the (height, width) dimensions. Please " "check the input data.") mat = coo_matrix(arr) data.update({"coo_roi": mat}) return data
def __call__(self, value): if value != self.comparable: raise exceptions.ValidationError( json.dumps( dict(__omarsh__=self.__class__.__name__, value=str(value), expected=str(self.comparable)))) return value
def __call__(self, value): min_greater = operator.gt if self.min_strict else operator.ge max_lower = operator.lt if self.max_strict else operator.le # check if ok if (((self.min is not None) and not min_greater(value, self.min)) or (self.max is not None and not max_lower(value, self.max))): raise exceptions.ValidationError( json.dumps( dict(__omarsh__=self.__class__.__name__, value=str(value), min_value=self.min, max_value=self.max, min_strict=self.min_strict, max_strict=self.max_strict))) return value
def build_response(self, schema: Schema, response): """ Validate the given response against a given Schema. Return the response data as a serialized object according to the given Schema's fields. :param schema: :param response: :return: """ # Validate that schema. # This is not normally done with responses, but I want to be strict about ensuring the schema is up-to-date validation_errors = schema.validate(response) if validation_errors: # Throw an exception here with all the errors. # This will be caught and handled by the 500 internal error raise exceptions.ValidationError(validation_errors) # Build schema object from response data = schema.dump(response) return data
def _deserialize(self, value, attr, data, **kwargs): # type: ignore try: return get_dollars(value) except ValueError as exc: raise marshmallow_exceptions.ValidationError(str(exc))
def is_wh_empty(self, lst): if not lst: raise exceptions.ValidationError("This field is empty.")
def is_interval_ok(self, intervals): for interval in intervals: if interval[:5] >= interval[6:]: raise exceptions.ValidationError("String does not match expected pattern.")