Skip to content

Commit

Permalink
Merge pull request #150 from digital-land/test_negative_filtering
Browse files Browse the repository at this point in the history
Added a test for a regex that tests 'not in'
  • Loading branch information
ssadhu-sl authored Nov 7, 2023
2 parents 7d3c29f + 25a0d81 commit 173b61c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/unit/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,21 @@ def test_filter_in():
assert out[0]["row"] == {"reference": "2", "name": "Two"}
assert out[1]["row"] == {"reference": "3", "name": "Three"}
assert len(out) == 2


def test_negative_filtering():
pattern = {
"somefield": "^(?!Individual|\\.).*"
} # NOT starting with Individual. Watch out for the pipe character preceding the \\.
input = (
"reference,somefield\r\n" + "1,Group\r\n" + "2,Individual\r\n" + "3,Zone\r\n"
) # We want 1 and 3

phase = FilterPhase(filters=pattern)
stream = _reader(input)

out = list(phase.process(stream))

assert len(out) == 2
assert out[0]["row"] == {"reference": "1", "somefield": "Group"}
assert out[1]["row"] == {"reference": "3", "somefield": "Zone"}

0 comments on commit 173b61c

Please sign in to comment.