Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: tests/test_stats/test_filtehits_loader.py

Issue 30037555: NoIssue - Added filterhit statistics loading capability
Patch Set: Addressed final comments (for real now) Created April 3, 2019, 5:31 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/test_stats/data/filterhits_missing_columns.csv ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/test_stats/test_filtehits_loader.py
diff --git a/tests/test_stats/test_filtehits_loader.py b/tests/test_stats/test_filtehits_loader.py
new file mode 100644
index 0000000000000000000000000000000000000000..716925933a644969dbc186d8014b3933c0f76ec9
--- /dev/null
+++ b/tests/test_stats/test_filtehits_loader.py
@@ -0,0 +1,63 @@
+# This file is part of Adblock Plus <https://adblockplus.org/>,
+# Copyright (C) 2006-present eyeo GmbH
+#
+# Adblock Plus is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3 as
+# published by the Free Software Foundation.
+#
+# Adblock Plus is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+
+import pytest
+import py
+
+from abp.stats.filterhits import load_filterhit_statistics
+
+DATA_PATH = py.path.local(__file__).dirpath('data')
+
+
+@pytest.fixture
+def filterhits_file():
+ return DATA_PATH.join('filterhits.csv')
+
+
+@pytest.fixture
+def filterhits_file_missing_columns():
+ return DATA_PATH.join('filterhits_missing_columns.csv')
+
+
+def test_filterhits_load_no_filtering(filterhits_file):
+ entries = load_filterhit_statistics(str(filterhits_file))
+
+ count = 0
+
+ for entry in entries:
+ count += 1
+ assert isinstance(entry['hits'], int)
+ assert isinstance(entry['onehour_sessions'], int)
+ assert isinstance(entry['domains'], int)
+ assert isinstance(entry['rootdomains'], int)
+
+ assert count == 2
+
+
+@pytest.mark.parametrize('sources,exp_count', [
+ (['www.exceptionlist.com'], 1),
+ (['www.exceptionlist.com', 'www.blocklist.com'], 2),
+ (['inexistent_source', 'foo', 'bar'], 0),
+])
+def test_filterhits_load_with_filtering(sources, exp_count, filterhits_file):
+ entries = load_filterhit_statistics(str(filterhits_file), sources)
+
+ assert len(list(entries)) == exp_count
+
+
+def test_filterhits_load_missing_columns(filterhits_file_missing_columns):
+ entries = load_filterhit_statistics(str(filterhits_file_missing_columns))
+
+ assert len(list(entries)) == 2
« no previous file with comments | « tests/test_stats/data/filterhits_missing_columns.csv ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld