diff options
| author | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-07-12 19:58:44 -0500 |
|---|---|---|
| committer | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-07-12 19:58:44 -0500 |
| commit | 61430951ec13753aa49200222971ec646846b9b6 (patch) | |
| tree | 0d12f4dfd11a97e0dc2b01a6f03b724a45211df3 | |
| parent | 2d3f06219199a4a7307a3c9a5c14b69be8608dca (diff) | |
| download | flake8-61430951ec13753aa49200222971ec646846b9b6.tar.gz | |
Add more tests around our Statistics class
| -rw-r--r-- | tests/unit/test_statistics.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/unit/test_statistics.py b/tests/unit/test_statistics.py index c60af33..f95c638 100644 --- a/tests/unit/test_statistics.py +++ b/tests/unit/test_statistics.py @@ -70,3 +70,52 @@ def test_statistic_increment(): assert stat.count == 0 stat.increment() assert stat.count == 1 + + +def test_recording_statistics(): + """Verify that we appropriately create a new Statistic and store it.""" + aggregator = stats.Statistics() + assert list(aggregator.statistics_for('E')) == [] + aggregator.record(make_error()) + storage = aggregator._store + for key, value in storage.items(): + assert isinstance(key, stats.Key) + assert isinstance(value, stats.Statistic) + + assert storage[(DEFAULT_FILENAME, DEFAULT_ERROR_CODE)].count == 1 + + +def test_statistics_for_single_record(): + """Show we can retrieve the only statistic recorded.""" + aggregator = stats.Statistics() + assert list(aggregator.statistics_for('E')) == [] + aggregator.record(make_error()) + statistics = list(aggregator.statistics_for('E')) + assert len(statistics) == 1 + assert isinstance(statistics[0], stats.Statistic) + + +def test_statistics_for_filters_by_filename(): + """Show we can retrieve the only statistic recorded.""" + aggregator = stats.Statistics() + assert list(aggregator.statistics_for('E')) == [] + aggregator.record(make_error()) + aggregator.record(make_error(filename='example.py')) + + statistics = list(aggregator.statistics_for('E', DEFAULT_FILENAME)) + assert len(statistics) == 1 + assert isinstance(statistics[0], stats.Statistic) + + +def test_statistic_for_retrieves_more_than_one_value(): + """Show this works for more than a couple statistic values.""" + aggregator = stats.Statistics() + for i in range(50): + aggregator.record(make_error(code='E1{:02d}'.format(i))) + aggregator.record(make_error(code='W2{:02d}'.format(i))) + + statistics = list(aggregator.statistics_for('E')) + assert len(statistics) == 50 + + statistics = list(aggregator.statistics_for('W22')) + assert len(statistics) == 10 |
