Skip to content

Commit b9bf601

Browse files
committed
add more testcase
1 parent 9fcab41 commit b9bf601

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

tests/test_jsontool.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ def test_unicode(self):
7676
expobj = expand(data)
7777
assert expobj
7878

79+
def test_expand_with_safe(self):
80+
data = {
81+
"www.a.com":{"qps":100,"p95":20},
82+
"api.a.com":{"qps":100,"p95":20,"p99":100},
83+
}
84+
expobj = expand(data, safe=True)
85+
self.assertEqual(expobj['api.a.com\\.p95'], 20)
86+
self.assertEqual(expobj['api.a.com\\.p99'], 100)
87+
88+
origin = restore(expobj, safe=True)
89+
self.assertEqual(origin, data)
90+
7991

8092
class TestConvertJSON(unittest.TestCase):
8193

@@ -89,3 +101,14 @@ def test_convert_expand(self):
89101

90102
fin.close()
91103
fout.close()
104+
105+
def test_convert_restore(self):
106+
fin = io.BytesIO('{"a.b": 3}\n{"a.c": 4}\n')
107+
fout = io.BytesIO()
108+
109+
convert_json(fin, fout, type="restore")
110+
111+
self.assertEqual('{"a": {"b": 3}}\n{"a": {"c": 4}}\n', fout.getvalue())
112+
113+
fin.close()
114+
fout.close()

0 commit comments

Comments
 (0)