/
test_common.py
38 lines (30 loc) · 1012 Bytes
/
test_common.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
pglookout
Copyright (c) 2015 Ohmu Ltd
See LICENSE for details
"""
from pglookout.common import (
convert_xlog_location_to_offset,
parse_iso_datetime, get_iso_timestamp, ISO_EXT_RE,
)
from pytest import raises
import datetime
def test_convert_xlog_location_to_offset():
assert convert_xlog_location_to_offset("1/00000000") == 1 << 32
assert convert_xlog_location_to_offset("F/AAAAAAAA") == (0xF << 32) | 0xAAAAAAAA
with raises(ValueError):
convert_xlog_location_to_offset("x")
with raises(ValueError):
convert_xlog_location_to_offset("x/y")
def test_parse_iso_datetime():
date = datetime.datetime.utcnow()
date.replace(microsecond=0)
assert date == parse_iso_datetime(date.isoformat() + "Z")
with raises(ValueError):
parse_iso_datetime("foobar")
def test_get_iso_timestamp():
v = get_iso_timestamp()
assert ISO_EXT_RE.match(v)
ts = datetime.datetime.now()
v = get_iso_timestamp(ts)
assert parse_iso_datetime(v) == ts