def test_bytes(self, bdata, brepr): """ Should decode to unicode or a number array """ entry = {'BDATA': bdata} formatter = get_formatter('json') out = json.loads(formatter.format(entry)) assert out['BDATA'] == brepr
def test_uuid(self): """ Should be string representation of UUID """ entry = {'_BOOT_ID': uuid.uuid1()} formatter = get_formatter('json') out = json.loads(formatter.format(entry)) assert out['_BOOT_ID'] == str(entry['_BOOT_ID'])
def test_timestamp(self): """ Should output microseconds since the epoch """ dt = datetime.fromtimestamp(5, tz=timezone(timedelta(hours=1))) entry = {'__REALTIME_TIMESTAMP': dt} formatter = get_formatter('json') out = json.loads(formatter.format(entry)) assert out['__REALTIME_TIMESTAMP'] == 5000000
def test_timedelta(self): """ Should be in microseconds """ sec = 1 us = 700 mono_ts = timedelta(0, sec, us) entry = {'__MONOTONIC_TIMESTAMP': mono_ts} formatter = get_formatter('json') out = json.loads(formatter.format(entry)) diff = out['__MONOTONIC_TIMESTAMP'] - (sec * 1000000 + us) assert diff < 0.001
def test_monotonic(self): """ Should be in microseconds """ us = 700 elapsed = timedelta(microseconds=us) boot_id = uuid.uuid1() timestamp = journal.Monotonic((elapsed, boot_id)) entry = {'__MONOTONIC_TIMESTAMP': timestamp} formatter = get_formatter('json') out = json.loads(formatter.format(entry)) assert out['__MONOTONIC_TIMESTAMP'] == us