1Python⽣成⾼质量Html⽂件:Pyh模块+Bootstrap框架
⼀,介绍
QQ交流:585499566
本⽂的⽬的是怎么使⽤Pyh+Bootstrap快速⽣成简约,⼤⽅,清新的Html页⾯,涉及到的技能:Python⼩⽩技能,Pyh会阅读中⽂⽂档,Html基础,Bootstrap能阅读懂中⽂⽂档
Python:当然是Python3了...
功能介绍:
⾃动格式化HTML标签
⾼度可定制
完全识别CSS和Javascript
⾃动闭合标签
⾯向对象的HTML编写⽅式
这⾥让你们看下“丑⼋怪”与“美少⼥”的对⽐:
是不是变的美了很多啊,啊,你说还不太美,想变成“西施”,那就需要你再帮帮它化下妆了......这好像证明了:天下了没有丑⼥⼈,只有懒⼥⼈⼆、实操
说的再多,却不贴代码,就是耍流氓,耽误阅读者的时间,浪费别⼈的青春
1#!/usr/bin/env python
2# -*- coding:utf-8 -*-
3
4from pyh import *
5
6 page = PyH('接⼝测试报告') #第⼀步:需要先⽣成含标题的HTML模板
7 page.addCSS('cdn.bootcss/bootstrap/3.3.7/css/bootstrap.min.css') #第⼆步:需要加载我们要使⽤的Bootstrap模板css⽂件,需要的话还可以加载js
8 Container = page << body(id='Body', cl='bg-warning') << div(id="container",cl="container") #第三步:通过移位符“<<”,来⽣成所属标签;“<<”左侧最终必须是page
9
10# 报告标题 start
11 Headrow = Container << div(id="Headrow", cl="row")
12 Headrow << h1(id="HeadH1",align="center") << strong("API_AutoTest_Report ",id="HeadTxt") + small("Sonny.zhang", id="author")
13 Headrow << br()
14# 报告标题 end
15
16# 数据统计 start
17 Totalrow = Container << div(id="Totalrow", cl="Totalrow") << div(cl="jumbotron")
18# --测试使⽤时间,测试⽤例总数--
19 test_time_txt = ["测试总耗时:", "0:00:04.307585"]
20 case_num = ["⽤例总数:", "7"]
21 UTimerow = Totalrow << div(id="UTimerow", cl="row")
22 UTimerow << div(cl="col-xs-12 col-md-6") << p(role="presentation") << span(test_time_txt[0]) << span(test_time_txt[1], cl="label label-default")
23 UTimerow << div(cl="col-xs-12 col-md-6") << p(role="presentation") << span(case_num[0]) << span(case_num[1],cl="label label-primary")
24# --⽤例失败成功统计--
25 Num1_txt = ["成功⽤例数(Pass):", "3"]
26 Num2_txt = ["失败⽤例数(Fail):", "2"]
27 Num3_txt = ["出错⽤例数(Error):", "2"]
28 Num4_txt = ["未执⾏⽤例数(Block):", "1"]
29 Amountrow = Totalrow << div(id="Amountrow", cl="row")
30 Num1 = Amountrow << div(id="Num1", cl="col-xs-12 col-md-3") << p(role="presentation") << span() << small(Num1_txt[0]) << span(Num1_txt[1], cl="label label-success")
31 Num2 = Amountrow << div(id="Num2", cl="col-xs-12 col-md-3") << p(role="presentation") << span() << small(Num2_txt[0]) << span(Num2_txt[1], cl="label label-danger")
32 Num3 = Amountrow << div(id="Num3", cl="col-xs-12 col-md-3") << p(role="presentation") << span() << small(Num3_txt[0]) << span(Num3_txt[1], cl="label label-warning")
33 Num4 = Amountrow << div(id="Num4", cl="col-xs-12 col-md-3") << p(role="presentation") << span() << small(Num4_txt[0]) << span(Num4_txt[1], cl="label label-default")
34# 数据统计 end
35
36# 测试计划 start
37 Plans = Container << div(id="plans", cl="row")
38# --栏⽬标题--
39 plans_title = "测试⽤例摘要"
40 PlansTitle = Plans << div(id="plans-title", cl="panel panel-primary") << div(cl="panel-heading") << strong() << center(plans_title, cl="text-uppercase")
41
42# --⼀个测试计划-- start
43 Plan1 = Plans << div(id="plan1", cl="col-xs-12 col-md-12") << table(cl="table table-striped")
44# ---⼀个标题--
45 plan1_title = "测试计划【项⽬名称:APItest, 计划名称:user_operation】"
46 Plan1 << center() << caption(plan1_title)
47# --⼀个列表--
48# 表头
49 thead1 = ["ID", "执⾏编号", "⽤例ID", "⽤例外部ID", "⽤例名称", "⽤例套件", "执⾏结果", "运⾏时间"]
50 Thead1 = Plan1 << thead()
51 Thead1 << tr() << th(thead1[0]) + th(thead1[1]) + th(thead1[2]) + th(thead1[3]) + th(thead1[4]) + th(thead1[5]) + th(thead1[6]) + th(thead1[7])
52# 表体
53 tbody1 = ["151", "20180804110924", "1079", "APItest-1", "获取token", "获取token", "Pass", "2018-08-04 11:09:24"]
54 Error = "Error"
python怎么读取py文件55 Tbody1 = Plan1 << tbody()
56 Tbody1 << tr() << th(tbody1[0], scope="row") + td(tbody1[1]) + td(tbody1[2]) + td(tbody1[3]) + td(tbody1[4]) + td(tbody1[5]) + td(tbody1[6]) + td(tbody1[7])
57 Tbody1 << tr() << th(tbody1[0], scope="row") + td(tbody1[1]) + td(tbody1[2]) + td(tbody1[3]) + td(tbody1[4]) + td(tbody1[5]) + td(p(Error, cl="label label-danger")) + td(tbody1[7])
58# --⼀个测试计划-- end
59# 测试计划 end
60
61# 测试⽤例 start
62 Cases = Container << div(cl="row")
63# --栏⽬标题--
64 cases_title = "⽤例执⾏明细"
65 CasesTitle = Cases << div(cl="panel panel-primary") << div(cl="panel-heading") << strong(center(cases_title, cl="text-uppercase"))
66# --⼀个测试⽤例-- start
67 Case1 = Cases << div(cl="col-xs-12 col-md-12") << table(cl="table table-striped")
68# ---⼀个标题--
69 Case1_title = "测试计划【项⽬名称:APItest, 计划名称:user_operation】"
70 Case1 << center() << caption(plan1_title)
71# --⼀个列表--
72# 表头
73 thead1 = ["ID", "执⾏编号", "⽤例ID", "⽤例外部ID", "⽤例名称", "⽤例套件", "执⾏结果", "运⾏时间"]
74 Case1Thead1 = Case1 << thead()
75 Case1Thead1 << tr() << th(thead1[0]) + th(thead1[1]) + th(thead1[2]) + th(thead1[3]) + th(thead1[4]) + th(thead1[5]) + th(thead1[6]) + th(thead1[7])
76# 表体
77 tbody1 = ["151", "20180804110924", "1079", "APItest-1", "获取token", "获取token", "Pass", "2018-08-04 11:09:24"]
78 Error = "Error"
79 Case1Tbody1 = Case1 << tbody()
80 Case1Tbody1 << tr() << th(tbody1[0], scope="row") + td(tbody1[1]) + td(tbody1[2]) + td(tbody1[3]) + td(tbody1[4]) + td(tbody1[5]) + td(tbody1[6]) + td(tbody1[7])
81 Case1Tbody1 << tr() << th(tbody1[0], scope="row") + td(tbody1[1]) + td(tbody1[2]) + td(tbody1[3]) + td(tbody1[4]) + td(tbody1[5]) + td(p(Error, cl="label label-danger")) + td(tbody1[7]) 82# --⼀个测试计划-- end
83# 测试计划 end
84
85 page.printOut('Pyh_Template.html')
在代码中我已经注释了Pyh的使⽤要点:“<<”,还有任何问题,可以加进⾏解答,交流
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论