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

Delta Between Two Patch Sets: tests/test_rpy.py

Issue 30031558: Issue 7391 - Let rpy recursively parse filter options to dicts (Closed) Base URL: https://hg.adblockplus.org/python-abp
Left Patch Set: Address comments on Patch Set 1 and bug fixes Created March 27, 2019, 9:24 p.m.
Right Patch Set: Remove all OrderedDicts Created April 12, 2019, 6:30 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 | « abp/filters/rpy.py ('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 """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, OrderedDict as Od 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, lines2dicts 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': {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 'out': { 87 'out': {
88 b'type': b'Filter', 88 b'type': b'Filter',
89 b'text': b'foo.com,bar.com##div#ad1', 89 b'text': b'foo.com,bar.com##div#ad1',
90 b'selector': {b'type': b'css', b'value': b'div#ad1'}, 90 b'selector': {b'type': b'css', b'value': b'div#ad1'},
91 b'action': b'hide', 91 b'action': b'hide',
92 b'options': {b'domain': {b'foo.com': True, b'bar.com': True}}, 92 b'options': {b'domain': {b'foo.com': True, b'bar.com': True}},
93 }, 93 },
94 }, 94 },
95 'filter_with_sitekey_list': { 95 'filter_with_sitekey_list': {
96 'in': b'@@bla$ping,domain=foo.com|~bar.foo.com,sitekey=foo|bar', 96 'in': b'@@bla$ping,domain=foo.com|~bar.foo.com,sitekey=foo|bar',
97 'out': 97 'out': {
98 Od([(b'text', 98 b'text':
99 b'@@bla$ping,domain=foo.com|~bar.foo.com,sitekey=foo|bar'), 99 b'@@bla$ping,domain=foo.com|~bar.foo.com,sitekey=foo|bar',
100 (b'selector', {b'value': b'bla', b'type': b'url-pattern'}), 100 b'selector': {b'value': b'bla', b'type': b'url-pattern'},
101 (b'action', b'allow'), 101 b'action': b'allow',
102 (b'options', 102 b'options': {
103 Od([(b'ping', True), 103 b'ping': True,
104 (b'domain', Od([(b'foo.com', True), 104 b'domain': {b'foo.com': True,
105 (b'bar.foo.com', False)])), 105 b'bar.foo.com': False},
106 (b'sitekey', [b'foo', b'bar'])])), 106 b'sitekey': [b'foo', b'bar']},
107 (b'type', b'Filter')]), 107 b'type': b'Filter',
108 },
108 }, 109 },
109 } 110 }
110 111
111 112
112 def check_data_utf8(data): 113 def check_data_utf8(data):
113 """Check if all the strings in a dict are encoded as unicode. 114 """Check if all the strings in a dict are encoded as unicode.
114 115
115 Parameters 116 Parameters
116 ---------- 117 ----------
117 data: dict 118 data: dict
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 """Test that the API returns the correct result in the appropriate format. 190 """Test that the API returns the correct result in the appropriate format.
190 191
191 By default, lines2dicts() does not correctly parse headers and metadata. 192 By default, lines2dicts() does not correctly parse headers and metadata.
192 """ 193 """
193 tests = [t for t in _TEST_EXAMPLES.values() 194 tests = [t for t in _TEST_EXAMPLES.values()
194 if t['out'][b'type'] not in {b'Header', b'Metadata'}] 195 if t['out'][b'type'] not in {b'Header', b'Metadata'}]
195 ins = [ex['in'] for ex in tests] 196 ins = [ex['in'] for ex in tests]
196 outs = [ex['out'] for ex in tests] 197 outs = [ex['out'] for ex in tests]
197 198
198 assert lines2dicts(ins) == outs 199 assert lines2dicts(ins) == outs
LEFTRIGHT

Powered by Google App Engine
This is Rietveld