Skip to content

Commit

Permalink
Merge 3aa9794 into 4d194d2
Browse files Browse the repository at this point in the history
  • Loading branch information
snopoke committed Jun 25, 2021
2 parents 4d194d2 + 3aa9794 commit 84eccba
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 17 deletions.
8 changes: 4 additions & 4 deletions commcare_export/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import six
from itertools import chain

from jsonpath_rw import jsonpath
from jsonpath_rw.parser import parse as parse_jsonpath
from jsonpath_ng import jsonpath
from jsonpath_ng.parser import parse as parse_jsonpath

from commcare_export.jsonpath_utils import split_leftmost
from commcare_export.misc import unwrap, unwrap_val
Expand Down Expand Up @@ -183,7 +183,7 @@ def __init__(self, bindings=None):
self.__bindings = bindings or {}
self.__restrict_to_root = bool(jsonpath.Fields("__root_only").find(self.__bindings))

# Currently hardcoded because it is a global is jsonpath-rw
# Currently hardcoded because it is a global is jsonpath-ng
# Probably not widely used, but will require refactor if so
jsonpath.auto_id_field = "id"

Expand All @@ -208,7 +208,7 @@ def lookup(self, name):

def iterator(jsonpath_expr=jsonpath_expr): # Capture closure
for datum in jsonpath_expr.find(self.__bindings):
# HACK: The auto id from jsonpath_rw is good, but we lose it when we do .value here,
# HACK: The auto id from jsonpath_ng is good, but we lose it when we do .value here,
# so just slap it on if not present
if isinstance(datum.value, dict) and 'id' not in datum.value:
datum.value['id'] = jsonpath.AutoIdForDatum(datum).value
Expand Down
6 changes: 3 additions & 3 deletions commcare_export/excel_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import re
from collections import defaultdict, namedtuple

from jsonpath_rw.lexer import JsonPathLexerError
from jsonpath_ng.lexer import JsonPathLexerError
from six.moves import xrange

from jsonpath_rw import jsonpath
from jsonpath_rw.parser import parse as parse_jsonpath
from jsonpath_ng import jsonpath
from jsonpath_ng.parser import parse as parse_jsonpath

from commcare_export.exceptions import LongFieldsException, MissingColumnException, ReservedTableNameException
from commcare_export.jsonpath_utils import split_leftmost
Expand Down
2 changes: 1 addition & 1 deletion commcare_export/jsonpath_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from jsonpath_rw import jsonpath
from jsonpath_ng import jsonpath


def split_leftmost(jsonpath_expr):
Expand Down
2 changes: 1 addition & 1 deletion commcare_export/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import hashlib
import inspect
import io
from jsonpath_rw import jsonpath
from jsonpath_ng import jsonpath
from commcare_export.repeatable_iterator import RepeatableIterator


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def run_tests(self):
install_requires = [
'alembic',
'argparse',
'jsonpath-rw>=1.2.1',
'jsonpath-ng~=1.5',
'openpyxl==2.5.12',
'python-dateutil',
'requests',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_commcare_minilinq.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
from itertools import *

from jsonpath_rw import jsonpath
from jsonpath_ng import jsonpath

from commcare_export.checkpoint import CheckpointManagerWithDetails
from commcare_export.minilinq import *
Expand Down
11 changes: 5 additions & 6 deletions tests/test_minilinq.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_eval_reference(self):
self.check_case(Reference("foo.$.baz").eval(JsonPathEnv({'foo': [2], 'baz': 3})), [3])

def test_eval_auto_id_reference(self):
"Test that we have turned on the jsonpath_rw.jsonpath.auto_id field properly"
"Test that we have turned on the jsonpath_ng.jsonpath.auto_id field properly"
env = BuiltInEnv()

self.check_case(Reference("foo.id").eval(JsonPathEnv({'foo': [2]})), ['foo'])
Expand All @@ -55,7 +55,7 @@ def test_eval_auto_id_reference(self):

def test_eval_auto_id_reference_nested(self):
# this test is documentation of existing (weird) functionality
# that results from a combination of jsonpath_rw auto_id feature and
# that results from a combination of jsonpath_ng auto_id feature and
# JsonPathEnv.lookup (which adds an additional auto ID for some reason).
env = JsonPathEnv({})

Expand All @@ -78,7 +78,7 @@ def test_eval_auto_id_reference_nested(self):
# as follows:
# '1.bar.1.bar.[0]' -> '1.bar.[0]'

# With the change above AND a change to jsonpath_rw to prevent converting IDs that exist into
# With the change above AND a change to jsonpath_ng to prevent converting IDs that exist into
# auto IDs (see https://github.com/kennknowles/python-jsonpath-rw/pull/96) we get the following:
# Reference("id"):
# '1.bar.bazzer' -> 'bazzer'
Expand Down Expand Up @@ -118,18 +118,17 @@ def test_value_or_root_empty_dict(self):
"bar": {},
}
self._test_value_or_root([Reference('id'), Reference('baz'), Reference('$.foo')], data, [
['1.bar.1.bar.[0]', [], "I am foo"], # weird ID here due to bug in jsonpath
['1', [], "I am foo"],
])

@pytest.mark.skip(reason="fails with TypeError from jsonpath")
def test_value_or_root_None(self):
"""Should use the root object if the child is None"""
data = {
"id": 1,
"bar": None,
}
self._test_value_or_root([Reference('id'), Reference('baz')], data, [
['1.bar.[0]', []], # weird ID here due to bug in jsonpath
['1', []],
])

def test_value_or_root_missing(self):
Expand Down

0 comments on commit 84eccba

Please sign in to comment.