Snapshot of captured metrics that mimics the dict interface.
Metrics have the 'Dict[str(path), Set[Metric]]' format.
Definition at line 132 of file metrics.py.
Public Member Functions | |
__init__ (self, typing.Mapping[str, typing.Set[Metric]] values) | |
typing.Set[Metric] | __getitem__ (self, str path) |
Returns a list of metrics by specified path. | |
int | __len__ (self) |
Returns count of metrics paths. | |
__iter__ (self) | |
Returns a (path, list) iterable over the metrics. | |
bool | __contains__ (self, str path) |
Returns True if metric with specified path is in the snapshot, False otherwise. | |
bool | __eq__ (self, object other) |
Compares the snapshot with a dict of metrics or with another snapshot. | |
str | __repr__ (self) |
str | __str__ (self) |
get (self, str path, default=None) | |
Returns an list of metrics by path or default if there's no such path. | |
items (self) | |
Returns a (path, list) iterable over the metrics. | |
keys (self) | |
Returns an iterable over paths of metrics. | |
values (self) | |
Returns an iterable over lists of metrics. | |
MetricValue | value_at (self, str path, typing.Optional[typing.Dict] labels=None, *typing.Optional[MetricValue] default=None) |
Returns a single metric value at specified path. | |
typing.List[Metric] | metrics_at (self, str path, typing.Optional[typing.Dict] require_labels=None) |
Metrics path must exactly equal the given path . | |
bool | has_metrics_at (self, str path, typing.Optional[typing.Dict] require_labels=None) |
None | assert_equals (self, typing.Mapping[str, typing.Set[Metric]] other, *bool ignore_zeros=False) |
Compares the snapshot with a dict of metrics or with another snapshot, displaying a nice diff on mismatch. | |
str | pretty_print (self) |
Multiline linear print: path: (label=value),(label=value) TYPE VALUE path: (label=value),(label=value) TYPE VALUE Usage: | |
str | to_json (self) |
Serialize to a JSON string. | |
Static Public Member Functions | |
'MetricsSnapshot' | from_json (str json_str) |
Construct MetricsSnapshot from a JSON string. | |
Protected Attributes | |
_values | |
pytest_userver.metrics.MetricsSnapshot.__init__ | ( | self, | |
typing.Mapping[str, typing.Set[Metric]] | values ) |
Definition at line 142 of file metrics.py.
bool pytest_userver.metrics.MetricsSnapshot.__contains__ | ( | self, | |
str | path ) |
Returns True if metric with specified path is in the snapshot, False otherwise.
Definition at line 157 of file metrics.py.
bool pytest_userver.metrics.MetricsSnapshot.__eq__ | ( | self, | |
object | other ) |
Compares the snapshot with a dict of metrics or with another snapshot.
Definition at line 164 of file metrics.py.
typing.Set[Metric] pytest_userver.metrics.MetricsSnapshot.__getitem__ | ( | self, | |
str | path ) |
Returns a list of metrics by specified path.
Definition at line 145 of file metrics.py.
pytest_userver.metrics.MetricsSnapshot.__iter__ | ( | self | ) |
Returns a (path, list) iterable over the metrics.
Definition at line 153 of file metrics.py.
int pytest_userver.metrics.MetricsSnapshot.__len__ | ( | self | ) |
Returns count of metrics paths.
Definition at line 149 of file metrics.py.
str pytest_userver.metrics.MetricsSnapshot.__repr__ | ( | self | ) |
Definition at line 171 of file metrics.py.
str pytest_userver.metrics.MetricsSnapshot.__str__ | ( | self | ) |
Definition at line 174 of file metrics.py.
None pytest_userver.metrics.MetricsSnapshot.assert_equals | ( | self, | |
typing.Mapping[str, typing.Set[Metric]] | other, | ||
*bool | ignore_zeros = False ) |
Compares the snapshot with a dict of metrics or with another snapshot, displaying a nice diff on mismatch.
Definition at line 282 of file metrics.py.
|
static |
Construct MetricsSnapshot from a JSON string.
Definition at line 337 of file metrics.py.
pytest_userver.metrics.MetricsSnapshot.get | ( | self, | |
str | path, | ||
default = None ) |
Returns an list of metrics by path or default if there's no such path.
Definition at line 177 of file metrics.py.
bool pytest_userver.metrics.MetricsSnapshot.has_metrics_at | ( | self, | |
str | path, | ||
typing.Optional[typing.Dict] | require_labels = None ) |
Definition at line 275 of file metrics.py.
pytest_userver.metrics.MetricsSnapshot.items | ( | self | ) |
Returns a (path, list) iterable over the metrics.
Definition at line 184 of file metrics.py.
pytest_userver.metrics.MetricsSnapshot.keys | ( | self | ) |
Returns an iterable over paths of metrics.
Definition at line 188 of file metrics.py.
typing.List[Metric] pytest_userver.metrics.MetricsSnapshot.metrics_at | ( | self, | |
str | path, | ||
typing.Optional[typing.Dict] | require_labels = None ) |
Metrics path must exactly equal the given path
.
A required subset of labels is specified by require_labels
Example: require_labels={'a':'b', 'c':'d'} { 'a':'b', 'c':'d'} - exact match { 'a':'b', 'c':'d', 'e': 'f', 'h':'k'} - match { 'a':'x', 'c':'d'} - no match, incorrect value for label 'a' { 'a' : 'b'} - required label not found Usage:
Definition at line 235 of file metrics.py.
str pytest_userver.metrics.MetricsSnapshot.pretty_print | ( | self | ) |
Multiline linear print: path: (label=value),(label=value) TYPE VALUE path: (label=value),(label=value) TYPE VALUE Usage:
Definition at line 296 of file metrics.py.
str pytest_userver.metrics.MetricsSnapshot.to_json | ( | self | ) |
Serialize to a JSON string.
Definition at line 354 of file metrics.py.
MetricValue pytest_userver.metrics.MetricsSnapshot.value_at | ( | self, | |
str | path, | ||
typing.Optional[typing.Dict] | labels = None, | ||
*typing.Optional[MetricValue] | default = None ) |
Returns a single metric value at specified path.
If a dict of labels is provided, does en exact match of labels (i.e. {} stands for no labels; {'a': 'b', 'c': 'd'} matches only {'a': 'b', 'c': 'd'} or {'c': 'd', 'a': 'b'} but neither match {'a': 'b'} nor {'a': 'b', 'c': 'd', 'e': 'f'}).
AssertionError | if not one metric by path |
Definition at line 196 of file metrics.py.
pytest_userver.metrics.MetricsSnapshot.values | ( | self | ) |
Returns an iterable over lists of metrics.
Definition at line 192 of file metrics.py.
|
protected |
Definition at line 143 of file metrics.py.