Exemplo n.º 1
0
 def test_serialized_value_round_trip(self):
     vals = [
         six.
         b('\x01\x00\x00\x01%\xe9a\xf9\xd1\x06\x00\x00\x01v\xbb>o\xff\x00'),
         six.
         b('\x01\x00\x00\x00\xdcm\x03-\xd1\x06\x00\x00\x01v\xbb>o\xff\x00')
     ]
     for serialized in vals:
         self.assertEqual(
             serialized,
             DateRangeType.serialize(
                 DateRangeType.deserialize(serialized, 0), 0))
Exemplo n.º 2
0
    def test_deserialize_zero_datetime(self):
        """
        Test deserialization where timestamp = 0

        Reproduces PYTHON-729

        @since 2.0.0
        @jira_ticket PYTHON-729
        @expected_result deserialization doesn't raise an error

        @test_category data_types
        """
        DateRangeType.deserialize(
            (int8_pack(1) + int64_pack(0) + int8_pack(0) + int64_pack(0) +
             int8_pack(0)), 5)
Exemplo n.º 3
0
 def test_deserialize_single_value(self):
     serialized = (int8_pack(0) + int64_pack(self.timestamp) + int8_pack(3))
     self.assertEqual(
         DateRangeType.deserialize(serialized, 5),
         util.DateRange(value=util.DateRangeBound(value=datetime.datetime(
             2017, 2, 1, 15, 42, 12, 404000),
                                                  precision='HOUR')))
Exemplo n.º 4
0
    def test_serialize_zero_datetime(self):
        """
        Test serialization where timestamp = 0

        Companion test for test_deserialize_zero_datetime

        @since 2.0.0
        @jira_ticket PYTHON-729
        @expected_result serialization doesn't raise an error

        @test_category data_types
        """
        DateRangeType.serialize(
            util.DateRange(lower_bound=(datetime.datetime(1970, 1, 1), 'YEAR'),
                           upper_bound=(datetime.datetime(1970, 1,
                                                          1), 'YEAR')), 5)
Exemplo n.º 5
0
 def test_deserialize_both_open(self):
     serialized = (int8_pack(4))
     deserialized = DateRangeType.deserialize(serialized, 5)
     self.assertEqual(
         deserialized,
         util.DateRange(lower_bound=util.OPEN_BOUND,
                        upper_bound=util.OPEN_BOUND))
Exemplo n.º 6
0
 def test_serialize_single_value(self):
     serialized = (int8_pack(0) + int64_pack(self.timestamp) + int8_pack(5))
     deserialized = DateRangeType.deserialize(serialized, 5)
     self.assertEqual(
         deserialized,
         util.DateRange(value=util.DateRangeBound(value=datetime.datetime(
             2017, 2, 1, 15, 42, 12),
                                                  precision='SECOND')))
Exemplo n.º 7
0
 def test_serialize_open_low(self):
     serialized = (int8_pack(2) + int64_pack(self.timestamp) + int8_pack(3))
     deserialized = DateRangeType.deserialize(serialized, 5)
     self.assertEqual(
         deserialized,
         util.DateRange(lower_bound=util.DateRangeBound(
             value=datetime.datetime(2017, 2, 1, 15), precision='HOUR'),
                        upper_bound=util.OPEN_BOUND))
Exemplo n.º 8
0
 def test_deserialize_open_low(self):
     serialized = (int8_pack(3) + int64_pack(self.timestamp) + int8_pack(4))
     deserialized = DateRangeType.deserialize(serialized, 5)
     self.assertEqual(
         deserialized,
         util.DateRange(lower_bound=util.OPEN_BOUND,
                        upper_bound=util.DateRangeBound(
                            value=datetime.datetime(2017, 2, 1, 15, 42, 20,
                                                    1000),
                            precision='MINUTE')))
Exemplo n.º 9
0
 def test_deserialize_closed_range(self):
     serialized = (int8_pack(1) + int64_pack(self.timestamp) +
                   int8_pack(2) + int64_pack(self.timestamp) + int8_pack(6))
     self.assertEqual(
         DateRangeType.deserialize(serialized, 5),
         util.DateRange(lower_bound=util.DateRangeBound(
             value=datetime.datetime(2017, 2, 1, 0, 0), precision='DAY'),
                        upper_bound=util.DateRangeBound(
                            value=datetime.datetime(2017, 2, 1, 15, 42, 12,
                                                    404000),
                            precision='MILLISECOND')))
Exemplo n.º 10
0
 def test_serialize_closed_range(self):
     serialized = (int8_pack(1) + int64_pack(self.timestamp) +
                   int8_pack(5) + int64_pack(self.timestamp) + int8_pack(0))
     deserialized = DateRangeType.deserialize(serialized, 5)
     self.assertEqual(
         deserialized,
         util.DateRange(lower_bound=util.DateRangeBound(
             value=datetime.datetime(2017, 2, 1, 15, 42, 12),
             precision='SECOND'),
                        upper_bound=util.DateRangeBound(
                            value=datetime.datetime(2017, 12, 31),
                            precision='YEAR')))
Exemplo n.º 11
0
 def test_decode_precision(self):
     self.assertEqual(DateRangeType._decode_precision(6), 'MILLISECOND')
Exemplo n.º 12
0
 def test_encode_precision(self):
     self.assertEqual(DateRangeType._encode_precision('SECOND'), 5)
Exemplo n.º 13
0
 def test_encode_precision_error(self):
     with self.assertRaises(ValueError):
         DateRangeType._encode_precision('INVALID')
Exemplo n.º 14
0
 def test_serialize_both_open(self):
     serialized = DateRangeType.serialize(
         util.DateRange(lower_bound=util.OPEN_BOUND,
                        upper_bound=util.OPEN_BOUND), 5)
     self.assertEqual(int8_pack(4), serialized)
Exemplo n.º 15
0
 def test_serialize_single_open(self):
     serialized = DateRangeType.serialize(
         util.DateRange(value=util.OPEN_BOUND, ), 5)
     self.assertEqual(int8_pack(5), serialized)
Exemplo n.º 16
0
 def test_decode_precision_error(self):
     with self.assertRaises(ValueError):
         DateRangeType._decode_precision(-1)
Exemplo n.º 17
0
 def test_deserialize_single_open(self):
     self.assertEqual(util.DateRange(value=util.OPEN_BOUND),
                      DateRangeType.deserialize(int8_pack(5), 5))