Testing StatsD client
Project description
nti.fakestatsd
nti.fakestatsd is a testing client for verifying StatsD metrics emitted by perfmetrics.
It’s easy to create a new client for use in testing:
>>> from nti.fakestatsd import FakeStatsDClient
>>> test_client = FakeStatsDClient()
This client exposes the same public interface as perfmetrics.statsd.StatsdClient. For example we can increment counters, set gauges, etc:
>>> test_client.incr('request_c')
>>> test_client.gauge('active_sessions', 320)
Unlike perfmetrics.statsd.StatsdClient, ~.FakeStatsDClient simply tracks the statsd packets that would be sent. This information is exposed on our test_client both as the raw statsd packet, and for conveninece this information is also parsed and exposed as ~.Metric objects. For complete details see ~.FakeStatsDClient and ~.Metric.
>>> test_client.packets
['request_c:1|c', 'active_sessions:320|g']
>>> test_client.metrics
[<nti.fakestatsd.metric.Metric object at ...>, <nti.fakestatsd.metric.Metric object at ...>]
For validating metrics we provide a set of hamcrest matchers for use in test assertions:
>>> from hamcrest import assert_that
>>> from hamcrest import contains
>>> from nti.fakestatsd.matchers import is_metric
>>> from nti.fakestatsd.matchers import is_gauge
>>> assert_that(test_client,
... contains(is_metric('c', 'request_c', '1'),
... is_gauge('active_sessions', '320')))
>>> assert_that(test_client,
... contains(is_gauge('request_c', '1'),
... is_gauge('active_sessions', '320')))
Traceback (most recent call last):
...
AssertionError:
Expected: a sequence containing [Metric of form <request_c:1|g>, Metric of form <active_sessions:320|g>]
but: item 0: was <request_c:1|c>
For complete details and the changelog, see the documentation.
Changes
0.0.2 (2018-10-26)
0.0.1 (2018-10-12)
First PyPI release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for nti.fakestatsd-0.0.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f6879a453ea43c7b64268b5133e38e2dd4a35d49b93029d6924a37f6a68054f |
|
MD5 | bcf0959d76c7e40dcd27b5f7d9c44422 |
|
BLAKE2b-256 | 4d97c8f3bdd69f31989d19dec5b55cf758a1cd1d78561afb162a84fa12c99ace |