From 9efc28fa932ac7052b06bd4bb74376b65f1aa8ba Mon Sep 17 00:00:00 2001 From: jackeyGao Date: Thu, 1 Mar 2018 13:32:42 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=E8=AF=8D=E5=86=85?= =?UTF-8?q?=E5=AE=B9=20JSON=20=E6=96=87=E4=BB=B6=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=EF=BC=8C=E5=8E=BB=E9=99=A4=20ci.db=20=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test_poetry.py | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/test_poetry.py b/test_poetry.py index 27454ec..10aadc1 100644 --- a/test_poetry.py +++ b/test_poetry.py @@ -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()) @@ -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') ] - c = conn.cursor() - c.execute("SELECT name FROM sqlite_master WHERE type='table'") +#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文件异常" - tables = c.fetchall() - - assert len(tables) == 2, u"Sqlite文件异常" + +def main(): + test_shi_json() + test_ci_json() + + +if __name__ == '__main__': + main()