At July 27 A.
This commit is contained in:
parent
eace83ef37
commit
c4b40bb990
File diff suppressed because it is too large
Load Diff
|
@ -303,15 +303,15 @@ class Template_mixin(object):
|
|||
},
|
||||
series: [{
|
||||
name: '通过',
|
||||
color: '#64BB64',
|
||||
color: '#64bb64',
|
||||
data: %(casesets_passed)s
|
||||
}, {
|
||||
name: '失败',
|
||||
color: '#F16D7E',
|
||||
color: '#f16d7e',
|
||||
data: %(casesets_failed)s
|
||||
}, {
|
||||
name: '错误',
|
||||
color: '#FDC68C',
|
||||
color: '#fdc68c',
|
||||
data: %(casesets_errors)s
|
||||
}]
|
||||
})
|
||||
|
@ -342,7 +342,7 @@ class Template_mixin(object):
|
|||
pie: {
|
||||
allowPointSelect: true,
|
||||
cursor: 'pointer',
|
||||
colors: ['#81ca9d', '#f16d7e', '#fdc68c'],
|
||||
colors: ['#64bb64', '#f16d7e', '#fdc68c'],
|
||||
dataLabels: {
|
||||
enabled: true,
|
||||
format: '<b>{point.name}</b>: {point.percentage:.1f} %%',
|
||||
|
@ -505,7 +505,10 @@ function html_escape(s) {
|
|||
%(header)s
|
||||
%(report)s
|
||||
%(footer)s
|
||||
<div style='width:auto;height:24px;line-height:24px;border:1px solid #e3e3e3;text-align:center'><a href='#' style='color:#505050'></a></div>
|
||||
<div style='width: auto; height: auto; border: 1px solid #e3e3e3; text-align: center; color: #505050; padding: 4px 0px 4px 0px;'>
|
||||
<img src='%(logo)s' style='width: auto; height: auto; max-height: 40px;'>
|
||||
<a href='#' style='font-size: 14px; color: #505050; text-align: center|bottom;'>%(sign)s</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
@ -790,9 +793,13 @@ class _TestResult(unittest.TestResult):
|
|||
# Note: _TestResult is a pure representation of results.
|
||||
# It lacks the output and reporting ability compares to unittest._TextTestResult.
|
||||
|
||||
def __init__(self, verbosity=1):
|
||||
def __init__(self, verbosity=1, log=None):
|
||||
super().__init__(verbosity=verbosity)
|
||||
self.fh = None
|
||||
self.lh = None
|
||||
self.ch = None
|
||||
self.verbosity = verbosity
|
||||
self.logoutput = log
|
||||
self.loggerStream = None
|
||||
self.outputBuffer = None
|
||||
self.stdout0 = None
|
||||
|
@ -837,9 +844,25 @@ class _TestResult(unittest.TestResult):
|
|||
|
||||
def startTest(self, test):
|
||||
# 单条用例执行开始前的动作
|
||||
if self.verbosity > 1:
|
||||
sys.stderr.write(_Color(fc=30, bc=47, bo=1, text='%04d' % (len(self.result) + 1)) + ' ')
|
||||
if self.verbosity >= 2:
|
||||
sys.stderr.write(_Color(fc=39, bc=4, bo=1, text='%-79s' % ('%04d Testing...' % (len(self.result) + 1))) + "\n")
|
||||
super().startTest(test)
|
||||
if self.verbosity >= 0:
|
||||
self.loggerStream = io.StringIO()
|
||||
self.lh = logging.StreamHandler(self.loggerStream)
|
||||
self.lh.setLevel(logging.DEBUG)
|
||||
self.lh.setFormatter(logging.Formatter(fmt='{asctime} - {levelname[0]}: {message}', style='{'))
|
||||
self.logger.addHandler(self.lh)
|
||||
if self.verbosity >= 2:
|
||||
self.ch = logging.StreamHandler(sys.stderr)
|
||||
self.ch.setLevel(logging.DEBUG)
|
||||
self.ch.setFormatter(logging.Formatter(fmt='{asctime} - {levelname[0]}: {message}', style='{'))
|
||||
self.logger.addHandler(self.ch)
|
||||
if self.logoutput:
|
||||
self.fh = logging.FileHandler(filename=self.logoutput, mode='a+', encoding='utf-8')
|
||||
self.fh.setLevel(logging.DEBUG)
|
||||
self.fh.setFormatter(logging.Formatter(fmt='{asctime} - {levelname[0]}: {module}.{funcName}\t{message}', style='{'))
|
||||
self.logger.addHandler(self.fh)
|
||||
# Just one buffer for both stdout and stderr
|
||||
self.outputBuffer = io.StringIO()
|
||||
stdout_redirector.fp = self.outputBuffer
|
||||
|
@ -849,12 +872,6 @@ class _TestResult(unittest.TestResult):
|
|||
sys.stdout = stdout_redirector
|
||||
sys.stderr = stderr_redirector
|
||||
self.stime = round(time.time(), 3)
|
||||
self.loggerStream = io.StringIO()
|
||||
self.ch = logging.StreamHandler(self.loggerStream)
|
||||
self.ch.setLevel(logging.DEBUG)
|
||||
self.ch.setFormatter(
|
||||
logging.Formatter('%(asctime)s - %(name)s -%(levelname)s -%(process)d -%(processName)s - %(message)s'))
|
||||
self.logger.addHandler(self.ch)
|
||||
|
||||
def complete_output(self):
|
||||
# 单条用例执行结束后,添加结果前的动作
|
||||
|
@ -869,7 +886,7 @@ class _TestResult(unittest.TestResult):
|
|||
sys.stderr = self.stderr0
|
||||
self.stdout0 = None
|
||||
self.stderr0 = None
|
||||
return self.loggerStream.getvalue() + self.outputBuffer.getvalue()
|
||||
return [self.loggerStream.getvalue(), self.outputBuffer.getvalue()]
|
||||
|
||||
def stopTest(self, test):
|
||||
# 单条用例执行结束后,添加结果后的动作
|
||||
|
@ -879,7 +896,9 @@ class _TestResult(unittest.TestResult):
|
|||
# We must disconnect stdout in stopTest(), which is guaranteed to be called.
|
||||
# self.complete_output()
|
||||
# 移除日志Handler
|
||||
self.logger.removeHandler(self.ch)
|
||||
for value in [self.fh, self.lh, self.ch]:
|
||||
if value:
|
||||
self.logger.removeHandler(value)
|
||||
|
||||
def addSuccess(self, test):
|
||||
# 单条用例执行结束后,添加结果时的动作
|
||||
|
@ -891,18 +910,18 @@ class _TestResult(unittest.TestResult):
|
|||
output = self.complete_output()
|
||||
utime = round(self.etime - self.stime, 3)
|
||||
self.sortCount(cls=test.__class__.__qualname__, res=term_head, dur=utime)
|
||||
self.result.append((0, test, output, '', utime))
|
||||
self.result.append((0, test, output[1], '', utime))
|
||||
# 单条用例执行结束后在终端打印结果
|
||||
if self.verbosity > 1:
|
||||
if self.verbosity >= 1:
|
||||
sys.stderr.write('%s %s %s %s.%s.%-18s\t%s %s\n' % (
|
||||
_Color(fc=term_clor, bo=1, text=term_mark + ' ' + term_head + ':'),
|
||||
datetime.datetime.utcfromtimestamp(utime).strftime('%H:%M:%S.%f')[0:12],
|
||||
_Color(fc=term_clor, bo=1, text='%04d' % (len(self.result)) + ' ' + term_mark + ' ' + term_head + ':'),
|
||||
_Color(fc=37, bo=0, text=datetime.datetime.utcfromtimestamp(utime).strftime('%H:%M:%S.%f')[0:12]),
|
||||
_Color(fc=term_clor, bo=1, text='<='),
|
||||
str(test.__module__).strip('_'),
|
||||
str(test.__class__.__qualname__),
|
||||
str(test.__dict__["_testMethodName"]),
|
||||
_Color(fc=37, bo=0, text=str(test.__module__).strip('_')),
|
||||
_Color(fc=37, bo=0, text=str(test.__class__.__qualname__)),
|
||||
_Color(fc=37, bo=0, text=str(test.__dict__["_testMethodName"])),
|
||||
_Color(fc=term_clor, bo=1, text='<='),
|
||||
str(test.__dict__["_testMethodDoc"] or "")
|
||||
_Color(fc=37, bo=0, text=str(test.__dict__["_testMethodDoc"] or ""))
|
||||
))
|
||||
|
||||
def addError(self, test, err):
|
||||
|
@ -916,18 +935,18 @@ class _TestResult(unittest.TestResult):
|
|||
output = self.complete_output()
|
||||
utime = round(self.etime - self.stime, 3)
|
||||
self.sortCount(cls=test.__class__.__qualname__, res=term_head, dur=utime)
|
||||
self.result.append((2, test, output, _exc_str, utime))
|
||||
self.result.append((2, test, output[0] + output[1], _exc_str, utime))
|
||||
# 单条用例执行结束后在终端打印结果
|
||||
if self.verbosity > 1:
|
||||
if self.verbosity >= 1:
|
||||
sys.stderr.write('%s %s %s %s.%s.%-18s\t%s %s\n' % (
|
||||
_Color(fc=term_clor, bo=1, text=term_mark + ' ' + term_head + ':'),
|
||||
datetime.datetime.utcfromtimestamp(utime).strftime('%H:%M:%S.%f')[0:12],
|
||||
_Color(fc=term_clor, bo=1, text='%04d' % (len(self.result)) + ' ' + term_mark + ' ' + term_head + ':'),
|
||||
_Color(fc=37, bo=0, text=datetime.datetime.utcfromtimestamp(utime).strftime('%H:%M:%S.%f')[0:12]),
|
||||
_Color(fc=term_clor, bo=1, text='<='),
|
||||
str(test.__module__).strip('_'),
|
||||
str(test.__class__.__qualname__),
|
||||
str(test.__dict__["_testMethodName"]),
|
||||
_Color(fc=37, bo=0, text=str(test.__module__).strip('_')),
|
||||
_Color(fc=37, bo=0, text=str(test.__class__.__qualname__)),
|
||||
_Color(fc=37, bo=0, text=str(test.__dict__["_testMethodName"])),
|
||||
_Color(fc=term_clor, bo=1, text='<='),
|
||||
str(test.__dict__["_testMethodDoc"] or "")
|
||||
_Color(fc=37, bo=0, text=str(test.__dict__["_testMethodDoc"] or ""))
|
||||
))
|
||||
# 收集错误测试用例名称以在测试报告中显示
|
||||
casename = str(test.__module__).strip('_') + '.' + str(test.__class__.__qualname__) + '.' + str(
|
||||
|
@ -946,18 +965,18 @@ class _TestResult(unittest.TestResult):
|
|||
output = self.complete_output()
|
||||
utime = round(self.etime - self.stime, 3)
|
||||
self.sortCount(cls=test.__class__.__qualname__, res=term_head, dur=utime)
|
||||
self.result.append((1, test, output, _exc_str, utime))
|
||||
self.result.append((1, test, output[0] + output[1], _exc_str, utime))
|
||||
# 单条用例执行结束后在终端打印结果
|
||||
if self.verbosity > 1:
|
||||
if self.verbosity >= 1:
|
||||
sys.stderr.write('%s %s %s %s.%s.%-18s\t%s %s\n' % (
|
||||
_Color(fc=term_clor, bo=1, text=term_mark + ' ' + term_head + ':'),
|
||||
datetime.datetime.utcfromtimestamp(utime).strftime('%H:%M:%S.%f')[0:12],
|
||||
_Color(fc=term_clor, bo=1, text='%04d' % (len(self.result)) + ' ' + term_mark + ' ' + term_head + ':'),
|
||||
_Color(fc=37, bo=0, text=datetime.datetime.utcfromtimestamp(utime).strftime('%H:%M:%S.%f')[0:12]),
|
||||
_Color(fc=term_clor, bo=1, text='<='),
|
||||
str(test.__module__).strip('_'),
|
||||
str(test.__class__.__qualname__),
|
||||
str(test.__dict__["_testMethodName"]),
|
||||
_Color(fc=37, bo=0, text=str(test.__module__).strip('_')),
|
||||
_Color(fc=37, bo=0, text=str(test.__class__.__qualname__)),
|
||||
_Color(fc=37, bo=0, text=str(test.__dict__["_testMethodName"])),
|
||||
_Color(fc=term_clor, bo=1, text='<='),
|
||||
str(test.__dict__["_testMethodDoc"] or "")
|
||||
_Color(fc=37, bo=0, text=str(test.__dict__["_testMethodDoc"] or ""))
|
||||
))
|
||||
# 收集失败测试用例名称以在测试报告中显示
|
||||
casename = str(test.__module__).strip('_') + '.' + str(test.__class__.__qualname__) + '.' + str(
|
||||
|
@ -968,10 +987,14 @@ class _TestResult(unittest.TestResult):
|
|||
|
||||
class HTMLTestRunner(Template_mixin):
|
||||
# 新增 errormsg 参数,-1为无需截图,否则需要截图
|
||||
def __init__(self, stream=None, verbosity=2, title=None, description=None, tester=None):
|
||||
def __init__(self, report=None, log=None, stream=None, verbosity=1, title=None, description=None,
|
||||
info=None, logo='', sign=''):
|
||||
self.passrate = None
|
||||
self.errormsg = None
|
||||
self.stream = stream
|
||||
self.logspath = log and os.path.abspath(log)
|
||||
self.logo = logo
|
||||
self.sign = sign
|
||||
self.stream = stream or (report and open(report, 'wb'))
|
||||
self.verbosity = verbosity
|
||||
self.runstime = None
|
||||
self.runetime = None
|
||||
|
@ -984,10 +1007,16 @@ class HTMLTestRunner(Template_mixin):
|
|||
self.description = self.DEFAULT_DESCRIPTION
|
||||
else:
|
||||
self.description = description
|
||||
if tester is None:
|
||||
self.tester = self.DEFAULT_TESTER
|
||||
if info is None:
|
||||
self.testinfo = []
|
||||
elif isinstance(info, list):
|
||||
self.testinfo = info
|
||||
elif isinstance(info, dict):
|
||||
self.testinfo = []
|
||||
for key, value in info.items():
|
||||
self.testinfo.append([key, value])
|
||||
else:
|
||||
self.tester = tester
|
||||
self.testinfo = []
|
||||
|
||||
def run(self, test):
|
||||
"""
|
||||
|
@ -996,14 +1025,14 @@ class HTMLTestRunner(Template_mixin):
|
|||
# The final result is output when the verbosity is 1,
|
||||
# and the result of each use case is output when the verbosity is 2.
|
||||
# Start testing.
|
||||
sys.stderr.write('********************************* 开始测试 *********************************' + '\n')
|
||||
sys.stderr.write("\n")
|
||||
sys.stderr.write(_Color(
|
||||
fc=38, bo=1, text='* * * * * * * * * * * * * * * * * * 开始测试 * * * * * * * * * * * * * * * * * *') + '\n')
|
||||
self.runstime = round(time.time(), 3)
|
||||
result = _TestResult(self.verbosity)
|
||||
result = _TestResult(verbosity=self.verbosity, log=self.logspath)
|
||||
test(result)
|
||||
self.runetime = round(time.time(), 3)
|
||||
sys.stderr.write("\n")
|
||||
sys.stderr.write('********************************* 结束测试 *********************************' + '\n')
|
||||
sys.stderr.write(_Color(
|
||||
fc=38, bo=1, text='* * * * * * * * * * * * * * * * * * 结束测试 * * * * * * * * * * * * * * * * * *') + '\n')
|
||||
# Generate test report.
|
||||
self.generateReport(test, result)
|
||||
case_count = {
|
||||
|
@ -1019,15 +1048,15 @@ class HTMLTestRunner(Template_mixin):
|
|||
list_failed = result.failedCaseList
|
||||
list_errors = result.errorsCaseList
|
||||
casesort = result.casesort
|
||||
sys.stderr.write(_Color(fc=38, bo=1, text='结果概要') + "\n")
|
||||
sys.stderr.write(_Color(fc=37, bo=0, text='总共') + "\x20" + str(case_count["t"]) + "\x20" +
|
||||
_Color(fc=37, bo=0, text='通过') + "\x20" + str(case_count["p"]) + "\x20" +
|
||||
_Color(fc=37, bo=0, text='失败') + "\x20" + str(case_count["f"]) + "\x20" +
|
||||
_Color(fc=37, bo=0, text='错误') + "\x20" + str(case_count["e"]) + "\x20" +
|
||||
_Color(fc=37, bo=0, text='耗时') + "\x20" + dura + "\x20" +
|
||||
_Color(fc=37, bo=0, text='通过率') + "\x20" + rate_passed + "\x20" +
|
||||
_Color(fc=37, bo=0, text='失败率') + "\x20" + rate_failed + "\x20" +
|
||||
_Color(fc=37, bo=0, text='错误率') + "\x20" + rate_errors + "\x20" +
|
||||
sys.stderr.write(_Color(fc=36, bo=1, text='结果概要') + "\n")
|
||||
sys.stderr.write(_Color(fc=37, bo=0, text='总共' + "\x20" + str(case_count["t"]) + "\x20") +
|
||||
_Color(fc=37, bo=0, text='通过' + "\x20" + str(case_count["p"]) + "\x20") +
|
||||
_Color(fc=37, bo=0, text='失败' + "\x20" + str(case_count["f"]) + "\x20") +
|
||||
_Color(fc=37, bo=0, text='错误' + "\x20" + str(case_count["e"]) + "\x20") +
|
||||
_Color(fc=37, bo=0, text='耗时' + "\x20" + dura + "\x20") +
|
||||
_Color(fc=37, bo=0, text='通过率' + "\x20" + rate_passed + "\x20") +
|
||||
_Color(fc=37, bo=0, text='失败率' + "\x20" + rate_failed + "\x20") +
|
||||
_Color(fc=37, bo=0, text='错误率' + "\x20" + rate_errors + "\x20") +
|
||||
"\n"
|
||||
)
|
||||
for value in [['失败用例', list_failed, 31], ['错误用例', list_errors, 33]]:
|
||||
|
@ -1096,13 +1125,12 @@ class HTMLTestRunner(Template_mixin):
|
|||
else:
|
||||
errorsCase = '无'
|
||||
|
||||
return [
|
||||
('测试人员', self.tester),
|
||||
('开始时间', runstime),
|
||||
('合计耗时', duration),
|
||||
('测试结果', status + ',通过率 ' + self.passrate),
|
||||
('失败用例', failedCase),
|
||||
('错误用例', errorsCase),
|
||||
return self.testinfo + [
|
||||
['开始时间', runstime],
|
||||
['合计耗时', duration],
|
||||
['测试结果', status + ',通过率 ' + self.passrate],
|
||||
['失败用例', failedCase],
|
||||
['错误用例', errorsCase],
|
||||
]
|
||||
|
||||
def generateReport(self, test, result):
|
||||
|
@ -1110,6 +1138,8 @@ class HTMLTestRunner(Template_mixin):
|
|||
report_count = self._generate_report(result)
|
||||
output = self.HTML_TMPL % dict(
|
||||
title=saxutils.escape(self.title),
|
||||
logo=self.logo,
|
||||
sign=self.sign,
|
||||
generator='HTMLTestRunner',
|
||||
styles=self._generate_styles(),
|
||||
passed=report_count["passed"],
|
||||
|
@ -1123,7 +1153,7 @@ class HTMLTestRunner(Template_mixin):
|
|||
report=report_count["report"],
|
||||
footer=self._generate_footer(),
|
||||
)
|
||||
self.stream.write(output.encode('utf-8'))
|
||||
self.stream and self.stream.write(output.encode('utf-8'))
|
||||
|
||||
def _generate_styles(self):
|
||||
return self.STYLES_TMPL
|
||||
|
@ -1147,13 +1177,12 @@ class HTMLTestRunner(Template_mixin):
|
|||
"<ol id='errorsCaseOl' class='collapse' style='float: left; font-family: Menlo,Monaco,Consolas,monospace;'>" + value + "</ol>"
|
||||
)
|
||||
case _:
|
||||
line = self.HEADER_ATTRIBUTE_TMPL % dict(name=saxutils.escape(name), value=saxutils.escape(value))
|
||||
line = self.HEADER_ATTRIBUTE_TMPL % dict(name=saxutils.escape(str(name)), value=saxutils.escape(str(value)))
|
||||
line_list.append(line)
|
||||
return self.HEADER_TMPL % dict(
|
||||
title=saxutils.escape(self.title),
|
||||
parameters=''.join(line_list),
|
||||
description=saxutils.escape(self.description),
|
||||
tester=saxutils.escape(self.tester),
|
||||
description=saxutils.escape(self.description)
|
||||
)
|
||||
|
||||
# 生成报告
|
||||
|
|
8
main.py
8
main.py
|
@ -1,5 +1,3 @@
|
|||
import re
|
||||
|
||||
|
||||
string = '...\n[TestErrorMsg]./index[/TestErrorMsg]\n[TestErrorMsg]./index[/TestErrorMsg]\n[TestErrorMsg]./index[/TestErrorMsg]\n456\nsddsfgsd: [WinError] 32432532\n[TestErrorMsg]./index[/TestErrorMsg]\n'
|
||||
print(re.compile('\[[A-Za-z]+].*?\[/[A-Za-z]+][\r\n]').sub('', string))
|
||||
a = []
|
||||
b = [1,2,3]
|
||||
print(a + b)
|
5
main2.py
5
main2.py
|
@ -1,5 +0,0 @@
|
|||
import subprocess,chardet
|
||||
|
||||
runResult = subprocess.run('ping -n 1 www.fanscloud.net && echo 测试',shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
||||
print(runResult)
|
70
main3.py
70
main3.py
|
@ -1,70 +0,0 @@
|
|||
import smtplib
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
from email.mime.base import MIMEBase
|
||||
from email.header import Header
|
||||
from email import encoders
|
||||
|
||||
mail_host = {
|
||||
"host": 'smtp.qq.com',
|
||||
"port": 465
|
||||
}
|
||||
mail_user = {
|
||||
"user": 'admin@fanscloud.net',
|
||||
"pass": 'gyzzvmjdlofnbedj'
|
||||
}
|
||||
sender = "admin@fanscloud.net"
|
||||
|
||||
mailToList = [
|
||||
"1634991757@qq.com",
|
||||
"fanscloud@foxmail.com"
|
||||
]
|
||||
mailCcList = [
|
||||
"zhaoyafan@foxmail.com"
|
||||
]
|
||||
mailBcList = [
|
||||
|
||||
]
|
||||
html = '''
|
||||
<p>Python 邮件发送HTML格式文件测试...</p>
|
||||
<p><a href="http://www.runoob.com">这是一个链接</a></p>
|
||||
'''
|
||||
message = MIMEMultipart()
|
||||
messageFrom = Header()
|
||||
messageFrom.append('云凡网络')
|
||||
messageFrom.append('<admin@fanscloud.net>')
|
||||
print(messageFrom)
|
||||
message["From"] = messageFrom
|
||||
message["To"] = ';'.join(mailToList)
|
||||
message["Cc"] = ';'.join(mailCcList)
|
||||
message["Bcc"] = ';'.join(mailBcList)
|
||||
message['Subject'] = Header('主题333')
|
||||
message.attach(MIMEText(html, 'html', 'utf-8'))
|
||||
|
||||
|
||||
# 构造附件2,传送当前目录下的 runoob.txt 文件
|
||||
# att2 = MIMEText(open('./1.xlsx', 'rb').read(), 'base64', 'utf-8')
|
||||
# att2["Content-Type"] = 'application/octet-stream'
|
||||
# file = Header('attachment; filename=')
|
||||
#
|
||||
# att2["Content-Disposition"] = file
|
||||
# message.attach(att2)
|
||||
#
|
||||
#
|
||||
# print(file)
|
||||
|
||||
mime = MIMEBase('application','octet-stream')
|
||||
mime.add_header('Content-Disposition', 'attachment', filename='文件文件.xlsx')
|
||||
mime.set_payload(open('./1.xlsx', 'rb').read())
|
||||
# 用Base64编码:
|
||||
encoders.encode_base64(mime)
|
||||
# 添加到MIMEMultipart:
|
||||
message.attach(mime)
|
||||
|
||||
print("加密后的发送内容\n", message.as_string()) # 打印输出加密后的发送内容
|
||||
#
|
||||
#
|
||||
smtpObj = smtplib.SMTP_SSL(mail_host['host'], mail_host['port'])
|
||||
# smtpObj.connect(mail_host['host'], mail_host['port']) # 链接 SMTP 服务器
|
||||
smtpObj.login(mail_user['user'], mail_user['pass']) # 登录邮箱验证
|
||||
smtpObj.sendmail(sender, mailToList, message.as_string()) # 发送邮件; "message" 通过 "as_string()" 进行发送内容字符串的加密
|
81
main4.py
81
main4.py
|
@ -1,81 +0,0 @@
|
|||
import requests, logging, time
|
||||
|
||||
def test():
|
||||
url = 'http://more-md.fanscloud.net/filebox.php?op=home'
|
||||
url_upload = 'https://more-me.fanscloud.net/typoraUpload'
|
||||
|
||||
# logging.basicConfig()
|
||||
# logging.getLogger().setLevel(logging.DEBUG)
|
||||
# requests_log = logging.getLogger("requests.packages.urllib3")
|
||||
#
|
||||
# requests_log.setLevel(logging.DEBUG)
|
||||
#
|
||||
# requests_log.propagate = True
|
||||
|
||||
|
||||
|
||||
|
||||
ses = requests.session()
|
||||
|
||||
|
||||
req = ses.request(
|
||||
method='POST',
|
||||
url=url,
|
||||
params={"ip": '119.29.29.29'},
|
||||
data={"user": 'admin', "pass": '1234ABCDabcd', "submitButtonName": '登录'},
|
||||
headers={"Version": '1.0.0', "Connection": 'keep-alive'},
|
||||
cookies={},
|
||||
files={},
|
||||
auth=None,
|
||||
timeout=10,
|
||||
allow_redirects=False,
|
||||
proxies=None,
|
||||
verify=False,
|
||||
cert=None,
|
||||
json=None
|
||||
)
|
||||
req2 = ses.request(
|
||||
method='GET',
|
||||
url=url,
|
||||
params={"ip": '119.29.29.29'},
|
||||
data={},
|
||||
headers={"Version": '1.0.0', "Connection": 'keep-alive'},
|
||||
cookies={},
|
||||
files={},
|
||||
auth=None,
|
||||
timeout=10,
|
||||
allow_redirects=False,
|
||||
proxies=None,
|
||||
verify=False,
|
||||
cert=None,
|
||||
json=None
|
||||
)
|
||||
# req = requests.post(url=url, params={"ip": '119.29.29.29'}, proxies={"http": '127.0.0.1:8888', "https": '127.0.0.1:8888'})
|
||||
# proxies={"http": '127.0.0.1:8888', "https": '127.0.0.1:8888'},
|
||||
|
||||
|
||||
|
||||
# print(req.request.method + ' ' + req.request.url + ' ' + 'HTTP/1.1' + '\r\n')
|
||||
print(req2.text)
|
||||
# print(req.headers)
|
||||
# logs = logging.getLogger()
|
||||
#
|
||||
# logs.setLevel(logging.DEBUG)
|
||||
#
|
||||
# path = './' + time.strftime('%Y-%m-%d-%H-%M-%S') + '.log'
|
||||
# write_file = logging.FileHandler(path, 'a+', encoding='utf-8')
|
||||
#
|
||||
# write_file.setLevel(logging.DEBUG)
|
||||
#
|
||||
# set_logs = logging.Formatter('%(asctime)s - %(filename)s - %(funcName)s - %(levelname)s - %(message)s')
|
||||
#
|
||||
# write_file.setFormatter(set_logs)
|
||||
#
|
||||
# pycharm_text = logging.StreamHandler()
|
||||
#
|
||||
# pycharm_text.setFormatter(set_logs)
|
||||
#
|
||||
# logs.addHandler(write_file)
|
||||
#
|
||||
# logs.addHandler(pycharm_text)
|
||||
test()
|
3
main5.py
3
main5.py
|
@ -1,3 +0,0 @@
|
|||
from Base.Class.Http import *
|
||||
|
||||
http = Request().http('get', 'http://127.0.0.1:81/iplookup.php', header={"Host": 'fanscloud.net'}, debug=True)
|
4
main6.py
4
main6.py
|
@ -1,4 +0,0 @@
|
|||
from Base.Class.Database import *
|
||||
sql = MySQL(host='sdm821105491.my3w.com', port=3306, user='sdm821105491', password='1234ABCDabcd', database='sdm821105491_db', charset='utf8', cursor='Dict')
|
||||
sql.execute('select * from emlog_options where option_name="bloginfo"')
|
||||
print(sql.fetchall())
|
14
main7.py
14
main7.py
|
@ -1,14 +0,0 @@
|
|||
from Base.Class.Excel import *
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Example.
|
||||
# 打开现有Excel文件
|
||||
excel = Excel().open(filename='./example.xlsx')
|
||||
excel.select(2)
|
||||
# print(excel.cellGetView('A1:C9'))
|
||||
# print(excel.cellGetView('1:9'))
|
||||
|
||||
print(excel.cellGetView('D5:F12'))
|
||||
# excel.save()
|
||||
# print(excel.cellGetView(area='F6:F11'))
|
11
run.py
11
run.py
|
@ -17,7 +17,7 @@ from types import FunctionType
|
|||
obj = type("测试用例",(unittest.TestCase,),dict())
|
||||
obj.__doc__ = 'Doc'
|
||||
obj.test_demo0123456789ABCDEF_000000 = FunctionType(compile('def foo(self): import time; time.sleep(0)', "", "exec").co_consts[0], globals(), "foo")
|
||||
obj.test_demo1 = FunctionType(compile('def foo(self): return "bar"', "", "exec").co_consts[0], globals(), "foo")
|
||||
obj.test_demo1 = FunctionType(compile('def foo(self): return a', "", "exec").co_consts[0], globals(), "foo")
|
||||
obj.test_demo2 = FunctionType(compile('def foo(self): assert 1 == 2', "", "exec").co_consts[0], globals(), "foo")
|
||||
obj.test_demo3 = FunctionType(compile('def foo(): return "bar"', "", "exec").co_consts[0], globals(), "foo")
|
||||
obj.test_demo1.__qualname__ = "test_demo1"
|
||||
|
@ -40,6 +40,7 @@ obj.test_demo3.__doc__ = "这是一条测试用例;这是一条测试用例;
|
|||
base_path = os.path.dirname(__file__)
|
||||
report_path = base_path
|
||||
report_filename = os.path.join(report_path, 'report.html')
|
||||
log_filename = os.path.join(report_path, 'test.log')
|
||||
|
||||
case_suite = unittest.TestSuite()
|
||||
case_suite.addTest(TestDemo('test_one1'))
|
||||
|
@ -63,12 +64,8 @@ case_suite.addTest(TestDemo('test_0123456789ABC'))
|
|||
|
||||
|
||||
def start():
|
||||
with open(report_filename, 'wb') as f:
|
||||
runner = HTMLTestRunner(stream=f,
|
||||
title='自动化测试报告',
|
||||
verbosity=2,
|
||||
description='描述',
|
||||
tester='DESKTOP')
|
||||
runner = HTMLTestRunner(report=report_filename, log=log_filename, stream=None, verbosity=0, title='自动化测试报告', description='描述', info=None)
|
||||
# runner = HTMLTestRunner()
|
||||
runner.run(case_suite)
|
||||
|
||||
|
||||
|
|
20
test_case.py
20
test_case.py
|
@ -1,3 +1,4 @@
|
|||
import sys
|
||||
import time
|
||||
import unittest
|
||||
from selenium import webdriver
|
||||
|
@ -5,11 +6,11 @@ from selenium.webdriver.chrome.options import Options
|
|||
|
||||
from Base.Class.Logger import *
|
||||
from Base.Class.Http import *
|
||||
log = Logger(name='test', level='DEBUG', ch={
|
||||
"level": 'DEBUG',
|
||||
"format": '{asctime} - {name} - {levelname[0]}: {message}'
|
||||
})
|
||||
|
||||
# log = Logger(name='test', level='DEBUG', ch={
|
||||
# "level": 'DEBUG',
|
||||
# "format": '{asctime} - {name} - {levelname[0]}: {message}'
|
||||
# })
|
||||
log = Logger(name='test', level='DEBUG')
|
||||
|
||||
class TestDemo(unittest.TestCase):
|
||||
def test_one1(self):
|
||||
|
@ -18,15 +19,20 @@ class TestDemo(unittest.TestCase):
|
|||
# os.system('echo Case One1 Exec...')
|
||||
# time.sleep(5)
|
||||
assert 1 == 1
|
||||
# log.i("Info...")
|
||||
# log.w("Warnning...")
|
||||
log.i("Info...")
|
||||
log.w("Warnning...")
|
||||
print("STDOUT", file=sys.stdout)
|
||||
print("STDERR", file=sys.stderr)
|
||||
|
||||
def test_two22(self):
|
||||
time.sleep(0.036)
|
||||
# log.d("正在断言...")
|
||||
log.e('错误啦!!!')
|
||||
assert 'A' in 'Hello!', '断言失败'
|
||||
|
||||
def test_tre333(self):
|
||||
print('[TestErrorImg]./01.png[/TestErrorImg]')
|
||||
a(1)
|
||||
time.sleep(0.025)
|
||||
# assert a == 10
|
||||
|
||||
|
|
Loading…
Reference in New Issue