How to use the sciunit.errors.ObservationError function in sciunit

To help you get started, we’ve selected a few sciunit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scidash / sciunit / sciunit / tests.py View on Github external
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
github scidash / sciunit / sciunit / tests.py View on Github external
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
github scidash / sciunit / sciunit / tests.py View on Github external
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}):
github scidash / sciunit / sciunit / tests.py View on Github external
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