From 25a0d81a58627ec65d95ecf88c8b0fddb0f4f60e Mon Sep 17 00:00:00 2001 From: Mark Smith Date: Sat, 4 Nov 2023 09:55:55 +0000 Subject: [PATCH] Added a test for a regex that tests 'not in' --- tests/unit/test_filter.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/unit/test_filter.py b/tests/unit/test_filter.py index 83d8797d..5e1fc491 100755 --- a/tests/unit/test_filter.py +++ b/tests/unit/test_filter.py @@ -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"}