【发布时间】:2021-05-08 18:18:27
【问题描述】:
这是我的队友用来检查 HTML 页面中的链接以查看其是否损坏的功能。该函数搜索每个链接并将它们存储在 array[] g 中。我的工作是为此功能创建测试用例,但我不完全确定如何开始。我是 Python 初学者,想学习如何创建更有效的测试用例。
import urllib.request
import re
import urllib.error
def check(url):
try:
f= urllib.request.urlopen(url)
except urllib.error.HTTPError :
return False
return True
def trouveurdurls(url):
f= urllib.request.urlopen(url)
b=(f.read().decode('utf-8'))
d = re.findall('<a href=".*?"', b)
liste=[]
f.close()
for el in d:
g=re.findall('"https?://.*\.*"',el)
liste.append(g)
a=[]
for el in liste:
chaine= ''.join(map(str,el))
url=chaine.replace('\'','')
print(url)
#check(url)
b=trouveurdurls("http://127.0.0.1/")
【问题讨论】:
标签: python unit-testing http testing