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
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
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
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]
def test_failed_validator(self, registered_validators): """ Ensure an assertion is raised. """ with pytest.raises(AssertionError): validate(Thing4(), self.validate_namespace)
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
def validation_report(self, validators, bad_catalog): """ return the report of the validators. """ return validate(bad_catalog, self.namespace, report=True)
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)