一些测试开发,主要关注开发平台,至于平台对测试有没有用,有多大用,就不关心了
又被淘宝的运营秀了一脸,特价版淘宝横空出世
很棒的感觉,不知道能否继承到 HttpRunner 中?
请教一下,这个 addict 支持 python 2 的 utf-8 么?
{'name_1': {u'msg': u'ok', u'code': u'0', u'data': {u'regionPath': u',root000000,c10e92a6-c090-4955-bdab-63eba5965c0a,', u'leaf': True, u'regionStatus': 0, u'dataVersion': 328, u'regionCodeStyle': u'none', u'indexCode': u'c10e92a6-c090-4955-bdab-63eba5965c0a', u'regionId': u'c10e92a6-c090-4955-bdab-63eba5965c0a', u'parentIndexCode': u'root000000', u'regionType': 0, u'regionCode': u'', u'parentId': u'root000000', u'disOrder': 91, u'regionDesc': u'', u'regionName': u'test1'}}}
这样的要如何处理?
if __name__ == '__main__':
all_list = ["1", "2", "3", "4", "5", {"test1": "1", "test2": "2", "test3": "3", "test9": [{"test6": "6"}, {"test7": "7"}, {"test8": "8"}], "test4": {"x": "9", "y": "0"}, "test5": "5"}]
check_list = ["3", "5", {"test3": "3", "test4": {"y": "0"}, "test9": [{"test7": "7"}]}]
print compare_json(all_list, check_list)
目前我也在做类似的内容,字典和列表互相嵌套,想直接作对比,看两者是否是包含关系。主要参考了你的代码,但觉得自己写的内容,过于繁琐,想了解下你后续的探索。
代码如下:
def compare_json(responce_data, check_data):
if isinstance(responce_data, dict) and isinstance(check_data, dict):
compare_json = compare_dict(responce_data, check_data)
elif isinstance(responce_data, list) and isinstance(check_data, list):
compare_json = compare_list(responce_data, check_data)
else:
compare_json = False
print "Please check responce_data: %s, check_data: %s. They are not dict or list." % (responce_data, check_data)
return compare_json
if compare_json:
print "responce_data: %s\ncheck_data: %s\nCheck Success!" % (responce_data, check_data)
else:
print "responce_data: %s\ncheck_data: %s\nCheck Fail!" % (responce_data, check_data)
def compare_dict(all_dict, check_dict):
global compare_dict_status
for (check_key, check_value) in check_dict.items():
for (all_key, all_value) in all_dict.items():
compare_dict_status = False
if operator.eq(check_key, all_key):
if isinstance(check_value, dict) and isinstance(all_value, dict):
#print "Dict::Dict check_value is %s, all_value is %s" % (check_value, all_value)
compare_dict_status = compare_dict(all_value, check_value)
if compare_dict_status:
break
elif isinstance(check_value, list) and isinstance(all_value, list):
#print "List::List check_item is %s, all_item is %s" % (check_value, all_value)
compare_dict_status = compare_list(all_value, check_value)
if compare_dict_status:
break
else:
if operator.eq(check_value, all_value):
print "%s:%s is in the %s" % (check_key, check_value, all_dict)
compare_dict_status = True
break
if not compare_dict_status:
print "Can't find %s:%s in the %s" % (check_key, check_value, all_dict)
return compare_dict_status
return compare_dict_status
def compare_list(all_list, check_list):
global compare_list_status
for check_item in check_list:
for all_item in all_list:
compare_list_status = False
if isinstance(check_item, list) and isinstance(all_item, list):
compare_list_status = compare_list(all_item, check_item)
#print "List::List check_item is %s, all_item is %s, compare_list_status is %s" % (check_item, all_item, compare_list_status)
if compare_list_status:
break
elif isinstance(check_item, dict) and isinstance(all_item, dict):
compare_list_status = compare_dict(all_item, check_item)
#print "Dict::Dict check_item is %s, all_item is %s, compare_list_status is %s" % (check_item, all_item, compare_list_status)
if compare_list_status:
break
else:
if operator.eq(check_item, all_item):
print "%s is in the %s" % (check_item, all_list)
compare_list_status = True
break
if not compare_list_status:
print "Can't find %s in the %s" % (check_item, all_list)
return compare_list_status
return compare_list_status