Skip to content

Commit

Permalink
test: 增加词内容 JSON 文件校验,去除 ci.db 文件校验
Browse files Browse the repository at this point in the history
  • Loading branch information
jackeyGao committed Mar 1, 2018
1 parent fc17a59 commit 9efc28f
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions test_poetry.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#! -*- coding: utf-8 -*-
import os, json, sqlite3

def check_json(f):
filepath = os.path.join('./json', f)
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())
Expand All @@ -11,24 +14,39 @@ def check_json(f):
assert False, u"校验(%s)失败" % f


def test_json():
def test_shi_json():
"""
测试古诗JSON文件是否有效
"""
map(check_json, os.listdir('./json'))

[ check_json(f, './json') for f in os.listdir('./json') ]


def test_sqlite():
def test_ci_json():
"""
测试ci数据库文件是否有效
测试词JSON文件是否有效
"""
conn = sqlite3.connect('./ci/ci.db')
[ 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文件异常"


c = conn.cursor()
def main():
test_shi_json()
test_ci_json()

c.execute("SELECT name FROM sqlite_master WHERE type='table'")

tables = c.fetchall()

assert len(tables) == 2, u"Sqlite文件异常"
if __name__ == '__main__':
main()

0 comments on commit 9efc28f

Please sign in to comment.