From 8052b0583296ae2ede3c36ebcb0f7a782497ddce Mon Sep 17 00:00:00 2001 From: rsmith013 Date: Fri, 9 Jul 2021 17:08:43 +0100 Subject: [PATCH] refactoring LIKE predicate from cql-json to match OGC docs. closes #20 --- pygeofilter/parsers/cql_json/parser.py | 12 ++++++------ tests/parsers/cql_json/test_parser.py | 24 ++++++++++-------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/pygeofilter/parsers/cql_json/parser.py b/pygeofilter/parsers/cql_json/parser.py index 4e20230..ee45a0b 100644 --- a/pygeofilter/parsers/cql_json/parser.py +++ b/pygeofilter/parsers/cql_json/parser.py @@ -164,12 +164,12 @@ def walk_cql_json(node: dict, is_temporal: bool = False) -> ast.Node: elif name == 'like': return ast.Like( - walk_cql_json(value['like'][0]), - value['like'][1], - nocase=value.get('nocase', True), - wildcard=value.get('wildcard', '%'), - singlechar=value.get('singleChar', '.'), - escapechar=value.get('escapeChar', '\\'), + walk_cql_json(value[0]), + value[1], + nocase=node.get('nocase', True), + wildcard=node.get('wildcard', '%'), + singlechar=node.get('singleChar', '.'), + escapechar=node.get('escapeChar', '\\'), not_=False, ) diff --git a/tests/parsers/cql_json/test_parser.py b/tests/parsers/cql_json/test_parser.py index 30fdabf..03ef7a8 100644 --- a/tests/parsers/cql_json/test_parser.py +++ b/tests/parsers/cql_json/test_parser.py @@ -140,13 +140,11 @@ def test_attribute_between_negative_positive(): def test_string_like(): result = parse({ - "like": { - "like": [ - {"property": "attr"}, - "some%", - ], - "nocase": False, - } + "like": [ + {"property": "attr"}, + "some%", + ], + "nocase": False, }) assert result == ast.Like( ast.Attribute('attr'), @@ -161,13 +159,11 @@ def test_string_like(): def test_string_ilike(): result = parse({ - "like": { - "like": [ - {"property": "attr"}, - "some%", - ], - "nocase": True, - } + "like": [ + {"property": "attr"}, + "some%", + ], + "nocase": True, }) assert result == ast.Like( ast.Attribute('attr'),