Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def validate_observation(self, observation):
"""Validate the observation provided to the constructor.
Raises an ObservationError if invalid.
"""
if not observation:
raise ObservationError("Observation is missing.")
if not isinstance(observation, dict):
raise ObservationError("Observation is not a dictionary.")
if "mean" in observation and observation["mean"] is None:
raise ObservationError("Observation mean cannot be 'None'.")
if self.observation_schema:
if isinstance(self.observation_schema, list):
schemas = [x[1] if isinstance(x, tuple) else x
for x in self.observation_schema]
schema = {'oneof_schema': schemas,
'type': 'dict'}
else:
schema = {'schema': self.observation_schema,
'type': 'dict'}
schema = {'observation': schema}
v = ObservationValidator(schema, test=self)
if not v.validate({'observation': observation}):
raise ObservationError(v.errors)
return observation
def validate_observation(self, observation):
"""Validate the observation provided to the constructor.
Raises an ObservationError if invalid.
"""
if not observation:
raise ObservationError("Observation is missing.")
if not isinstance(observation, dict):
raise ObservationError("Observation is not a dictionary.")
if "mean" in observation and observation["mean"] is None:
raise ObservationError("Observation mean cannot be 'None'.")
if self.observation_schema:
if isinstance(self.observation_schema, list):
schemas = [x[1] if isinstance(x, tuple) else x
for x in self.observation_schema]
schema = {'oneof_schema': schemas,
'type': 'dict'}
else:
schema = {'schema': self.observation_schema,
'type': 'dict'}
schema = {'observation': schema}
v = ObservationValidator(schema, test=self)
if not v.validate({'observation': observation}):
raise ObservationError(v.errors)
return observation
def validate_observation(self, observation):
"""Validate the observation provided to the constructor.
Raises an ObservationError if invalid.
"""
if not observation:
raise ObservationError("Observation is missing.")
if not isinstance(observation, dict):
raise ObservationError("Observation is not a dictionary.")
if "mean" in observation and observation["mean"] is None:
raise ObservationError("Observation mean cannot be 'None'.")
if self.observation_schema:
if isinstance(self.observation_schema, list):
schemas = [x[1] if isinstance(x, tuple) else x
for x in self.observation_schema]
schema = {'oneof_schema': schemas,
'type': 'dict'}
else:
schema = {'schema': self.observation_schema,
'type': 'dict'}
schema = {'observation': schema}
v = ObservationValidator(schema, test=self)
if not v.validate({'observation': observation}):
raise ObservationError("Observation is not a dictionary.")
if "mean" in observation and observation["mean"] is None:
raise ObservationError("Observation mean cannot be 'None'.")
if self.observation_schema:
if isinstance(self.observation_schema, list):
schemas = [x[1] if isinstance(x, tuple) else x
for x in self.observation_schema]
schema = {'oneof_schema': schemas,
'type': 'dict'}
else:
schema = {'schema': self.observation_schema,
'type': 'dict'}
schema = {'observation': schema}
v = ObservationValidator(schema, test=self)
if not v.validate({'observation': observation}):
raise ObservationError(v.errors)
return observation