def test_none_validates(self): nm = NumberMeta("int32") assert 0 == nm.validate(None)
def test_unsigned_validates(self): nm = NumberMeta("uint32") assert nm.validate("22") == 22 assert nm.validate(-22) == 2**32 - 22
def test_float_to_int_truncates(self): nm = NumberMeta("int32") assert nm.validate(123.6) == 123
def test_int_against_int(self): nm = NumberMeta("int32") assert 123 == nm.validate(123)
def test_int_against_float(self): nm = NumberMeta("float64") assert 123 == nm.validate(123)
def test_float_against_float64(self): nm = NumberMeta("float64") assert 123.456 == nm.validate(123.456)
def test_float_against_float32(self): nm = NumberMeta("float32") self.assertAlmostEqual(123.456, nm.validate(123.456), places=5)