Esempio n. 1
0
    def test_normal(self, method, strict_level, value, expected):
        from typepy import Nan, StrictLevel

        actual = convert_wrapper(typepy.RealNumber(value, strict_level),
                                 method)
        if Nan(expected, strict_level=StrictLevel.MIN).is_type():
            assert Nan(actual, strict_level=StrictLevel.MIN).is_type()
        else:
            assert actual == expected
Esempio n. 2
0
    def __modify_item(data):
        try:
            return typepy.Integer(data).convert()
        except typepy.TypeConversionError:
            pass

        try:
            return typepy.RealNumber(data).convert()
        except typepy.TypeConversionError:
            pass

        return MultiByteStrDecoder(data).unicode_str
Esempio n. 3
0
    def to_query(self) -> str:
        value = self._value

        if value is None:
            return "NULL"

        if typepy.Integer(value).is_type() or typepy.RealNumber(
                value).is_type():
            return str(value)

        try:
            if value.find("'") != -1:
                return f'"{value}"'
        except (TypeError, AttributeError):
            pass

        return f"'{value}'"
Esempio n. 4
0
    def to_query(self):
        value = self._value

        if value is None:
            return "NULL"

        if typepy.Integer(value).is_type() or typepy.RealNumber(
                value).is_type():
            return six.text_type(value)

        try:
            if value.find("'") != -1:
                return '"{}"'.format(value)
        except (TypeError, AttributeError):
            pass

        return "'{}'".format(value)
Esempio n. 5
0
    def __get_unit(self):
        if typepy.RealNumber(self.__readable_time).is_type():
            # if the input value is real numbers consider unit as milliseconds.
            return "ms"

        return _RE_NUMBER.sub("", self.__readable_time).strip().lower()
Esempio n. 6
0
    def test_normal_float_type(self, value, float_type, expected):
        result = typepy.RealNumber(value,
                                   strict_level=StrictLevel.MIN,
                                   float_type=float_type).convert()

        assert result == expected