How to use the pykwalify.types.is_scalar 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_types.py View on Github external
assert types.is_builtin_type("str")

        assert types.is_collection_type("map")
        assert types.is_collection_type("seq")
        assert not types.is_collection_type("str")

        assert types.is_scalar_type("str")
        assert not types.is_scalar_type("seq")
        assert not types.is_scalar_type("map")

        assert types.is_collection([])
        assert types.is_collection({})
        assert not types.is_collection("foo")

        assert types.is_scalar("")
        assert types.is_scalar(True)
        assert not types.is_scalar([])

        assert types.is_correct_type("", str)
        assert types.is_correct_type({}, dict)

        assert types.is_string("foo")
        assert not types.is_string([])

        assert types.is_int(1)
        assert not types.is_int("foo")

        assert types.is_bool(True)
        assert not types.is_bool(1)
        assert not types.is_bool("true")

        assert types.is_float(1.0)
github Grokzen / pykwalify / tests / test_types.py View on Github external
assert types.is_collection_type("map")
        assert types.is_collection_type("seq")
        assert not types.is_collection_type("str")

        assert types.is_scalar_type("str")
        assert not types.is_scalar_type("seq")
        assert not types.is_scalar_type("map")

        assert types.is_collection([])
        assert types.is_collection({})
        assert not types.is_collection("foo")

        assert types.is_scalar("")
        assert types.is_scalar(True)
        assert not types.is_scalar([])

        assert types.is_correct_type("", str)
        assert types.is_correct_type({}, dict)

        assert types.is_string("foo")
        assert not types.is_string([])

        assert types.is_int(1)
        assert not types.is_int("foo")

        assert types.is_bool(True)
        assert not types.is_bool(1)
        assert not types.is_bool("true")

        assert types.is_float(1.0)
        assert not types.is_float("foo")
github Grokzen / pykwalify / tests / test_types.py View on Github external
assert types.is_builtin_type("str")

        assert types.is_collection_type("map")
        assert types.is_collection_type("seq")
        assert not types.is_collection_type("str")

        assert types.is_scalar_type("str")
        assert not types.is_scalar_type("seq")
        assert not types.is_scalar_type("map")

        assert types.is_collection([])
        assert types.is_collection({})
        assert not types.is_collection("foo")

        assert types.is_scalar("")
        assert types.is_scalar(True)
        assert not types.is_scalar([])

        assert types.is_correct_type("", str)
        assert types.is_correct_type({}, dict)

        assert types.is_string("foo")
        assert not types.is_string([])

        assert types.is_int(1)
        assert not types.is_int("foo")

        assert types.is_bool(True)
        assert not types.is_bool(1)
        assert not types.is_bool("true")
github Grokzen / pykwalify / pykwalify / core.py View on Github external
)

        if rule.length is not None:
            self._validate_length(
                rule.length,
                value,
                path,
                'scalar',
            )

        # Validate timestamp
        if rule.type == "timestamp":
            self._validate_scalar_timestamp(value, path)

        if rule.type == "date":
            if not is_scalar(value):
                raise CoreError(u'value is not a valid scalar')
            date_format = rule.format
            self._validate_scalar_date(value, date_format, path)
github Grokzen / pykwalify / pykwalify / core.py View on Github external
log.debug("Matching pattern '{0}' to regex '{1}".format(rule.pattern, value))
                res = re.match(rule.pattern, value, re.UNICODE)
            except TypeError:
                res = None

            if res is None:  # Not matching
                self.errors.append(SchemaError.SchemaErrorEntry(
                    msg=u"Value '{value}' does not match pattern '{pattern}'. Path: '{path}'",
                    path=path,
                    value=nativestr(str(value)),
                    pattern=rule._pattern))
            else:
                log.debug("Pattern matched...")

        if rule.range is not None:
            if not is_scalar(value):
                raise CoreError(u"value is not a valid scalar")

            r = rule.range

            try:
                v = len(value)
                value = v
            except Exception:
                pass

            self._validate_range(
                r.get("max"),
                r.get("min"),
                r.get("max-ex"),
                r.get("min-ex"),
                value,