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: Addressed Initial Comments Created April 3, 2019, 5:15 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')
25 27
26 28
27 @pytest.fixture 29 @pytest.fixture
28 def filterhits_file_missing_columns(): 30 def filterhits_file_missing_columns():
29 return py.path.local(__file__).dirpath('data').join( 31 return DATA_PATH.join('filterhits_missing_columns.csv')
30 'filterhits_missing_columns.csv',
31 )
32 32
33 33
34 def test_filterhits_load_no_filtering(filterhits_file): 34 def test_filterhits_load_no_filtering(filterhits_file):
35 entries = load_filterhit_statistics(str(filterhits_file)) 35 entries = load_filterhit_statistics(str(filterhits_file))
36 36
37 count = 0 37 count = 0
38 38
39 for entry in entries: 39 for entry in entries:
40 count += 1 40 count += 1
41 assert isinstance(entry['hits'], int) 41 assert isinstance(entry['hits'], int)
42 assert isinstance(entry['onehour_sessions'], int) 42 assert isinstance(entry['onehour_sessions'], int)
43 assert isinstance(entry['domains'], int) 43 assert isinstance(entry['domains'], int)
44 assert isinstance(entry['rootdomains'], int) 44 assert isinstance(entry['rootdomains'], int)
45 45
46 assert count == 2 46 assert count == 2
47 47
48 48
49 @pytest.mark.parametrize('sources,exp_count', [ 49 @pytest.mark.parametrize('sources,exp_count', [
50 (['www.exceptionlist.com'], 1), 50 (['www.exceptionlist.com'], 1),
51 (['www.exceptionlist.com', 'www.blocklist.com'], 2), 51 (['www.exceptionlist.com', 'www.blocklist.com'], 2),
52 (['inexistent_source', 'foo', 'bar'], 0), 52 (['inexistent_source', 'foo', 'bar'], 0),
53 ]) 53 ])
54 def test_filterhits_load_with_filtering(sources, exp_count, filterhits_file): 54 def test_filterhits_load_with_filtering(sources, exp_count, filterhits_file):
55 entries = load_filterhit_statistics(str(filterhits_file), sources) 55 entries = load_filterhit_statistics(str(filterhits_file), sources)
56 56
57 count = 0 57 assert len(list(entries)) == exp_count
58 for _ in entries:
59 count += 1
60
61 assert count == exp_count
62 58
63 59
64 def test_filterhits_load_missing_columns(filterhits_file_missing_columns): 60 def test_filterhits_load_missing_columns(filterhits_file_missing_columns):
65 entries = load_filterhit_statistics(str(filterhits_file_missing_columns)) 61 entries = load_filterhit_statistics(str(filterhits_file_missing_columns))
66 62
67 count = 0 63 assert len(list(entries)) == 2
68 for _ in entries:
69 count += 1
70
71 assert count == 2
LEFTRIGHT

Powered by Google App Engine
This is Rietveld