def test_RawMetricData_invalid_timestamp():
    with pytest.raises(ValueError):
        metrics._RawMetricData(metric_name='IFail',
                               value=100,
                               timestamp=time.time() - 2000000)
    with pytest.raises(ValueError):
        metrics._RawMetricData(metric_name='IFail',
                               value=100,
                               timestamp=time.time() + 10000)
def test_RawMetricData_utc_timestamp():
    utcnow = datetime.datetime.now(datetime.timezone.utc)
    assert utcnow.tzinfo
    metric = metrics._RawMetricData(metric_name='foo',
                                    value=1.0,
                                    timestamp=utcnow)
    assert utcnow.timestamp() == metric.Timestamp
Exemplo n.º 3
0
def test_RawMetricData_aware_timestamp():
    aware_datetime = datetime.datetime.now(dateutil.tz.gettz("America/Chicago"))
    assert aware_datetime.tzinfo
    metric = metrics._RawMetricData(metric_name="foo", value=1.0, timestamp=aware_datetime)
    assert (aware_datetime - aware_datetime.utcoffset()).replace(
        tzinfo=datetime.timezone.utc
    ).timestamp() == metric.Timestamp
Exemplo n.º 4
0
def test_RawMetricData_naive_timestamp():
    naive_datetime = datetime.datetime.now()
    assert naive_datetime.tzinfo is None
    metric = metrics._RawMetricData(metric_name="foo", value=1.0, timestamp=naive_datetime)
    local_datetime = naive_datetime.replace(tzinfo=dateutil.tz.tzlocal())
    assert (local_datetime - local_datetime.utcoffset()).replace(
        tzinfo=datetime.timezone.utc
    ).timestamp() == metric.Timestamp
def test_RawMetricData_number_timestamp():
    time_now = time.time()
    metric = metrics._RawMetricData(metric_name='foo',
                                    value=1.0,
                                    timestamp=time_now)
    assert time_now == metric.Timestamp