|
7 | 7 |
|
8 | 8 | import jsonpath |
9 | 9 | from jsonpath import JSONPointer |
| 10 | +from jsonpath import JSONPointerError |
10 | 11 | from jsonpath import JSONPointerIndexError |
11 | 12 | from jsonpath import JSONPointerResolutionError |
12 | 13 | from jsonpath import JSONPointerTypeError |
@@ -117,9 +118,9 @@ def test_resolve_with_missing_parent() -> None: |
117 | 118 |
|
118 | 119 | def test_resolve_with_missing_target() -> None: |
119 | 120 | data = {"some": {"thing": [1, 2, 3]}} |
120 | | - pointer = JSONPointer("some/other") |
| 121 | + pointer = JSONPointer("/some/other") |
121 | 122 | parent, rv = pointer.resolve_parent(data) |
122 | | - assert parent == data |
| 123 | + assert parent == data["some"] |
123 | 124 | assert rv == UNDEFINED |
124 | 125 |
|
125 | 126 |
|
@@ -204,3 +205,17 @@ def test_index_with_leading_zero() -> None: |
204 | 205 | pointer = JSONPointer("/some/thing/01") |
205 | 206 | with pytest.raises(JSONPointerTypeError): |
206 | 207 | pointer.resolve_parent(data) |
| 208 | + |
| 209 | + |
| 210 | +def test_pointer_without_leading_slash() -> None: |
| 211 | + with pytest.raises(JSONPointerError): |
| 212 | + JSONPointer("some/thing/01") |
| 213 | + |
| 214 | + with pytest.raises(JSONPointerError): |
| 215 | + JSONPointer("nosuchthing") |
| 216 | + |
| 217 | + |
| 218 | +def test_pointer_with_leading_whitespace() -> None: |
| 219 | + data = {"some": {"thing": [1, 2, 3]}} |
| 220 | + pointer = JSONPointer(" /some/thing/0") |
| 221 | + assert pointer.resolve(data) == 1 |
0 commit comments