jsonpointer 3.9__tar.gz → 3.11__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {jsonpointer-3.9/jsonpointer.egg-info → jsonpointer-3.11}/PKG-INFO +1 -1
- {jsonpointer-3.9 → jsonpointer-3.11/jsonpointer.egg-info}/PKG-INFO +1 -1
- {jsonpointer-3.9 → jsonpointer-3.11}/jsonpointer.py +8 -2
- {jsonpointer-3.9 → jsonpointer-3.11}/tests.py +47 -0
- {jsonpointer-3.9 → jsonpointer-3.11}/AUTHORS +0 -0
- {jsonpointer-3.9 → jsonpointer-3.11}/LICENSE.txt +0 -0
- {jsonpointer-3.9 → jsonpointer-3.11}/MANIFEST.in +0 -0
- {jsonpointer-3.9 → jsonpointer-3.11}/README.md +0 -0
- {jsonpointer-3.9 → jsonpointer-3.11}/bin/jsonpointer +0 -0
- {jsonpointer-3.9 → jsonpointer-3.11}/doc/commandline.rst +0 -0
- {jsonpointer-3.9 → jsonpointer-3.11}/doc/index.rst +0 -0
- {jsonpointer-3.9 → jsonpointer-3.11}/doc/mod-jsonpointer.rst +0 -0
- {jsonpointer-3.9 → jsonpointer-3.11}/doc/tutorial.rst +0 -0
- {jsonpointer-3.9 → jsonpointer-3.11}/jsonpointer-stubs/__init__.pyi +0 -0
- {jsonpointer-3.9 → jsonpointer-3.11}/jsonpointer.egg-info/SOURCES.txt +0 -0
- {jsonpointer-3.9 → jsonpointer-3.11}/jsonpointer.egg-info/dependency_links.txt +0 -0
- {jsonpointer-3.9 → jsonpointer-3.11}/jsonpointer.egg-info/top_level.txt +0 -0
- {jsonpointer-3.9 → jsonpointer-3.11}/setup.cfg +0 -0
- {jsonpointer-3.9 → jsonpointer-3.11}/setup.py +0 -0
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
|
|
33
33
|
# Will be parsed by setup.py to determine package metadata
|
|
34
34
|
__author__ = 'Stefan Kögl <stefan@skoegl.net>'
|
|
35
|
-
__version__ = '3.
|
|
35
|
+
__version__ = '3.11'
|
|
36
36
|
__website__ = 'https://github.com/stefankoegl/python-json-pointer'
|
|
37
37
|
__license__ = 'Modified BSD License'
|
|
38
38
|
|
|
@@ -341,6 +341,12 @@ class JsonPointer:
|
|
|
341
341
|
|
|
342
342
|
# Else the object is a mapping or supports __getitem__(so assume custom indexing)
|
|
343
343
|
try:
|
|
344
|
+
# Check membership first so that mappings with a fallback for
|
|
345
|
+
# missing keys (e.g. defaultdict.__missing__) are not mutated and
|
|
346
|
+
# absent members are reported as missing.
|
|
347
|
+
if isinstance(doc, Mapping) and part not in doc:
|
|
348
|
+
raise KeyError(part)
|
|
349
|
+
|
|
344
350
|
return doc[part]
|
|
345
351
|
|
|
346
352
|
except KeyError:
|
|
@@ -414,7 +420,7 @@ class JsonPointer:
|
|
|
414
420
|
"""
|
|
415
421
|
|
|
416
422
|
if not isinstance(other, JsonPointer):
|
|
417
|
-
return
|
|
423
|
+
return NotImplemented
|
|
418
424
|
|
|
419
425
|
return self.parts == other.parts
|
|
420
426
|
|
|
@@ -12,6 +12,7 @@ import sys
|
|
|
12
12
|
import tempfile
|
|
13
13
|
import textwrap
|
|
14
14
|
import unittest
|
|
15
|
+
from collections import defaultdict
|
|
15
16
|
from contextlib import redirect_stderr, redirect_stdout
|
|
16
17
|
from unittest import mock
|
|
17
18
|
|
|
@@ -170,6 +171,23 @@ class ComparisonTests(unittest.TestCase):
|
|
|
170
171
|
# a pointer compares not-equal to objects of other types
|
|
171
172
|
self.assertFalse(p1 == "/something/1/b")
|
|
172
173
|
|
|
174
|
+
def test_other_types_remain_unequal(self):
|
|
175
|
+
for other in ["/a/b/c", None, 1, object()]:
|
|
176
|
+
for left, right in [(self.ptr1, other), (other, self.ptr1)]:
|
|
177
|
+
with self.subTest(left=left, right=right):
|
|
178
|
+
self.assertFalse(left == right)
|
|
179
|
+
self.assertTrue(left != right)
|
|
180
|
+
|
|
181
|
+
def test_reflected_equality(self):
|
|
182
|
+
for left, right in [(self.ptr1, mock.ANY), (mock.ANY, self.ptr1)]:
|
|
183
|
+
with self.subTest(left=left, right=right):
|
|
184
|
+
self.assertTrue(left == right)
|
|
185
|
+
|
|
186
|
+
def test_reflected_inequality(self):
|
|
187
|
+
for left, right in [(self.ptr1, mock.ANY), (mock.ANY, self.ptr1)]:
|
|
188
|
+
with self.subTest(left=left, right=right):
|
|
189
|
+
self.assertFalse(left != right)
|
|
190
|
+
|
|
173
191
|
def test_contains(self):
|
|
174
192
|
self.assertTrue(self.ptr1.contains(self.ptr2))
|
|
175
193
|
self.assertTrue(self.ptr1.contains(self.ptr1))
|
|
@@ -593,6 +611,35 @@ class AltTypesTests(unittest.TestCase):
|
|
|
593
611
|
self.assertRaises(JsonPointerException, resolve_pointer, doc, '/root/1/2/3/4')
|
|
594
612
|
|
|
595
613
|
|
|
614
|
+
class DefaultDictTests(unittest.TestCase):
|
|
615
|
+
"""Missing members of mappings with __missing__ must stay missing (#101)"""
|
|
616
|
+
|
|
617
|
+
def test_resolve_missing_returns_default(self):
|
|
618
|
+
doc = defaultdict(dict)
|
|
619
|
+
self.assertEqual(resolve_pointer(doc, '/missing', 'SENTINEL'), 'SENTINEL')
|
|
620
|
+
self.assertEqual(dict(doc), {})
|
|
621
|
+
|
|
622
|
+
def test_resolve_missing_raises(self):
|
|
623
|
+
doc = defaultdict(dict)
|
|
624
|
+
self.assertRaises(JsonPointerException, resolve_pointer, doc, '/missing')
|
|
625
|
+
self.assertEqual(dict(doc), {})
|
|
626
|
+
|
|
627
|
+
def test_resolve_existing_member(self):
|
|
628
|
+
doc = defaultdict(dict, {'foo': {'bar': 1}})
|
|
629
|
+
self.assertEqual(resolve_pointer(doc, '/foo/bar'), 1)
|
|
630
|
+
|
|
631
|
+
def test_set_without_create_raises(self):
|
|
632
|
+
doc = defaultdict(dict)
|
|
633
|
+
self.assertRaises(JsonPointerException, set_pointer, doc,
|
|
634
|
+
'/missing/child', 1)
|
|
635
|
+
self.assertEqual(dict(doc), {})
|
|
636
|
+
|
|
637
|
+
def test_set_with_create(self):
|
|
638
|
+
doc = defaultdict(dict)
|
|
639
|
+
set_pointer(doc, '/missing/child', 1, create=True)
|
|
640
|
+
self.assertEqual(dict(doc), {'missing': {'child': 1}})
|
|
641
|
+
|
|
642
|
+
|
|
596
643
|
class CommandLineTests(unittest.TestCase):
|
|
597
644
|
""" Tests the jsonpointer command line utility """
|
|
598
645
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|