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
|