OLD | NEW |
(Empty) | |
| 1 # This file is part of Adblock Plus <https://adblockplus.org/>, |
| 2 # Copyright (C) 2006-present eyeo GmbH |
| 3 # |
| 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 |
| 6 # published by the Free Software Foundation. |
| 7 # |
| 8 # Adblock Plus is distributed in the hope that it will be useful, |
| 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 # GNU General Public License for more details. |
| 12 # |
| 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/>. |
| 15 |
| 16 import pytest |
| 17 import py |
| 18 |
| 19 from abp.stats.filterhits import load_filterhit_statistics |
| 20 |
| 21 DATA_PATH = py.path.local(__file__).dirpath('data') |
| 22 |
| 23 |
| 24 @pytest.fixture |
| 25 def filterhits_file(): |
| 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') |
| 32 |
| 33 |
| 34 def test_filterhits_load_no_filtering(filterhits_file): |
| 35 entries = load_filterhit_statistics(str(filterhits_file)) |
| 36 |
| 37 count = 0 |
| 38 |
| 39 for entry in entries: |
| 40 count += 1 |
| 41 assert isinstance(entry['hits'], int) |
| 42 assert isinstance(entry['onehour_sessions'], int) |
| 43 assert isinstance(entry['domains'], int) |
| 44 assert isinstance(entry['rootdomains'], int) |
| 45 |
| 46 assert count == 2 |
| 47 |
| 48 |
| 49 @pytest.mark.parametrize('sources,exp_count', [ |
| 50 (['www.exceptionlist.com'], 1), |
| 51 (['www.exceptionlist.com', 'www.blocklist.com'], 2), |
| 52 (['inexistent_source', 'foo', 'bar'], 0), |
| 53 ]) |
| 54 def test_filterhits_load_with_filtering(sources, exp_count, filterhits_file): |
| 55 entries = load_filterhit_statistics(str(filterhits_file), sources) |
| 56 |
| 57 assert len(list(entries)) == exp_count |
| 58 |
| 59 |
| 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 |
OLD | NEW |