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))
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)
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')))
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)
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))
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')))
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))
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')))
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')))
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')))
def test_decode_precision(self): self.assertEqual(DateRangeType._decode_precision(6), 'MILLISECOND')
def test_encode_precision(self): self.assertEqual(DateRangeType._encode_precision('SECOND'), 5)
def test_encode_precision_error(self): with self.assertRaises(ValueError): DateRangeType._encode_precision('INVALID')
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)
def test_serialize_single_open(self): serialized = DateRangeType.serialize( util.DateRange(value=util.OPEN_BOUND, ), 5) self.assertEqual(int8_pack(5), serialized)
def test_decode_precision_error(self): with self.assertRaises(ValueError): DateRangeType._decode_precision(-1)
def test_deserialize_single_open(self): self.assertEqual(util.DateRange(value=util.OPEN_BOUND), DateRangeType.deserialize(int8_pack(5), 5))