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

Delta Between Two Patch Sets: tests/test_rpy.py

Issue 29988581: Issue 7230 - python-abp line2dict vectorization (Closed) Base URL: https://hg.adblockplus.org/python-abp/
Left Patch Set: Switch from dict to list Created Jan. 25, 2019, 12:27 a.m.
Right Patch Set: Separate tests Created Jan. 29, 2019, 1:43 a.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
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 150
151 151
152 def test_lines2dicts(): 152 def test_lines2dicts_start_mode():
153 """Test that the API result has the appropriate format. 153 """Test that the API returns the correct result in the appropriate format.
154 154
155 Checks for both keys and datatypes. 155 Checks for 'start' mode, which can handle headers and metadata.
156 """ 156 """
157 string_list = [] 157 tests = [t for t in _TEST_EXAMPLES.values()]
158 line_types = {b'EmptyLine': 'empty', b'Filter': 'filter_single', 158 ins = [ex['in'] for ex in tests]
159 b'Comment': 'comment', b'Include': 'include'} 159 outs = [ex['out'] for ex in tests]
160 160
161 for key in _TEST_EXAMPLES.keys(): 161 assert lines2dicts(ins, 'start') == outs
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 162
166 result_list = lines2dicts(string_list)
167 163
168 for line in result_list: 164 def test_lines2dicts_default():
169 line_type = line_types[line[b'type']] 165 """Test that the API returns the correct result in the appropriate format.
170 data = line2dict(_TEST_EXAMPLES[line_type]['in'], 'start')
171 166
172 assert data == _TEST_EXAMPLES[line_type]['out'] 167 By default, lines2dicts() does not correctly parse headers and metadata.
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
168 """
169 tests = [t for t in _TEST_EXAMPLES.values()
170 if t['out'][b'type'] not in {b'Header', b'Metadata'}]
171 ins = [ex['in'] for ex in tests]
172 outs = [ex['out'] for ex in tests]
173
174 assert lines2dicts(ins) == outs
LEFTRIGHT

Powered by Google App Engine
This is Rietveld