-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_json2txttree.py
42 lines (39 loc) · 1.75 KB
/
test_json2txttree.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import unittest
import json
import json2txttree as j2t
class SimpleTest(unittest.TestCase):
def test_json2txttree(self):
with open('sample.json', 'r') as jsonfile:
data = json.load(jsonfile)
tree = j2t.json2txttree(data)
tree_exp = '└─ (object)\n' + \
' ├─ "name" (string)\n' + \
' ├─ "age" (number)\n' + \
' ├─ "languages" (array)\n' + \
' │ └─ (string)\n' + \
' ├─ "subjects" (object)\n' + \
' │ ├─ "Math" (number)\n' + \
' │ └─ "Science" (number)\n' + \
' └─ "ids" (array)\n' + \
' └─ (object)\n' + \
' ├─ "name" (string)\n' + \
' └─ "number" (string)\n'
self.assertEqual(tree_exp, tree)
def test_json2txttable(self):
with open('sample.json', 'r') as jsonfile:
data = json.load(jsonfile)
table = j2t.json2txttable(data)
table_exp = '| Field | Data type | Details |\n' + \
'| ----- | --------- | ------- |\n' + \
'| `name` | `string` | - |\n' + \
'| `age` | `number` | - |\n' + \
'| `languages` | `array` | - |\n' + \
'| `subjects` | `object` | - |\n' + \
'| `Math` | `number` | - |\n' + \
'| `Science` | `number` | - |\n' + \
'| `ids` | `array` | - |\n' + \
'| `name` | `string` | - |\n' + \
'| `number` | `string` | - |\n'
self.assertEqual(table_exp, table)
if __name__ == '__main__':
unittest.main()