Skip to content

Commit e05fbc2

Browse files
committed
ext classes support all examples
1 parent e99ff85 commit e05fbc2

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

jsonpath_ng/ext/filter.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ def update(self, data, val):
6464
else:
6565
data[index] = val
6666
return data
67-
67+
68+
def __eq__(self, other):
69+
return (isinstance(other, Filter) and
70+
self.expressions == other.expressions)
71+
6872
def __repr__(self):
6973
return '%s(%r)' % (self.__class__.__name__, self.expressions)
7074

@@ -108,7 +112,7 @@ def find(self, datum):
108112
return found
109113

110114
def __eq__(self, other):
111-
return (isinstance(other, Filter) and
115+
return (isinstance(other, Expression) and
112116
self.target == other.target and
113117
self.op == other.op and
114118
self.value == other.value)

tests/test_parser.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99

1010
import pytest
1111

12+
from jsonpath_ng.ext.filter import Filter, Expression
13+
from jsonpath_ng.ext.parser import (
14+
ExtendedJsonPathLexer,
15+
ExtentedJsonPathParser,
16+
)
1217
from jsonpath_ng.jsonpath import *
13-
from jsonpath_ng.lexer import JsonPathLexer
14-
from jsonpath_ng.parser import JsonPathParser
1518

1619

1720
# TODO: This will be much more effective with a few regression tests and `arbitrary` parse . pretty testing
@@ -22,11 +25,11 @@ def setup_module():
2225

2326

2427
def check_parse_case(string, parsed):
25-
parser = JsonPathParser(
28+
parser = ExtentedJsonPathParser(
2629
debug=True,
2730
# Note that just manually passing token streams avoids this
2831
# dep, but that sucks
29-
lexer_class=lambda: JsonPathLexer(debug=False),
32+
lexer_class=lambda: ExtendedJsonPathLexer(debug=False),
3033
)
3134
assert parser.parse(string) == parsed
3235

@@ -91,10 +94,14 @@ def test_nested(string, parsed):
9194
Child(Descendants(Root(), Fields('book')), Slice(end=2))),
9295
9396
# Filter all books with ISBN number
94-
# ("$..book[?(@.isbn)]", None), # Not implemented
97+
("$..book[?(@.isbn)]",
98+
Child(Descendants(Root(), Fields('book')),
99+
Filter([Expression(Child(This(), Fields('isbn')), None, None)]))),
95100
96101
# Filter all books cheaper than 10
97-
# ("$..book[?(@.price<10)]", None), # Not implemented
102+
("$..book[?(@.price<10)]",
103+
Child(Descendants(Root(), Fields('book')),
104+
Filter([Expression(Child(This(), Fields('price')), '<', 10)]))),
98105
99106
# All members of JSON structure
100107
("$..*", Descendants(Root(), Fields('*'))),

0 commit comments

Comments
 (0)