@@ -101,16 +101,27 @@ def test_op_remove_baz_list_member():
101
101
assert obj ['bar' ] != 'potatoes'
102
102
103
103
104
- def test_op_remove_fail_on_nonexistent_member ():
105
- """Should raise an exception if removing a non-existent object member ."""
104
+ def test_op_remove_fail_on_nonexistent_path ():
105
+ """Should raise an exception if referencing a non-existent tree to remove ."""
106
106
patches = [
107
- {"op" : "remove" , "path" : "/0/foo/four " }
107
+ {"op" : "remove" , "path" : "/0/qux/one " }
108
108
]
109
109
jp = JSONPatcher (sample_json , * patches )
110
110
with pytest .raises (PathError ):
111
111
jp .patch ()
112
112
113
113
114
+ def test_op_remove_unchanged_on_nonexistent_member ():
115
+ """Should not raise an exception if referencing a non-existent leaf to remove."""
116
+ patches = [
117
+ {"op" : "remove" , "path" : "/0/foo/four" }
118
+ ]
119
+ jp = JSONPatcher (sample_json , * patches )
120
+ changed , tested = jp .patch ()
121
+ assert changed is False
122
+ assert tested is None
123
+
124
+
114
125
# OPERATION: REPLACE
115
126
def test_op_replace_foo_three ():
116
127
"""Should replace the value for the 'three' member in 'foo'."""
@@ -124,8 +135,8 @@ def test_op_replace_foo_three():
124
135
assert jp .obj [0 ]['foo' ]['three' ] == 'booyah'
125
136
126
137
127
- def test_op_replace_fail_on_nonexistent_member ():
128
- """Should raise an exception if replacing a non-existent object member ."""
138
+ def test_op_replace_fail_on_nonexistent_path_or_member ():
139
+ """Should raise an exception if any part of the referenced path does not exist (RFC 6902) ."""
129
140
patches = [
130
141
{"op" : "replace" , "path" : "/0/foo/four" , "value" : 4 }
131
142
]
@@ -161,14 +172,15 @@ def test_op_move_baz_list_foo():
161
172
assert len (jp .obj [0 ]['foo' ]['fruits' ]) == 3
162
173
163
174
164
- def test_op_move_fail_on_nonexistent ():
165
- """Should raise an exception if moving a non-existent object member."""
175
+ def test_op_move_unchanged_on_nonexistent ():
176
+ """Should not raise an exception if moving a non-existent object member."""
166
177
patches = [
167
178
{"op" : "move" , "from" : "/0/foo/four" , "path" : "/1/bar/four" }
168
179
]
169
180
jp = JSONPatcher (sample_json , * patches )
170
- with pytest .raises (PathError ):
171
- jp .patch ()
181
+ changed , tested = jp .patch ()
182
+ assert changed is False
183
+ assert tested is None
172
184
173
185
174
186
def test_op_move_foo_object_end_of_list ():
0 commit comments