Exemplo n.º 1
0
 def test_cast_from_decimal_to_decimal(self):
     self.assertEqual(
         cast_to_decimal(cast_to_decimal(1.526,
                                         FloatType(),
                                         DecimalType(scale=2),
                                         options=BASE_OPTIONS),
                         DecimalType(scale=2),
                         DecimalType(scale=3),
                         options=BASE_OPTIONS), 1.53)
Exemplo n.º 2
0
 def test_cast_timestamp_to_decimal_with_scale(self):
     self.assertEqual(
         cast_to_decimal(datetime.datetime(2019, 8, 28),
                         TimestampType(),
                         DecimalType(precision=11, scale=1),
                         options=BASE_OPTIONS),
         1566939600.0 + self.tz_diff.seconds)
Exemplo n.º 3
0
 def test_cast_float_to_decimal_with_scale_and_other_rounding(self):
     self.assertEqual(
         cast_to_decimal(10.987654321,
                         FloatType(),
                         DecimalType(precision=10, scale=8),
                         options=BASE_OPTIONS), 10.98765432)
Exemplo n.º 4
0
 def test_cast_float_to_decimal_with_scale(self):
     self.assertEqual(
         cast_to_decimal(10.123456789,
                         FloatType(),
                         DecimalType(precision=10, scale=8),
                         options=BASE_OPTIONS), 10.12345679)
Exemplo n.º 5
0
 def test_cast_timestamp_to_decimal_with_too_small_precision(self):
     self.assertEqual(
         cast_to_decimal(datetime.datetime(2019, 8, 28),
                         TimestampType(),
                         DecimalType(precision=10, scale=1),
                         options=BASE_OPTIONS), None)
Exemplo n.º 6
0
 def test_cast_date_to_decimal(self):
     self.assertEqual(
         cast_to_decimal(datetime.date(2019, 8, 28),
                         DateType(),
                         DecimalType(),
                         options=BASE_OPTIONS), None)
Exemplo n.º 7
0
 def test_cast_timestamp_to_decimal_without_scale(self):
     self.assertEqual(
         cast_to_decimal(datetime.datetime(2019, 8, 28),
                         TimestampType(),
                         DecimalType(),
                         options=BASE_OPTIONS), 1566943200.0)