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 convenience 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
[Observation(name='request_c', value='1', kind='c', sampling_rate=None), Observation(name='active_sessions', value='320', kind='g', sampling_rate=None)]
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
We can use both strings and numbers (or any matcher) for the value:
>>> assert_that(test_client,
... contains(is_metric('c', 'request_c', '1'),
... is_gauge('active_sessions', 320)))
>>> assert_that(test_client,
... contains(is_metric('c', 'request_c', '1'),
... is_gauge('active_sessions', '320')))
>>> from hamcrest import is_
>>> assert_that(test_client,
... contains(is_metric('c', 'request_c', '1'),
... is_gauge('active_sessions', is_('320'))))
If the matching fails, we get a descriptive error:
>>> 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 [(an instance of Metric and (an object with a property 'kind' matching 'g' and an object with a property 'name' matching 'request_c' and an object with a property 'value' matching '1')), (an instance of Metric and (an object with a property 'kind' matching 'g' and an object with a property 'name' matching 'active_sessions' and an object with a property 'value' matching '320'))]
but: item 0: was Metric(name='request_c', value='1', kind='c', sampling_rate=None)
For complete details and the changelog, see the documentation.
Changes
1.0.0 (2019-09-03)
This project has been merged into perfmetrics.testing. There will be no further development.
0.0.2 (2018-10-26)
0.0.1 (2018-10-12)
First PyPI release.
Metadata
Release files for nti.fakestatsd 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nti.fakestatsd-1.0.0.tar.gz | 12.8 kB | Without provenance | Details for nti.fakestatsd-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nti.fakestatsd-1.0.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for nti.fakestatsd-1.0.0-py2.py3-none-any.whl |
Total release size: 22.4 kB
Release files / nti.fakestatsd-1.0.0.tar.gz
| Download URL | nti.fakestatsd-1.0.0.tar.gz |
|---|---|
| Size | 12.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8d2194affb955820defa7fcc1c8fee60267f929455b281466f2cccb15869c427
|
|
BLAKE2b-256 checksum How to use checksums |
5e91304adcaade06cf42b671e96f6564b3f41c4ed651803f0dd9199ed60325fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4
|
Release files / nti.fakestatsd-1.0.0-py2.py3-none-any.whl
| Download URL | nti.fakestatsd-1.0.0-py2.py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
5071362c663e7f2d62d34b6c736484b69f66a22ece0e340bf20322de0664b2e7
|
|
BLAKE2b-256 checksum How to use checksums |
4a6f6967e9c5cb6eac8139e70043c0ae5ea7aafb3c22b4465a5354c757a0e623
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4
|
Security for nti.fakestatsd 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.