使用python造测试参数01
代码如下:
author = "damao"import json
import randomclass Test_Data(object):
def __init__(self):
passdef rdm_province(self):
province = ["上海","北京","安徽","江苏"]
p = province[random.randint(0,len(province)-1)]
# print(p)
return pdef rdm_city(self,province):
city_anhui = ["合肥市","安庆市","黄山市"]
city_jiangsu = ["南京市","无锡市","苏州市"]
if province == "上海":
city = "上海市"
# print(city)
return city
elif province == "北京":
city = "北京市"
# print(city)
return city
elif province == "安徽":
city = city_anhui[random.randint(0,len(city_anhui)-1)]
# print(city)
return city
elif province == "江苏":
city = city_jiangsu[random.randint(0,len(city_jiangsu)-1)]
# print(city)
return citydef rdm_address(self,city):
address_bjs = ["朝阳区", "海定区", "大兴区", "通州区"]
address_shs = ["静安区", "浦东新区", "杨浦区","徐汇区"]
address_hfs = ["瑶海区","庐山区","蜀山区","包河区"]
address_aqs = ["迎江区", "大观区", "宜秀区"]
address_hss = ["屯溪区", "黄山区", "徽州区"]
address_njs = ["雨花台区", "建邺区", "江宁区", "溧水区"]
address_wxs = ["新吴区", "梁溪区", "滨湖区", "惠山区"]
address_szs = ["吴江区", "姑苏区", "相城区", "吴中区"]
# adds_list = [address_bjs,address_shs,address_hfs,address_aqs,address_hss,address_njs,address_wxs,address_szs]
# adds_list_choce = adds_list[random.randint(0,7)]
# address = adds_list_choce[random.randint(0,len(adds_list_choce)-1)]
if city == "北京市":
address = address_bjs[random.randint(0,len(address_bjs)-1)]
# print(address)
return address
elif city == "上海市":
address = address_shs[random.randint(0,len(address_shs)-1)]
# print(address)
return address
elif city == "合肥市":
address = address_hfs[random.randint(0,len(address_hfs)-1)]
# print(address)
return address
elif city == "安庆市":
address = address_aqs[random.randint(0,len(address_aqs)-1)]
# print(address)
return address
elif city == "黄山市":
address = address_hss[random.randint(0,len(address_hss)-1)]
# print(address)
return address
elif city == "南京市":
address = address_njs[random.randint(0, len(address_njs)-1)]
# print(address)
return address
elif city == "无锡市":
address = address_wxs[random.randint(0, len(address_wxs)-1)]
# print(address)
return address
elif city == "苏州市":
address = address_szs[random.randint(0, len(address_szs)-1)]
# print(address)
return addressdef rdm_lat_and_lon(self,city):
if city == "北京市":
lat = random.uniform(39.40,41.60)
lon = random.uniform(115.70,117.40)
# print(round(lat,2),round(lon,2))
return round(lat,2),round(lon,2)
elif city == "上海市":
lat = random.uniform(30.40, 31.53)
lon = random.uniform(120.51, 120.12)
# print(round(lat, 2), round(lon, 2))
return round(lat, 2), round(lon, 2)
elif city == "合肥市":
lat = random.uniform(30.57, 32.32)
lon = random.uniform(116.41, 117.58)
# print(round(lat, 2), round(lon, 2))
return round(lat, 2), round(lon, 2)
elif city == "安庆市":
lat = random.uniform(31.01, 31.38)
lon = random.uniform(117.05, 117.43)
# print(round(lat, 2), round(lon, 2))
return round(lat, 2), round(lon, 2)
elif city == "黄山市":
lat = random.uniform(30.08, 31.38)
lon = random.uniform(118.09, 119.43)
# print(round(lat, 2), round(lon, 2))
return round(lat, 2), round(lon, 2)
elif city == "南京市":
lat = random.uniform(31.23, 32.61)
lon = random.uniform(118.35, 119.23)
# print(round(lat, 2), round(lon, 2))
return round(lat, 2), round(lon, 2)
elif city == "无锡市":
lat = random.uniform(31.12, 31.98)
lon = random.uniform(119.51, 120.59)
# print(round(lat, 2), round(lon, 2))
return round(lat, 2), round(lon, 2)
elif city == "苏州市":
lat = random.uniform(30.75, 32.03)
lon = random.uniform(119.91, 121.38)
# print(round(lat, 2), round(lon, 2))
return round(lat, 2), round(lon, 2)
return citydef data(self):
a = self.rdm_province()
b = self.rdm_city(a)
c = self.rdm_address(b)
d,e = self.rdm_lat_and_lon(b)
dict ={"gps1": {"province": a,
"city": b,
"address": c,
"location": {"lat": d,
"lon": e}}}
print(dict)
return json.dumps(dict)if __name__ == "__main__":
# for i in range(10):
r = Test_Data()
r.data()
运行结果如下: 【使用python造测试参数01】#######第一次运行结果:
文章图片
第一次运行结果.png 第二次运行结果:
文章图片
第二次运行结果.png
推荐阅读
- 由浅入深理解AOP
- 【译】20个更有效地使用谷歌搜索的技巧
- mybatisplus如何在xml的连表查询中使用queryWrapper
- MybatisPlus|MybatisPlus LambdaQueryWrapper使用int默认值的坑及解决
- MybatisPlus使用queryWrapper如何实现复杂查询
- python学习之|python学习之 实现QQ自动发送消息
- 逻辑回归的理解与python示例
- 生活建造家|生活建造家 | 疫情后56%的人想回乡建别墅
- python自定义封装带颜色的logging模块
- 【Leetcode/Python】001-Two|【Leetcode/Python】001-Two Sum