Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve assertion messages of aggregator stub #5975

Merged
merged 2 commits into from
Mar 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions datadog_checks_base/datadog_checks/base/stubs/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,11 @@ def assert_metric_has_tag(self, metric_name, tag, count=None, at_least=1):
if tag in metric.tags:
candidates.append(metric)

msg = "Candidates size assertion for `{}`, count: {}, at_least: {}) failed".format(metric_name, count, at_least)
if count is not None:
assert len(candidates) == count
assert len(candidates) == count, msg
else:
assert len(candidates) >= at_least
assert len(candidates) >= at_least, msg

# Potential kwargs: aggregation_key, alert_type, event_type,
# msg_title, source_type_name
Expand All @@ -170,9 +171,7 @@ def assert_event(self, msg_text, count=None, at_least=1, exact_match=True, tags=
else:
candidates.append(e)

msg = ("Candidates size assertion for {0}, count: {1}, " "at_least: {2}) failed").format(
msg_text, count, at_least
)
msg = "Candidates size assertion for `{}`, count: {}, at_least: {}) failed".format(msg_text, count, at_least)
if count is not None:
assert len(candidates) == count, msg
else:
Expand Down Expand Up @@ -392,10 +391,11 @@ def assert_metric_has_tag_prefix(self, metric_name, tag_prefix, count=None, at_l
if len(gtags) > 0:
candidates.append(metric)

msg = "Candidates size assertion for `{}`, count: {}, at_least: {}) failed".format(metric_name, count, at_least)
if count is not None:
assert len(candidates) == count
assert len(candidates) == count, msg
else:
assert len(candidates) >= at_least
assert len(candidates) >= at_least, msg

@property
def metrics_asserted_pct(self):
Expand Down