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

Unified Diff: tests/test_rpy.py

Issue 29988581: Issue 7230 - python-abp line2dict vectorization (Closed) Base URL: https://hg.adblockplus.org/python-abp/
Patch Set: Switch from dict to list Created Jan. 25, 2019, 12:27 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« abp/filters/rpy.py ('K') | « abp/filters/rpy.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/test_rpy.py
===================================================================
--- a/tests/test_rpy.py
+++ b/tests/test_rpy.py
@@ -20,7 +20,7 @@
import pytest
import sys
-from abp.filters.rpy import tuple2dict, line2dict
+from abp.filters.rpy import tuple2dict, line2dict, lines2dicts
_SAMPLE_TUPLE = namedtuple('tuple', 'foo,bar')
@@ -147,3 +147,26 @@
data = line2dict(_TEST_EXAMPLES[line_type]['in'], position)
assert data == _TEST_EXAMPLES[line_type]['out']
+
+
+def test_lines2dicts():
+ """Test that the API result has the appropriate format.
+
+ Checks for both keys and datatypes.
+ """
+ string_list = []
+ line_types = {b'EmptyLine': 'empty', b'Filter': 'filter_single',
+ b'Comment': 'comment', b'Include': 'include'}
+
+ 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.
+ 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.
+ and _TEST_EXAMPLES[key]['out'][b'type'] != b'Metadata'):
+ string_list.append(_TEST_EXAMPLES[key]['in'])
+
+ result_list = lines2dicts(string_list)
+
+ for line in result_list:
+ line_type = line_types[line[b'type']]
+ data = line2dict(_TEST_EXAMPLES[line_type]['in'], 'start')
+
+ 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
« abp/filters/rpy.py ('K') | « abp/filters/rpy.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld