Closed christopherjwhite closed 10 years ago
The patch looks good in general, but please fix the tests for Python 3.2 and 3.3 (see https://travis-ci.org/stefankoegl/python-json-pointer/builds/11633865)
Hmm. The doctests are failing. In 2.7 the strings embedded in the objects are converted to unicode, thus come out with u'anArray' whereas in 3.x they just print out as strings without the u prefix.
I don't have a lot of experience with 3.2. The simple fix is to drop the examples from the docstrings, but not sure if that means I'm hiding something.
I'll research further. Let me know if you have encountered this before and have a better solution.
...cj
On 9/21/13 2:28 PM, Stefan Kögl wrote:
The patch looks good in general, but please fix the tests for Python 3.2 and 3.3 (see https://travis-ci.org/stefankoegl/python-json-pointer/builds/11633865)
— Reply to this email directly or view it on GitHub https://github.com/stefankoegl/python-json-pointer/pull/5#issuecomment-24868055.
This is apparently a somewhat known issue and I could find no clean solution. It apparently looks better in Python 3.3. As such, I took the easy route and simply commented out those example commands so that they don't run at all, thus cannot fail. Unfortunate, but other solutions look rather horribly complex just for 2 examples. Hopefully you're cool with it this way.
Commenting out docstrings is not really a nice solution...
Instead of
>>> set_pointer(obj, '/foo/anArray/0/prop', 55)
{'foo': {'another prop': {'baz': 'A string'}, 'anArray': [{'prop': 55}]}}
please try something like
>>> set_pointer(obj, '/foo/anArray/0/prop', 55) == {'foo': {'another prop': {'baz': 'A string'}, 'anArray': [{'prop': 55}]}}
True
Good suggestion, that seems to work well!
...cj
On 9/22/13 5:22 AM, Stefan Kögl wrote:
Commenting out docstrings is not really a nice solution...
Instead of
set_pointer(obj, '/foo/anArray/0/prop', 55) {'foo': {'another prop': {'baz': 'A string'}, 'anArray': [{'prop': 55}]}}
please try something like
set_pointer(obj, '/foo/anArray/0/prop', 55) == {'foo': {'another prop': {'baz': 'A string'}, 'anArray': [{'prop': 55}]}} True
— Reply to this email directly or view it on GitHub https://github.com/stefankoegl/python-json-pointer/pull/5#issuecomment-24878776.
I've squashed your commits into one, fixed some whitespace-only changes, and merged everything into master: 19f9f2152480c72e0f83f48930088bd22f1eded5.
Thanks :)
This adds support to modify documents based on jsonpointers as well as support for any object whose class supports the necessary methods getitem (for resolving pointers to get data), and setitem (for the set_pointer operation).
See the tests for an example.
I considered wrapping the support for non-dict/list types via getitem with a boolean "check_getitem", but in the end I figured it was unnecessary complexity.