Changeset View
Changeset View
Standalone View
Standalone View
swh/model/tests/test_model.py
Show First 20 Lines • Show All 492 Lines • ▼ Show 20 Lines | def test_timestampwithtimezone(): | ||||
tstz = TimestampWithTimezone(timestamp=ts, offset_bytes=b"+2000000000") | tstz = TimestampWithTimezone(timestamp=ts, offset_bytes=b"+2000000000") | ||||
attr.validate(tstz) | attr.validate(tstz) | ||||
assert tstz.offset == 0 | assert tstz.offset == 0 | ||||
assert tstz.offset_bytes == b"+2000000000" | assert tstz.offset_bytes == b"+2000000000" | ||||
with pytest.raises(AttributeTypeError): | with pytest.raises(AttributeTypeError): | ||||
TimestampWithTimezone(timestamp=datetime.datetime.now(), offset_bytes=b"+0000") | TimestampWithTimezone(timestamp=datetime.datetime.now(), offset_bytes=b"+0000") | ||||
with pytest.raises((AttributeTypeError, AttributeError, TypeError)): | with pytest.raises((AttributeTypeError, TypeError)): | ||||
TimestampWithTimezone(timestamp=ts, offset_bytes=0) | TimestampWithTimezone(timestamp=ts, offset_bytes=0) | ||||
def test_timestampwithtimezone_from_datetime(): | def test_timestampwithtimezone_from_datetime(): | ||||
# Typical case | # Typical case | ||||
tz = datetime.timezone(datetime.timedelta(minutes=+60)) | tz = datetime.timezone(datetime.timedelta(minutes=+60)) | ||||
date = datetime.datetime(2020, 2, 27, 14, 39, 19, tzinfo=tz) | date = datetime.datetime(2020, 2, 27, 14, 39, 19, tzinfo=tz) | ||||
tstz = TimestampWithTimezone.from_datetime(date) | tstz = TimestampWithTimezone.from_datetime(date) | ||||
▲ Show 20 Lines • Show All 970 Lines • Show Last 20 Lines |