Skip to content

Commit d92bf4f

Browse files
committed
Add an extra test
1 parent b92fb8c commit d92bf4f

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
**Features**
66

7-
- Added `JSONPathNode.parent`, a reference the the node's parent node.
8-
- Changed `JSONPathNode.value` to be a `@property` and `setter`. When assigning to `JSONPathNode.value`, source data is updated too.
7+
- Added `JSONPathNode.parent`, a reference the the node's parent node. See [#21](https://github.com/jg-rp/python-jsonpath-rfc9535/issues/21).
8+
- Changed `JSONPathNode.value` to be a `@property` and `setter`. When assigning to `JSONPathNode.value`, source data is updated too. See [#21](https://github.com/jg-rp/python-jsonpath-rfc9535/issues/21).
99

1010
## Version 0.1.6
1111

jsonpath_rfc9535/node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
class JSONPathNode:
1818
"""A JSON-like value and its location in a JSON document.
1919
20-
Assigning to `JSONPathNode.value` will automatically mutate source data.
20+
Assigning to `JSONPathNode.value` will update and mutate source data too.
2121
Updating data after evaluating a query can invalidate existing child
2222
nodes. Use at your own risk.
2323

tests/test_issues.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,23 @@
44
def test_issue_13() -> None:
55
# This was failing with "unbalanced parentheses".
66
_q = jsonpath.compile("$[? count(@.likes[? @.location]) > 3]")
7+
8+
9+
def test_issue_21() -> None:
10+
data = {"foo": {"bar": {"baz": 42}}}
11+
node = jsonpath.find_one("$.foo.bar.baz", data)
12+
13+
expected = 42
14+
assert node is not None
15+
assert node.value == expected
16+
assert data["foo"]["bar"]["baz"] == expected
17+
18+
new_value = 99
19+
node.value = new_value
20+
assert node.value == new_value
21+
assert data["foo"]["bar"]["baz"] == new_value
22+
23+
parent = node.parent
24+
assert parent is not None
25+
assert parent.value == {"baz": new_value}
26+
assert parent.value["baz"] == new_value # type: ignore

0 commit comments

Comments
 (0)