How to use the pykwalify.errors.PyKwalifyException function in pykwalify

To help you get started, we’ve selected a few pykwalify 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 Grokzen / pykwalify / tests / test_exceptions.py View on Github external
def test_base_exception(self):
        # retcode=2 should be schemaerror
        e = errors.PyKwalifyException(msg="foobar", retcode=2)
        assert e.__repr__() == "PyKwalifyException(msg='foobar')"
        assert e.retname == "schemaerror"
github taverntesting / tavern / tavern / schemas / files.py View on Github external
BadSchemaError: Schema did not match
    """
    logger.debug("Verifying %s against %s", to_verify, schema)

    here = os.path.dirname(os.path.abspath(__file__))
    extension_module_filename = os.path.join(here, "extensions.py")

    verifier = core.Core(
        source_data=to_verify,
        schema_data=schema,
        extensions=[extension_module_filename],
    )

    try:
        verifier.validate()
    except pykwalify.errors.PyKwalifyException as e:
        logger.exception("Error validating %s", to_verify)
        raise_from(BadSchemaError(), e)
github intel / tcf / commonl / yamll.py View on Github external
"""
    try:
        with open(filename, 'r') as f:
            return yaml.safe_load(f)
    except yaml.scanner.ScannerError as e:	# For errors parsing schema.yaml
        logging.error("YAML errror: %s ", e)
        raise

# If pykwalify is installed, then the validate function will work --
# otherwise, it is a stub and we'd warn about it.
try:
    import pykwalify.core
    # Don't print error messages yourself, let us do it
    logging.getLogger("pykwalify.core").setLevel(50)

    e = pykwalify.errors.PyKwalifyException
    def validate(data, schema):
        if not schema:
            return
        c = pykwalify.core.Core(source_data = data, schema_data = schema)
        c.validate(raise_exception = True)

except ImportError as e:
    logging.warning("can't import pykwalify; won't validate YAML (%s)", e)
    e = Exception
    def validate(_data, _schema):
        pass


def load_verify(filename, schema):
    """
    Safely load a testcase/sample yaml document and validate it
github projectatomic / papr / papr / utils / parser.py View on Github external
def _validate(self, suite):

        schema = os.path.join(PKG_DIR, "schema.yml")
        ext = os.path.join(PKG_DIR, "ext_schema.py")

        try:
            c = pykwalify.core.Core(source_data=suite,
                                    schema_files=[schema],
                                    extensions=[ext])
            c.validate()
        except pykwalify.errors.PyKwalifyException as e:
            raise ParserError(e.msg)

        if suite['context'] in self.contexts:
            raise ParserError("duplicate 'context' value detected")

        self.met_required = self.met_required or suite.get('required', False)

        if suite['context'] == "required" and self.met_required:
            raise ParserError('context "required" forbidden when using the '
                              "'required' key")

        self.contexts.append(suite['context'])
github Grokzen / pykwalify / pykwalify / errors.py View on Github external
class NotSequenceError(PyKwalifyException):
    """
    """
    def __init__(self, *args, **kwargs):
        """
        """
        assert "retcode" not in kwargs, "keyword retcode implicitly defined"
        super(self.__class__, self).__init__(
            retcode=retnames['notsequenceerror'],
            *args, **kwargs
        )


class RuleError(PyKwalifyException):
    """
    """
    def __init__(self, *args, **kwargs):
        """
        """
        assert "retcode" not in kwargs, "keyword retcode implicitly defined"
        super(self.__class__, self).__init__(
            retcode=retnames["ruleerror"],
            *args, **kwargs
        )


class SchemaConflict(PyKwalifyException):
    """
    """
    def __init__(self, *args, **kwargs):
github Grokzen / pykwalify / pykwalify / errors.py View on Github external
def retname():
        doc = """ """

        def fget(self):
            return self._retname

        def fset(self, value):
            assert isinstance(value, str), "argument is not string"
            self._retname = value

        return locals()
    retname = property(**retname())


class UnknownError(PyKwalifyException):
    """
    """
    def __init__(self, *args, **kwargs):
        """
        """
        assert 'retcode' not in kwargs, "keyword retcode implicitly defined"
        super(self.__class__, self).__init__(
            retcode=retnames['unknownerror'],
            *args, **kwargs
        )


class SchemaError(PyKwalifyException):
    """
    """
    class SchemaErrorEntry(object):
github Grokzen / pykwalify / pykwalify / errors.py View on Github external
self.__setattr__(key, value)

        def __repr__(self):
            return self.msg.format(**self.__dict__)

    def __init__(self, *args, **kwargs):
        """
        """
        assert "retcode" not in kwargs, "keyword retcode implicitly defined"
        super(self.__class__, self).__init__(
            retcode=retnames["schemaerror"],
            *args, **kwargs
        )


class CoreError(PyKwalifyException):
    """
    """
    def __init__(self, *args, **kwargs):
        """
        """
        assert "retcode" not in kwargs, "keyword retcode implicitly defined"
        super(self.__class__, self).__init__(
            retcode=retnames["coreerror"],
            *args, **kwargs
        )


class NotMappingError(PyKwalifyException):
    """
    """
    def __init__(self, *args, **kwargs):
github Grokzen / pykwalify / pykwalify / errors.py View on Github external
class RuleError(PyKwalifyException):
    """
    """
    def __init__(self, *args, **kwargs):
        """
        """
        assert "retcode" not in kwargs, "keyword retcode implicitly defined"
        super(self.__class__, self).__init__(
            retcode=retnames["ruleerror"],
            *args, **kwargs
        )


class SchemaConflict(PyKwalifyException):
    """
    """
    def __init__(self, *args, **kwargs):
        """
        """
        assert "retcode" not in kwargs, "keyword retcode implicitly defined"
        super(self.__class__, self).__init__(
            retcode=retnames["schemaconflict"],
            *args, **kwargs
        )
github Grokzen / pykwalify / pykwalify / errors.py View on Github external
class CoreError(PyKwalifyException):
    """
    """
    def __init__(self, *args, **kwargs):
        """
        """
        assert "retcode" not in kwargs, "keyword retcode implicitly defined"
        super(self.__class__, self).__init__(
            retcode=retnames["coreerror"],
            *args, **kwargs
        )


class NotMappingError(PyKwalifyException):
    """
    """
    def __init__(self, *args, **kwargs):
        """
        """
        assert "retcode" not in kwargs, "keyword retcode implicitly defined"
        super(self.__class__, self).__init__(
            retcode=retnames['notmaperror'],
            *args, **kwargs
        )


class NotSequenceError(PyKwalifyException):
    """
    """
    def __init__(self, *args, **kwargs):