Skip to content

Commit 1c26185

Browse files
authored
Merge pull request #1 from fsoft72/python-tests
Add test_suite.py in the python dir test
2 parents aa16428 + 0e858c2 commit 1c26185

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/python/test_suite.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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")

0 commit comments

Comments
 (0)