Ejemplo n.º 1
0
    def init_type_value(self, v, rule, path):
        log.debug("Init type value : {}".format(path))
        log.debug("Type: {} {}".format(v, rule))

        if v is None:
            v = DEFAULT_TYPE

        self._type = v
        self._type_class = type_class(v)

        if not is_builtin_type(self._type):
            raise RuleError("type.unknown : {} : {}".format(self._type, path))
Ejemplo n.º 2
0
    def init_type_value(self, v, rule, path):
        log.debug("Init type value : {}".format(path))
        log.debug("Type: {} {}".format(v, rule))

        if v is None:
            v = DEFAULT_TYPE

        self._type = v
        self._type_class = type_class(v)

        if not is_builtin_type(self._type):
            raise RuleError("type.unknown : {} : {}".format(self._type, path))
Ejemplo n.º 3
0
    def init_type_value(self, v, rule, path):
        log.debug(u"Init type value : %s", path)
        log.debug(u"Type: %s %s", v, rule)

        if v is None:
            v = DEFAULT_TYPE

        self.type = v
        self.type_class = type_class(v)

        if not is_builtin_type(self.type):
            raise RuleError(
                msg=u"Type: {} is not any of the known types".format(self.type), error_key=u"type.unknown", path=path
            )
Ejemplo n.º 4
0
    def init_type_value(self, v, rule, path):
        log.debug(u"Init type value : %s", path)
        log.debug(u"Type: %s %s", v, rule)

        if v is None:
            v = DEFAULT_TYPE

        self.type = v
        self.type_class = type_class(v)

        if not is_builtin_type(self.type):
            raise RuleError(
                msg=u"Type: {} is not any of the known types".format(self.type),
                error_key=u"type.unknown",
                path=path,
            )
Ejemplo n.º 5
0
    def test_types(self):
        """
        Test that all type helper methods works correctly
        """
        assert types.type_class("str") == str

        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)
        assert not types.is_float("foo")

        assert types.is_number(1)
        assert types.is_number(1.0)
        assert not types.is_number("foo")

        assert types.is_text("foo")
        assert types.is_text(1)
        assert types.is_text(1.0)
        assert not types.is_text([])
        assert not types.is_text(True)

        assert types.is_any("foo")
        assert types.is_any(True)
        assert types.is_any(1)
        assert types.is_any(1.0)
        assert types.is_any({})
        assert types.is_any([])

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

        assert types.is_none(None)
        assert not types.is_none("foo")
Ejemplo n.º 6
0
    def test_types(self):
        """
        Test that all type helper methods works correctly
        """
        assert types.type_class("str") == str

        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)
        assert not types.is_float("foo")

        assert types.is_number(1)
        assert types.is_number(1.0)
        assert not types.is_number("foo")

        assert types.is_text("foo")
        assert types.is_text(1)
        assert types.is_text(1.0)
        assert not types.is_text([])
        assert not types.is_text(True)

        assert types.is_any("foo")
        assert types.is_any(True)
        assert types.is_any(1)
        assert types.is_any(1.0)
        assert types.is_any({})
        assert types.is_any([])

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

        assert types.is_none(None)
        assert not types.is_none("foo")

        assert types.is_url("https://github.com")