Example #1
0
 def test_validators_work_once(self, registered_validators):
     """
     Ensure validators registered for multiple classes get called just once
     for subclasses of each.
     """
     validate(Thing3(), self.validate_namespace)
     assert registered_validators["multiple_validate"] == 1
Example #2
0
 def test_thing_two(self, registered_validators):
     """
     An instance of thing 3 should trigger all the validators since it
     is a subclass of thing1 and thing2.
     """
     validate(Thing3(), self.validate_namespace)
     for a in range(1, 4):
         assert registered_validators[f"test{a}"] == 1
Example #3
0
def validate_catalog(events: Union[Catalog, Event],
                     **kwargs) -> Union[Catalog, Event]:
    """
    Perform checks on a events or event object.

    This function will try to fix any issues but will raise if it cannot. It
    is a simple wrapper around obsplus.validate.validate for the obsplus
    namespace.

    Parameters
    ----------
    events
        The events or event to check
    """
    cat = events if isinstance(events, Catalog) else Catalog(events=[events])
    validate(cat, "obsplus", **kwargs)
    return events
Example #4
0
 def test_failed_validator_report(self, registered_validators):
     """ Ensure a dataframe is returned with a report. """
     df = validate(Thing4(), self.validate_namespace, report=True)
     assert len(df) == 1
     assert not df["passed"].iloc[0]
Example #5
0
 def test_failed_validator(self, registered_validators):
     """ Ensure an assertion is raised. """
     with pytest.raises(AssertionError):
         validate(Thing4(), self.validate_namespace)
Example #6
0
 def test_thing_one(self, registered_validators):
     """ Ensure the validator is triggered on thing one instance. """
     validate(Thing1(), self.validate_namespace)
     assert registered_validators["test1"] == 1
Example #7
0
 def validation_report(self, validators, bad_catalog):
     """ return the report of the validators. """
     return validate(bad_catalog, self.namespace, report=True)
Example #8
0
 def test_kwargs_passed(self, registered_validators):
     """ Ensure the kwargs get passed to individual validators. """
     with pytest.raises(ValueError):
         validate(Thing2(), self.validate_namespace, some_kwarg=True)