forked from chinese-poetry/chinese-poetry
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_poetry.py
52 lines (40 loc) · 1 KB
/
test_poetry.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
43
44
45
46
47
48
49
50
51
52
#! -*- coding: utf-8 -*-
import os, json, sqlite3
def check_json(f, _dir):
if not f.endswith('.json'):
return True
filepath = os.path.join(_dir, f)
with open(filepath) as file:
try:
_ = json.loads(file.read())
return True
except:
assert False, u"校验(%s)失败" % f
def test_shi_json():
"""
测试古诗JSON文件是否有效
"""
[ check_json(f, './json') for f in os.listdir('./json') ]
def test_ci_json():
"""
测试词JSON文件是否有效
"""
[ check_json(f, './ci') for f in os.listdir('./ci') ]
#def test_sqlite():
# """
# 测试ci数据库文件是否有效
# """
# conn = sqlite3.connect('./ci/ci.db')
#
# c = conn.cursor()
#
# c.execute("SELECT name FROM sqlite_master WHERE type='table'")
#
# tables = c.fetchall()
#
# assert len(tables) == 2, u"Sqlite文件异常"
def main():
test_shi_json()
test_ci_json()
if __name__ == '__main__':
main()