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
def test_normal_nan(self, value, is_convert, expected_data, expected_typecode): dp = DataProperty( value, strict_level_map=get_strict_level_map(not is_convert)) assert Nan(dp.data).is_type() assert dp.typecode == expected_typecode
def __exeute_method(self, method, value): try: result = getattr(self.typeclass(value, self.strict_level), method)() if method == "validate": result = "-" except (TypeError, typepy.TypeConversionError): return '"E"' # for string tests if NullString(result, StrictLevel.MAX).is_type(): return '""' strict_level = StrictLevel.MAX typeobj = Integer(result, strict_level) if typeobj.is_type(): return typeobj.convert() typeobj = RealNumber(result, strict_level) if typeobj.is_type(): return typeobj.convert() if String(result, strict_level).is_type(): return '"{}"'.format(result) if Infinity(result, strict_level).is_type(): return '"inf"' if Nan(result, strict_level).is_type(): return '"nan"' return result
def __equals_raw(self, other) -> bool: if not self.__equals_base(other): return False if self.headers != other.headers: return False for lhs_row, rhs_row in zip(self.rows, other.rows): if len(lhs_row) != len(rhs_row): return False if not all([ lhs == rhs for lhs, rhs in zip(lhs_row, rhs_row) if not Nan(lhs).is_type() and not Nan(rhs).is_type() ]): return False return True
def __get_decimal_places(self) -> Optional[int]: try: avg = self.minmax_decimal_places.mean() except TypeError: return None if Nan(avg).is_type(): return None return int(min(math.ceil(avg + Decimal("1.0")), self.minmax_decimal_places.max_value))
def __get_realnumber_format(self, decimal_places): if not self.__is_formatting_float: return "{}" base_format = self.__get_base_format_str() if decimal_places is None or Nan(decimal_places).is_type(): return "{:" + base_format + "f}" try: return "{:" + "{:s}.{:d}f".format(base_format, decimal_places) + "}" except ValueError: pass return "{:" + base_format + "f}"
def __init__(self): self.typeclass = None self.strict_level = None self.headers = None self.value_list = None self.__table_writer = ptw.RstSimpleTableWriter() self.__table_writer._dp_extractor.type_value_map = { NullString(None).typecode: '``""``', NoneType(None).typecode: "``None``", Infinity(None).typecode: '``Decimal("inf")``', Nan(None).typecode: '``Decimal("nan")``', } self.__table_writer.value_map = { True: "``True``", False: "``False``", '``"127.0.0.1"``': '``ip_address("127.0.0.1")``', }
def test_normal(self, value, strict_level, expected): type_checker = Nan(value, strict_level) assert type_checker.is_type() == expected assert type_checker.typecode == Typecode.NAN
def test_null(self, container): assert Nan(container.diff()).is_type()
def test_abnormal(self, value): dp = DataProperty(value) Nan(dp.decimal_places).is_type()
def test_abnormal(self, value): dp = DataProperty(value) Nan(dp.integer_digits).is_type()
def test_abnormal(self, value, expected): Nan(DataProperty(value).length).is_type()