#coding=utf-8
import os
import json
CUR_DIR = os.path.dirname(os.path.abspath(__file__))
TEMPLATE_PATH = os.path.join(CUR_DIR, 'template.html')
def generate_json(data, path=None):
? ? path = path or os.path.join(os.getcwd(), 'report.json')
? ? with open(path, 'w') as f:
? ? ? ? f.write(json.dumps(data, indent=2, ensure_ascii=False))
def generate_html(data, path=None):
? ? """
? ? 根據(jù)測(cè)試結(jié)果生成 html
? ? """
? ? with open(TEMPLATE_PATH) as f:
? ? ? ? content = f.read().replace('${resultData}',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? json.dumps(data))
? ? path = path or os.path.join(os.getcwd(), 'report.html')
? ? with open(path, 'w') as f:
? ? ? ? f.write(content)