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

Delta Between Two Patch Sets: tests/test_stats/test_filtehits_loader.py

Issue 30037555: NoIssue - Added filterhit statistics loading capability
Left Patch Set: Removed .DS_Store files Created April 3, 2019, 4:16 p.m.
Right Patch Set: Addressed final comments (for real now) Created April 3, 2019, 5:31 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « tests/test_stats/data/filterhits_missing_columns.csv ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # This file is part of Adblock Plus <https://adblockplus.org/>, 1 # This file is part of Adblock Plus <https://adblockplus.org/>,
2 # Copyright (C) 2006-present eyeo GmbH 2 # Copyright (C) 2006-present eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details. 11 # GNU General Public License for more details.
12 # 12 #
13 # You should have received a copy of the GNU General Public License 13 # You should have received a copy of the GNU General Public License
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15 15
16 import pytest 16 import pytest
17 import py 17 import py
18 18
19 from abp.stats.filterhits import load_filterhit_statistics 19 from abp.stats.filterhits import load_filterhit_statistics
20 20
21 DATA_PATH = py.path.local(__file__).dirpath('data')
22
21 23
22 @pytest.fixture 24 @pytest.fixture
23 def filterhits_file(): 25 def filterhits_file():
24 return py.path.local(__file__).dirpath('data').join('filterhits.csv') 26 return DATA_PATH.join('filterhits.csv')
27
28
29 @pytest.fixture
30 def filterhits_file_missing_columns():
31 return DATA_PATH.join('filterhits_missing_columns.csv')
25 32
26 33
27 def test_filterhits_load_no_filtering(filterhits_file): 34 def test_filterhits_load_no_filtering(filterhits_file):
28 entries = load_filterhit_statistics(str(filterhits_file)) 35 entries = load_filterhit_statistics(str(filterhits_file))
29 36
30 count = 0 37 count = 0
31 38
32 for entry in entries: 39 for entry in entries:
33 count += 1 40 count += 1
34 assert isinstance(entry['hits'], int) 41 assert isinstance(entry['hits'], int)
35 assert isinstance(entry['onehour_sessions'], int) 42 assert isinstance(entry['onehour_sessions'], int)
43 assert isinstance(entry['domains'], int)
44 assert isinstance(entry['rootdomains'], int)
36 45
37 assert count == 9 46 assert count == 2
38 47
39 48
40 @pytest.mark.parametrize('sources,exp_count', [ 49 @pytest.mark.parametrize('sources,exp_count', [
41 (['https://easylist-downloads.adblockplus.org/easylist.txt'], 4), 50 (['www.exceptionlist.com'], 1),
42 (['https://easylist-downloads.adblockplus.org/exceptionrules.txt'], 4), 51 (['www.exceptionlist.com', 'www.blocklist.com'], 2),
43 (['inexistent_source', 'foo', 'bar'], 0), 52 (['inexistent_source', 'foo', 'bar'], 0),
44 ]) 53 ])
45 def test_filterhits_load_with_filtering(sources, exp_count, filterhits_file): 54 def test_filterhits_load_with_filtering(sources, exp_count, filterhits_file):
46 entries = load_filterhit_statistics(str(filterhits_file), sources) 55 entries = load_filterhit_statistics(str(filterhits_file), sources)
47 56
48 count = 0 57 assert len(list(entries)) == exp_count
49 58
50 for entry in entries:
51 count += 1
52 59
53 assert count == exp_count 60 def test_filterhits_load_missing_columns(filterhits_file_missing_columns):
61 entries = load_filterhit_statistics(str(filterhits_file_missing_columns))
62
63 assert len(list(entries)) == 2
LEFTRIGHT

Powered by Google App Engine
This is Rietveld