How to use the pykwalify.errors.SchemaError 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_create_sub_class_exceptions(self):
        u_e = errors.UnknownError()
        assert u_e.retcode == 1

        s_e = errors.SchemaError()
        assert s_e.retcode == 2

        c_e = errors.CoreError()
        assert c_e.retcode == 3

        r_e = errors.RuleError()
        assert r_e.retcode == 4

        sc_e = errors.SchemaConflict()
        assert sc_e.retcode == 5
github zephyrproject-rtos / zephyr / scripts / zephyr_module.py View on Github external
def process_module(module):
    module_path = PurePath(module)
    module_yml = module_path.joinpath('zephyr/module.yml')

    # The input is a module if zephyr/module.yml is a valid yaml file
    # or if both zephyr/CMakeLists.txt and zephyr/Kconfig are present.

    if Path(module_yml).is_file():
        with Path(module_yml).open('r') as f:
            meta = yaml.safe_load(f.read())

        try:
            pykwalify.core.Core(source_data=meta, schema_data=schema)\
                .validate()
        except pykwalify.errors.SchemaError as e:
            sys.exit('ERROR: Malformed "build" section in file: {}\n{}'
                     .format(module_yml.as_posix(), e))

        return meta

    if Path(module_path.joinpath('zephyr/CMakeLists.txt')).is_file() and \
       Path(module_path.joinpath('zephyr/Kconfig')).is_file():
        return {'build': {'cmake': 'zephyr', 'kconfig': 'zephyr/Kconfig'}}

    return None
github Royal-Society-of-New-Zealand / NZ-ORCID-Hub / orcid_hub / models.py View on Github external
last_name = invitee.get("last-name")
                            orcid_id = invitee.get("ORCID-iD")
                            put_code = invitee.get("put-code")
                            visibility = get_val(invitee, "visibility")

                            WorkInvitees.create(
                                work_record=work_record,
                                identifier=identifier,
                                email=email.lower(),
                                first_name=first_name,
                                last_name=last_name,
                                orcid=orcid_id,
                                visibility=visibility,
                                put_code=put_code)
                    else:
                        raise SchemaError(u"Schema validation failed:\n - "
                                          u"Expecting Invitees for which the work record will be written")

                    contributors_list = work_data.get("contributors").get("contributor") if \
                        work_data.get("contributors") else None

                    if contributors_list:
                        for contributor in contributors_list:
                            orcid_id = get_val(contributor, "contributor-orcid", "path")
                            name = get_val(contributor, "credit-name", "value")
                            email = get_val(contributor, "contributor-email", "value")
                            role = get_val(contributor, "contributor-attributes", "contributor-role")
                            contributor_sequence = get_val(contributor, "contributor-attributes",
                                                           "contributor-sequence")

                            WorkContributor.create(
                                work_record=work_record,
github zephyrproject-rtos / west / src / west / commands / command.py View on Github external
# Project may not be cloned yet.
    if not os.path.exists(spec_file):
        return []

    # Load the spec file and check the schema.
    with open(spec_file, 'r') as f:
        try:
            commands_spec = yaml.safe_load(f.read())
        except yaml.YAMLError as e:
            raise ExtensionCommandError from e
    try:
        pykwalify.core.Core(
            source_data=commands_spec,
            schema_files=[_EXT_SCHEMA_PATH]).validate()
    except pykwalify.errors.SchemaError as e:
        raise ExtensionCommandError from e

    ret = []
    for commands_desc in commands_spec['west-commands']:
        ret.extend(_ext_specs_from_desc(project, commands_desc))
    return ret
github Royal-Society-of-New-Zealand / NZ-ORCID-Hub / orcid_hub / models.py View on Github external
def load_yaml_json(filename, source):
    """Create a common way of loading JSON or YAML file."""
    _, ext = os.path.splitext(filename)
    if ext.lower() in [".yaml", ".yml"]:
        data = json.loads(json.dumps(yaml.load(source)), object_pairs_hook=NestedDict)
    else:
        data = json.loads(source, object_pairs_hook=NestedDict)

    # Removing None for correct schema validation
    if not isinstance(data, list) and not (isinstance(data, dict) and "records" in data):
        raise SchemaError(
            u"Schema validation failed:\n - Expecting a list of Records")
    return data
github Royal-Society-of-New-Zealand / NZ-ORCID-Hub / orcid_hub / models.py View on Github external
def load_yaml_json(filename, source):
    """Create a common way of loading json or yaml file."""
    if os.path.splitext(filename)[1][1:] == "yaml" or os.path.splitext(
            filename)[1][1:] == "yml":
        data_list = yaml.load(source)
    else:
        data_list = json.loads(source)

    # Removing None for correct schema validation
    if not isinstance(data_list, list):
        raise SchemaError(
            u"Schema validation failed:\n - Expecting a list of Records")
    return data_list
github projectatomic / papr / papr / utils / ext_schema.py View on Github external
def ext_hosts(value, rule_obj, path):
    # Until this is fixed:
    # https://github.com/Grokzen/pykwalify/issues/67
    if type(value) is not list:
        raise SchemaError("expected list of dicts")
    for i, host in enumerate(value):
        if type(host) is not dict:
            raise SchemaError("host %d is not a dict" % i)
        if 'name' not in host:
            raise SchemaError("host %d missing key 'name'" % i)
        if 'distro' not in host:
            raise SchemaError("host %d missing key 'distro'" % i)
        if not _valid_hostname(host['name']):
            raise SchemaError("invalid hostname for host %d" % i)
        if 'ostree' in host:
            ext_ostree(host['ostree'], rule_obj, path)
    return True
github Royal-Society-of-New-Zealand / NZ-ORCID-Hub / orcid_hub / models.py View on Github external
last_name = invitee.get("last-name") if invitee.get("last-name") else None
                            orcid_id = invitee.get("ORCID-iD") if invitee.get("ORCID-iD") else None
                            put_code = invitee.get("put-code") if invitee.get("put-code") else None
                            visibility = get_val(invitee, "visibility")

                            PeerReviewInvitee.create(
                                peer_review_record=peer_review_record,
                                identifier=identifier,
                                email=email.lower(),
                                first_name=first_name,
                                last_name=last_name,
                                orcid=orcid_id,
                                visibility=visibility,
                                put_code=put_code)
                    else:
                        raise SchemaError(u"Schema validation failed:\n - "
                                          u"Expecting Invitees for which the peer review record will be written")

                    external_ids_list = peer_review_data.get("review-identifiers").get("external-id") if \
                        peer_review_data.get("review-identifiers") else None
                    if external_ids_list:
                        for external_id in external_ids_list:
                            type = external_id.get("external-id-type")
                            value = external_id.get("external-id-value")
                            url = external_id.get("external-id-url").get("value") if \
                                external_id.get("external-id-url") else None
                            relationship = external_id.get("external-id-relationship")
                            PeerReviewExternalId.create(
                                peer_review_record=peer_review_record,
                                type=type,
                                value=value,
                                url=url,