33
44from __future__ import unicode_literals
55
6+ import copy
67import doctest
7- import unittest
88import sys
9- import copy
9+ import unittest
10+
1011import jsonpointer
1112from jsonpointer import resolve_pointer , EndOfList , JsonPointerException , \
12- JsonPointer , set_pointer
13+ JsonPointer , set_pointer
1314
1415
1516class SpecificationTests (unittest .TestCase ):
1617 """ Tests all examples from the JSON Pointer specification """
1718
1819 def test_example (self ):
19- doc = {
20+ doc = {
2021 "foo" : ["bar" , "baz" ],
2122 "" : 0 ,
2223 "a/b" : 1 ,
@@ -42,7 +43,6 @@ def test_example(self):
4243 self .assertEqual (resolve_pointer (doc , "/ " ), 7 )
4344 self .assertEqual (resolve_pointer (doc , "/m~0n" ), 8 )
4445
45-
4646 def test_eol (self ):
4747 doc = {
4848 "foo" : ["bar" , "baz" ]
@@ -165,19 +165,16 @@ def test_eq_hash(self):
165165 self .assertFalse (p1 == "/something/1/b" )
166166
167167 def test_contains (self ):
168-
169168 self .assertTrue (self .ptr1 .contains (self .ptr2 ))
170169 self .assertTrue (self .ptr1 .contains (self .ptr1 ))
171170 self .assertFalse (self .ptr1 .contains (self .ptr3 ))
172171
173172 def test_contains_magic (self ):
174-
175173 self .assertTrue (self .ptr2 in self .ptr1 )
176174 self .assertTrue (self .ptr1 in self .ptr1 )
177175 self .assertFalse (self .ptr3 in self .ptr1 )
178176
179177 def test_join (self ):
180-
181178 ptr12a = self .ptr1 .join (self .ptr2 )
182179 self .assertEqual (ptr12a .path , "/a/b/c/a/b" )
183180
@@ -196,7 +193,6 @@ def test_join(self):
196193 self .assertRaises (JsonPointerException , self .ptr1 .join , 0 )
197194
198195 def test_join_magic (self ):
199-
200196 ptr12a = self .ptr1 / self .ptr2
201197 self .assertEqual (ptr12a .path , "/a/b/c/a/b" )
202198
@@ -212,6 +208,7 @@ def test_join_magic(self):
212208 ptr12e = self .ptr1 / ["a" , "b" ]
213209 self .assertEqual (ptr12e .path , "/a/b/c/a/b" )
214210
211+
215212class WrongInputTests (unittest .TestCase ):
216213
217214 def test_no_start_slash (self ):
@@ -244,7 +241,6 @@ def test_empty_path(self):
244241 self .assertEqual (doc , last )
245242 self .assertTrue (nxt is None )
246243
247-
248244 def test_path (self ):
249245 doc = {'a' : [{'b' : 1 , 'c' : 2 }, 5 ]}
250246 ptr = JsonPointer ('/a/0/b' )
@@ -256,7 +252,7 @@ def test_path(self):
256252class SetTests (unittest .TestCase ):
257253
258254 def test_set (self ):
259- doc = {
255+ doc = {
260256 "foo" : ["bar" , "baz" ],
261257 "" : 0 ,
262258 "a/b" : 1 ,
@@ -285,7 +281,7 @@ def test_set(self):
285281
286282 newdoc = set_pointer (doc , "/fud" , {}, inplace = False )
287283 newdoc = set_pointer (newdoc , "/fud/gaw" , [1 , 2 , 3 ], inplace = False )
288- self .assertEqual (resolve_pointer (newdoc , "/fud" ), {'gaw' : [1 , 2 , 3 ]})
284+ self .assertEqual (resolve_pointer (newdoc , "/fud" ), {'gaw' : [1 , 2 , 3 ]})
289285
290286 newdoc = set_pointer (doc , "" , 9 , inplace = False )
291287 self .assertEqual (newdoc , 9 )
@@ -307,14 +303,13 @@ def test_set(self):
307303 self .assertRaises (JsonPointerException , set_pointer , doc , "/fud/gaw" , 9 )
308304
309305 set_pointer (doc , "/fud" , {})
310- set_pointer (doc , "/fud/gaw" , [1 , 2 , 3 ] )
311- self .assertEqual (resolve_pointer (doc , "/fud" ), {'gaw' : [1 , 2 , 3 ]})
306+ set_pointer (doc , "/fud/gaw" , [1 , 2 , 3 ])
307+ self .assertEqual (resolve_pointer (doc , "/fud" ), {'gaw' : [1 , 2 , 3 ]})
312308
313309 self .assertRaises (JsonPointerException , set_pointer , doc , "" , 9 )
314310
315311
316312class AltTypesTests (unittest .TestCase ):
317-
318313 class Node (object ):
319314 def __init__ (self , name , parent = None ):
320315 self .name = name
@@ -349,13 +344,13 @@ def __setitem__(self, key, val):
349344 class mdict (object ):
350345 def __init__ (self , d ):
351346 self ._d = d
347+
352348 def __getitem__ (self , item ):
353349 return self ._d [item ]
354350
355351 mdict = mdict ({'root' : {'1' : {'2' : '3' }}})
356352 Node = Node
357353
358-
359354 def test_alttypes (self ):
360355 Node = self .Node
361356
0 commit comments