| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 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 """Functional tests for testing rPython integration.""" | 16 """Functional tests for testing rPython integration.""" |
| 17 from __future__ import unicode_literals | 17 from __future__ import unicode_literals |
| 18 | 18 |
| 19 from collections import namedtuple | 19 from collections import namedtuple |
| 20 import pytest | 20 import pytest |
| 21 import sys | 21 import sys |
| 22 | 22 |
| 23 from abp.filters.rpy import tuple2dict, line2dict | 23 from abp.filters.rpy import tuple2dict, line2dict, lines2dicts |
| 24 | 24 |
| 25 | 25 |
| 26 _SAMPLE_TUPLE = namedtuple('tuple', 'foo,bar') | 26 _SAMPLE_TUPLE = namedtuple('tuple', 'foo,bar') |
| 27 | 27 |
| 28 _TEST_EXAMPLES = { | 28 _TEST_EXAMPLES = { |
| 29 'header': { | 29 'header': { |
| 30 'in': b'[Adblock Plus 2.0]', | 30 'in': b'[Adblock Plus 2.0]', |
| 31 'out': { | 31 'out': { |
| 32 b'type': b'Header', | 32 b'type': b'Header', |
| 33 b'version': b'Adblock Plus 2.0', | 33 b'version': b'Adblock Plus 2.0', |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 @pytest.mark.parametrize('line_type', list(_TEST_EXAMPLES.keys())) | 140 @pytest.mark.parametrize('line_type', list(_TEST_EXAMPLES.keys())) |
| 141 def test_line2dict_format(line_type): | 141 def test_line2dict_format(line_type): |
| 142 """Test that the API result has the appropriate format. | 142 """Test that the API result has the appropriate format. |
| 143 | 143 |
| 144 Checks for both keys and datatypes. | 144 Checks for both keys and datatypes. |
| 145 """ | 145 """ |
| 146 position = 'start' if line_type in {'header', 'metadata'} else 'body' | 146 position = 'start' if line_type in {'header', 'metadata'} else 'body' |
| 147 data = line2dict(_TEST_EXAMPLES[line_type]['in'], position) | 147 data = line2dict(_TEST_EXAMPLES[line_type]['in'], position) |
| 148 | 148 |
| 149 assert data == _TEST_EXAMPLES[line_type]['out'] | 149 assert data == _TEST_EXAMPLES[line_type]['out'] |
| 150 | |
| 151 | |
| 152 def test_lines2dicts(): | |
| 153 """Test that the API result has the appropriate format. | |
| 154 | |
| 155 Checks for both keys and datatypes. | |
| 156 """ | |
| 157 string_list = [] | |
| 158 line_types = {b'EmptyLine': 'empty', b'Filter': 'filter_single', | |
| 159 b'Comment': 'comment', b'Include': 'include'} | |
| 160 | |
| 161 for key in _TEST_EXAMPLES.keys(): | |
|
Vasily Kuznetsov
2019/01/25 15:00:58
This is equivalent to `for key in _TEST_EXAMPLES:`
rhowell
2019/01/26 01:08:22
Done.
| |
| 162 if (_TEST_EXAMPLES[key]['out'][b'type'] != b'Header' | |
|
Vasily Kuznetsov
2019/01/25 15:00:58
You can use `... not in {b'Header', b'Metadata'}`.
rhowell
2019/01/26 01:08:22
Done.
| |
| 163 and _TEST_EXAMPLES[key]['out'][b'type'] != b'Metadata'): | |
| 164 string_list.append(_TEST_EXAMPLES[key]['in']) | |
| 165 | |
| 166 result_list = lines2dicts(string_list) | |
| 167 | |
| 168 for line in result_list: | |
| 169 line_type = line_types[line[b'type']] | |
| 170 data = line2dict(_TEST_EXAMPLES[line_type]['in'], 'start') | |
| 171 | |
| 172 assert data == _TEST_EXAMPLES[line_type]['out'] | |
|
Vasily Kuznetsov
2019/01/25 15:00:58
So in the end we compare the output of line2dict(_
rhowell
2019/01/26 01:08:22
Good idea, this test makes much more sense. I was
Vasily Kuznetsov
2019/01/28 17:47:36
This happens because the proposed code doesn't dep
rhowell
2019/01/29 01:44:47
Ah, right, makes sense. I ran into this issue when
| |
| OLD | NEW |