示例#1
0
def test_metric_with_deleted_prefix():
    prefix = 'test.prefix'
    metric = 'test.metric'
    Metric.prefix = prefix
    assert Metric.prefix == prefix
    del Metric.prefix
    assert Metric(metric).metric == metric
示例#2
0
def test_send_global_graphite():
    Metric.graphite = GraphiteMock('test_send_global_graphite')
    metric = Metric('test_send_global_graphite')
    metric.send(4)
    metric.send(5, 6)
    assert Metric.graphite.sent == [('test_send_global_graphite', 4, None),
                                    ('test_send_global_graphite', 5, 6)]
示例#3
0
async def test_time_async():
    graphite = GraphiteMock('test_time_async')
    metric = Metric('test_time_async', graphite=graphite)

    @metric.time
    async def func():
        await asleep(.001)

    await func()
    await func()
    await func()

    assert all(m == 'test_time_async' and 1 <= v // 1000000 <= 3 and t is None
               for m, v, t in graphite.sent)
示例#4
0
def test_time():
    graphite = GraphiteMock('test_time')
    metric = Metric('test_time', graphite=graphite)

    @metric.time
    def func():
        sleep(.001)

    func()
    func()
    func()

    assert all(m == 'test_time' and 1 <= v // 1000000 <= 3 and t is None
               for m, v, t in graphite.sent)
示例#5
0
def test_count():
    graphite = GraphiteMock('test_count')
    metric = Metric('test_count', graphite=graphite)

    @metric.count
    def func():
        pass

    func()
    func()
    func()

    assert graphite.sent == [('test_count', 1, None), ('test_count', 1, None),
                             ('test_count', 1, None)]
示例#6
0
async def test_count_async():
    graphite = GraphiteMock('test_count_async')
    metric = Metric('test_count_async', graphite=graphite)

    @metric.count
    async def func():
        pass

    await func()
    await func()
    await func()

    assert graphite.sent == [
        ('test_count_async', 1, None),
        ('test_count_async', 1, None),
        ('test_count_async', 1, None),
    ]
示例#7
0
def test_metric_with_prefix():
    prefix = 'test.prefix'
    metric = 'test.metric'
    Metric.prefix = prefix
    assert Metric(metric).metric == '{}.{}'.format(prefix, metric)
示例#8
0
def test_invalid_graphite():
    with raises(TypeError):
        # noinspection PyTypeChecker
        Metric('some', graphite=object())
示例#9
0
def test_graphite():
    graphite = GraphiteMock('test_graphite')
    assert Metric('some', graphite=graphite)._graphite is graphite
示例#10
0
def test_invalid_metric():
    with raises(TypeError):
        # noinspection PyTypeChecker
        Metric(1234)
示例#11
0
def test_metric():
    metric = 'test.metric'
    assert Metric(metric).metric == metric
示例#12
0
def test_send():
    graphite = GraphiteMock('test_send')
    metric = Metric('test_send', graphite=graphite)
    metric.send(1)
    metric.send(2, 3)
    assert graphite.sent == [('test_send', 1, None), ('test_send', 2, 3)]