-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for the strategies module. (#1541)
* Add unit tests for the strategies module.
- Loading branch information
Showing
5 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/sh | ||
|
||
# We currently get one warning when running Python in dev mode: | ||
# aiohttp/helpers.py:107: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead | ||
# Turn off dev mode until aiohttp gets fixed or there's a way to suppress warnings in third party code | ||
# export PYTHONDEVMODE=1 | ||
|
||
# For Windows compatibility; prevent path from ending with a ':' | ||
export PYTHONPATH=`python -c 'import sys;print(":".join(sys.argv[1:]))' src $PYTHONPATH` | ||
export COVERAGE_RCFILE=../../.coveragerc | ||
coverage run -m unittest --quiet | ||
coverage xml | ||
coverage html | ||
coverage report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
coverage==5.3 | ||
pip==20.2.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
29 changes: 29 additions & 0 deletions
29
components/notifier/tests/strategies/test_reds_per_report.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""Unit tests for the notification strategies.""" | ||
|
||
import unittest | ||
|
||
from strategies.reds_per_report import reds_per_report | ||
|
||
|
||
class RedsPerReportTestCase(unittest.TestCase): | ||
"""Unit tests for the reds per report notification strategy.""" | ||
|
||
def test_no_reports(self): | ||
"""Test that there is nothing to notify when there are no reports.""" | ||
self.assertEqual([], reds_per_report(dict(reports=[]))) | ||
|
||
def test_no_red_metrics(self): | ||
"""Test that there is nothing to notify when there are no red metrics.""" | ||
green_metric = dict(status="target_met") | ||
subject1 = dict(metrics=dict(metric1=green_metric)) | ||
report1 = dict(report_uuid="report1", subjects=dict(subject1=subject1)) | ||
json = dict(reports=[report1]) | ||
self.assertEqual([["report1", 0]], reds_per_report(json)) | ||
|
||
def test_red_metrics(self): | ||
"""Test that the number of red metrics is returned.""" | ||
red_metric = dict(status="target_not_met") | ||
subject1 = dict(metrics=dict(metric1=red_metric)) | ||
report1 = dict(report_uuid="report1", subjects=dict(subject1=subject1)) | ||
json = dict(reports=[report1]) | ||
self.assertEqual([["report1", 1]], reds_per_report(json)) |