Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Added more field tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roll committed Jun 28, 2020
1 parent 27252c7 commit 3f881a2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions data/matrix.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
f1,f2,f3,f4
11,12,13,14
21,22,23,24
31,32,33,34
41,42,43,44
42 changes: 42 additions & 0 deletions tests/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,48 @@ def test_stream_limit_offset_fields():
]


def test_stream_matrix_pick_fields():
with Stream('data/matrix.csv', headers=1, pick_fields=[2, 'f3']) as stream:
assert stream.headers == ['f2', 'f3']
assert stream.read() == [['12', '13'], ['22', '23'], ['32', '33'], ['42', '43']]


def test_stream_matrix_pick_fields_regex():
with Stream('data/matrix.csv', headers=1, pick_fields=[{'type': 'regex', 'value': 'f[23]'}]) as stream:
assert stream.headers == ['f2', 'f3']
assert stream.read() == [['12', '13'], ['22', '23'], ['32', '33'], ['42', '43']]


def test_stream_matrix_skip_fields():
with Stream('data/matrix.csv', headers=1, skip_fields=[1, 'f4']) as stream:
assert stream.headers == ['f2', 'f3']
assert stream.read() == [['12', '13'], ['22', '23'], ['32', '33'], ['42', '43']]


def test_stream_matrix_skip_fields_regex():
with Stream('data/matrix.csv', headers=1, skip_fields=[{'type': 'regex', 'value': 'f[14]'}]) as stream:
assert stream.headers == ['f2', 'f3']
assert stream.read() == [['12', '13'], ['22', '23'], ['32', '33'], ['42', '43']]


def test_stream_matrix_limit_fields():
with Stream('data/matrix.csv', headers=1, limit_fields=1) as stream:
assert stream.headers == ['f1']
assert stream.read() == [['11'], ['21'], ['31'], ['41']]


def test_stream_matrix_offset_fields():
with Stream('data/matrix.csv', headers=1, offset_fields=3) as stream:
assert stream.headers == ['f4']
assert stream.read() == [['14'], ['24'], ['34'], ['44']]


def test_stream_matrix_limit_and_offset_fields():
with Stream('data/matrix.csv', headers=1, limit_fields=2, offset_fields=1) as stream:
assert stream.headers == ['f2', 'f3']
assert stream.read() == [['12', '13'], ['22', '23'], ['32', '33'], ['42', '43']]


# Pick/skip/limit/offset rows

def test_stream_pick_rows():
Expand Down

0 comments on commit 3f881a2

Please sign in to comment.