未验证 提交 b96330dc 编写于 作者: H Hui Li 提交者: GitHub

Merge pull request #9057 from taosdata/test/TD-12057

[TD-12057]Adjust catalog collection logic
......@@ -17,8 +17,11 @@ import sys
import getopt
import os
from fabric2 import Connection
sys.path.append("pytest")
import importlib
import re
class CatalogGen:
def __init__(self, CaseDirList, CatalogName, DirDepth):
......@@ -31,7 +34,7 @@ class CatalogGen:
for i in self.CaseDirList:
self.GetCatalog(i)
self.CollectLog(i)
print('Catalog Generation done')
print("Catalog Generation done")
def CollectLog(self, CaseDir):
DirorFiles = os.listdir(CaseDir)
......@@ -43,12 +46,14 @@ class CatalogGen:
else:
if i == self.CatalogName and fileName not in self.blacklist:
self.blacklist.append(fileName)
with open(fileName, "r") as f :
with open(fileName, "r") as f:
Catalog = f.read()
title = CaseDir.split("/")[-1]
TitleLevel = CaseDir.count("/")
with open(os.path.dirname(CaseDir) + '/' + self.CatalogName, "a") as f :
f.write("#" * TitleLevel + ' %s\n' % title)
with open(
os.path.dirname(CaseDir) + "/" + self.CatalogName, "a"
) as f:
f.write("#" * TitleLevel + " %s\n" % title)
f.write(Catalog)
def GetCatalog(self, CaseDir):
......@@ -58,16 +63,20 @@ class CatalogGen:
fileName = os.path.join(root, file)
moduleName = fileName.replace(".py", "").replace("/", ".")
uModule = importlib.import_module(moduleName)
title = file.split('.')[0]
TitleLevel = root.count('/') + 1
title = file.split(".")[0]
TitleLevel = root.count("/") + 1
try:
ucase = uModule.TDTestCase()
with open(root + '/' + self.CatalogName, 'a') as f:
f.write('#'*TitleLevel + ' %s\n' % title)
for i in ucase.caseDescription.__doc__.split('\n'):
if i.lstrip() == '':continue
f.write('* ' + i.strip()+'\n')
except :
with open(root + "/" + self.CatalogName, "a") as f:
f.write("#" * TitleLevel + " %s\n" % title)
for i in ucase.caseDescription.__doc__.split("\n"):
if i.lstrip() == "":
continue
if re.match("^case.*:", i.strip()):
f.write("* " + i.strip() + "\n")
else:
f.write(i.strip() + "\n")
except:
print(fileName)
def CleanCatalog(self):
......@@ -75,57 +84,61 @@ class CatalogGen:
for root, dirs, files in os.walk(i):
for file in files:
if file == self.CatalogName:
os.remove(root + '/' + self.CatalogName)
print('clean is done')
os.remove(root + "/" + self.CatalogName)
print("clean is done")
if __name__ == "__main__":
CaseDirList = []
CatalogName = ''
CatalogName = ""
DirDepth = 0
generate = True
delete = True
opts, args = getopt.gnu_getopt(sys.argv[1:], 'd:c:v:n:th')
opts, args = getopt.gnu_getopt(sys.argv[1:], "d:c:v:n:th")
for key, value in opts:
if key in ['-h', '--help']:
if key in ["-h", "--help"]:
print("A collection of test cases catalog written using Python")
print(
'A collection of test cases catalog written using Python')
print("-d root dir of test case files written by Python, default: system-test,develop-test")
print('-c catalog file name, default: catalog.md')
print('-v dir depth of test cases.default: 5')
print('-n <True:False> generate')
print('-r <True:False> delete')
"-d root dir of test case files written by Python, default: system-test,develop-test"
)
print("-c catalog file name, default: catalog.md")
print("-v dir depth of test cases.default: 5")
print("-n <True:False> generate")
print("-r <True:False> delete")
sys.exit(0)
if key in ['-d']:
CaseDirList = value.split(',')
if key in ["-d"]:
CaseDirList = value.split(",")
if key in ['-c']:
if key in ["-c"]:
CatalogName = value
if key in ['-v']:
if key in ["-v"]:
DirDepth = int(value)
if key in ['-n']:
if (value.upper() == "TRUE"):
if key in ["-n"]:
if value.upper() == "TRUE":
generate = True
elif (value.upper() == "FALSE"):
elif value.upper() == "FALSE":
generate = False
if key in ['-r']:
if (value.upper() == "TRUE"):
if key in ["-r"]:
if value.upper() == "TRUE":
delete = True
elif (value.upper() == "FALSE"):
elif value.upper() == "FALSE":
delete = False
print(CaseDirList, CatalogName)
if CaseDirList == [] :
CaseDirList = ['system-test', 'develop-test']
if CatalogName == '' :
CatalogName = 'catalog.md'
if CaseDirList == []:
CaseDirList = ["system-test", "develop-test"]
if CatalogName == "":
CatalogName = "catalog.md"
if DirDepth == 0:
DirDepth = 5
print('opt:\n\tcatalogname: %s\n\tcasedirlist: %s\n\tdepth: %d\n\tgenerate: %s\n\tdelete: %s'
% (CatalogName, ','.join(CaseDirList), DirDepth, generate, delete))
print(
"opt:\n\tcatalogname: %s\n\tcasedirlist: %s\n\tdepth: %d\n\tgenerate: %s\n\tdelete: %s"
% (CatalogName, ",".join(CaseDirList), DirDepth, generate, delete)
)
f = CatalogGen(CaseDirList, CatalogName, DirDepth)
if delete:
f.CleanCatalog()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册