Example #1
0
    def validate(self, path, schema=None):
        """Validates given stub path against its schema

        Args:
            path (str): path to validate
            schema (str, optional): Path to schema. Defaults to None.
                If None, the DeviceStub schema is used.

        Raises:
            StubError: Raised if no info file can be found
            StubValidationError: Raised if the info file fails validation
        """
        self.log.debug(f"Validating: {path}")
        schema = schema or self._schema
        path = Path(path).resolve()
        stub_info = path / 'info.json'
        val = utils.Validator(schema)
        try:
            val.validate(stub_info)
        except FileNotFoundError:
            raise StubError(f"{path.name} contains no info file!")
        except Exception as e:
            raise StubValidationError(path, str(e))
Example #2
0
def test_fail_validate(schema):
    """Test for invalid file"""
    schema, _, fail_file = schema
    val = utils.Validator(schema_path=schema)
    with pytest.raises(ValidationError):
        val.validate(fail_file)
Example #3
0
def test_validate(schema):
    """Test for successful validation"""
    schema, pass_file, _ = schema
    val = utils.Validator(schema_path=schema)
    val.validate(pass_file)