File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ import os
2
+ import json
3
+
4
+ from fsoft_diff_patch import diff , patch
5
+
6
+ # for all directories in ../data directory, run the test
7
+ data_dir = os .path .join (os .path .dirname (__file__ ), '../data' )
8
+ dirs = sorted (os .listdir (data_dir ))
9
+
10
+ for dir in dirs :
11
+ # write dir name, but keep the cursor at the same line
12
+ print (f"Testing: { dir } ... " , end = "" )
13
+
14
+ file01 = os .path .join (data_dir , dir , '01.json' )
15
+ file02 = os .path .join (data_dir , dir , '02.json' )
16
+
17
+ # read file 01.json and 02.json from the directory
18
+ with open (file01 , 'r' ) as f :
19
+ obj01 = json .load (f )
20
+ with open (file02 , 'r' ) as f :
21
+ obj02 = json .load (f )
22
+
23
+ # diff obj01 and obj02 and create a diffData object
24
+ diff_data = diff (obj01 , obj02 )
25
+
26
+ # apply diffData to obj01 and create a new object
27
+ patched_obj01 = patch (obj01 , diff_data )
28
+
29
+ # check if patched_obj01 is equal to obj02
30
+ if json .dumps (patched_obj01 ) != json .dumps (obj02 ):
31
+ print ("FAILED" )
32
+ else :
33
+ print ("OK" )
You can’t perform that action at this time.
0 commit comments