Changeset View
Changeset View
Standalone View
Standalone View
swh/model/tests/test_model.py
Show First 20 Lines • Show All 446 Lines • ▼ Show 20 Lines | |||||
# TimestampWithTimezone | # TimestampWithTimezone | ||||
def test_timestampwithtimezone(): | def test_timestampwithtimezone(): | ||||
ts = Timestamp(seconds=0, microseconds=0) | ts = Timestamp(seconds=0, microseconds=0) | ||||
tstz = TimestampWithTimezone(timestamp=ts, offset_bytes=b"+0000") | tstz = TimestampWithTimezone(timestamp=ts, offset_bytes=b"+0000") | ||||
attr.validate(tstz) | attr.validate(tstz) | ||||
assert tstz.offset == 0 | assert tstz.offset_minutes() == 0 | ||||
assert tstz.offset_bytes == b"+0000" | assert tstz.offset_bytes == b"+0000" | ||||
tstz = TimestampWithTimezone(timestamp=ts, offset_bytes=b"+0010") | tstz = TimestampWithTimezone(timestamp=ts, offset_bytes=b"+0010") | ||||
attr.validate(tstz) | attr.validate(tstz) | ||||
assert tstz.offset == 10 | assert tstz.offset_minutes() == 10 | ||||
assert tstz.offset_bytes == b"+0010" | assert tstz.offset_bytes == b"+0010" | ||||
tstz = TimestampWithTimezone(timestamp=ts, offset_bytes=b"-0010") | tstz = TimestampWithTimezone(timestamp=ts, offset_bytes=b"-0010") | ||||
attr.validate(tstz) | attr.validate(tstz) | ||||
assert tstz.offset == -10 | assert tstz.offset_minutes() == -10 | ||||
assert tstz.offset_bytes == b"-0010" | assert tstz.offset_bytes == b"-0010" | ||||
tstz = TimestampWithTimezone(timestamp=ts, offset_bytes=b"-0000") | tstz = TimestampWithTimezone(timestamp=ts, offset_bytes=b"-0000") | ||||
attr.validate(tstz) | attr.validate(tstz) | ||||
assert tstz.offset == 0 | assert tstz.offset_minutes() == 0 | ||||
assert tstz.offset_bytes == b"-0000" | assert tstz.offset_bytes == b"-0000" | ||||
tstz = TimestampWithTimezone(timestamp=ts, offset_bytes=b"-1030") | tstz = TimestampWithTimezone(timestamp=ts, offset_bytes=b"-1030") | ||||
attr.validate(tstz) | attr.validate(tstz) | ||||
assert tstz.offset == -630 | assert tstz.offset_minutes() == -630 | ||||
assert tstz.offset_bytes == b"-1030" | assert tstz.offset_bytes == b"-1030" | ||||
tstz = TimestampWithTimezone(timestamp=ts, offset_bytes=b"+1320") | tstz = TimestampWithTimezone(timestamp=ts, offset_bytes=b"+1320") | ||||
attr.validate(tstz) | attr.validate(tstz) | ||||
assert tstz.offset == 800 | assert tstz.offset_minutes() == 800 | ||||
assert tstz.offset_bytes == b"+1320" | assert tstz.offset_bytes == b"+1320" | ||||
tstz = TimestampWithTimezone(timestamp=ts, offset_bytes=b"+200") | tstz = TimestampWithTimezone(timestamp=ts, offset_bytes=b"+200") | ||||
attr.validate(tstz) | attr.validate(tstz) | ||||
assert tstz.offset == 120 | assert tstz.offset_minutes() == 120 | ||||
assert tstz.offset_bytes == b"+200" | assert tstz.offset_bytes == b"+200" | ||||
tstz = TimestampWithTimezone(timestamp=ts, offset_bytes=b"+02") | tstz = TimestampWithTimezone(timestamp=ts, offset_bytes=b"+02") | ||||
attr.validate(tstz) | attr.validate(tstz) | ||||
assert tstz.offset == 120 | assert tstz.offset_minutes() == 120 | ||||
assert tstz.offset_bytes == b"+02" | assert tstz.offset_bytes == b"+02" | ||||
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_minutes() == 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, TypeError)): | with pytest.raises((AttributeTypeError, TypeError)): | ||||
TimestampWithTimezone(timestamp=ts, offset_bytes=0) | TimestampWithTimezone(timestamp=ts, offset_bytes=0) | ||||
▲ Show 20 Lines • Show All 976 Lines • Show Last 20 Lines |