乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      python接口自動(dòng)化讀取json、yaml、ini文件

       昵稱71011036 2020-08-10
      1. import yaml
      2. import json
      3. from configparser import ConfigParser
      4. from common.logger import logger
      5. class MyConfigParser(ConfigParser):
      6. # 重寫 configparser 中的 optionxform 函數(shù),解決 .ini 文件中的 鍵option 自動(dòng)轉(zhuǎn)為小寫的問題
      7. def __init__(self, defaults=None):
      8. ConfigParser.__init__(self, defaults=defaults)
      9. def optionxform(self, optionstr):
      10. return optionstr
      11. class ReadFileData():
      12. def __init__(self):
      13. pass
      14. def load_yaml(self, file_path):
      15. logger.info("加載 {} 文件......".format(file_path))
      16. with open(file_path, encoding='utf-8') as f:
      17. data = yaml.safe_load(f)
      18. logger.info("讀到數(shù)據(jù) ==>> {} ".format(data))
      19. return data
      20. def load_json(self, file_path):
      21. logger.info("加載 {} 文件......".format(file_path))
      22. with open(file_path, encoding='utf-8') as f:
      23. data = json.load(f)
      24. logger.info("讀到數(shù)據(jù) ==>> {} ".format(data))
      25. return data
      26. def load_ini(self, file_path):
      27. logger.info("加載 {} 文件......".format(file_path))
      28. config = MyConfigParser()
      29. config.read(file_path, encoding="UTF-8")
      30. data = dict(config._sections)
      31. # print("讀到數(shù)據(jù) ==>> {} ".format(data))
      32. return data
      33. ini_data = ReadFileData().load_ini('C:\\Users\\heguanghua\\Downloads\\pytestDemo-master\\config\\setting.ini')
      34. print(ini_data)
      35. json_data = ReadFileData().load_json('C:\\Users\\heguanghua\\Downloads\\pytestDemo-master\\data\\test_data.json')
      36. print(json_data)
      37. yml_data = ReadFileData().load_yaml('C:\\Users\\heguanghua\\Downloads\\pytestDemo-master\\data\\api_test_data.yml')
      38. print(yml_data)

      運(yùn)行結(jié)果:

      1. D:\Users\heguanghua\AppData\Local\Programs\Python\Python35\python.exe C:/Users/heguanghua/Downloads/pytestDemo-master/common/read_data.py
      2. {'host': OrderedDict([('api_root_url', 'http://127.0.0.1:8000')]), 'mysql': OrderedDict([('MYSQL_HOST', '172.20.0.91'), ('MYSQL_PORT', '3305'), ('MYSQL_USER', 'root'), ('MYSQL_PASSWD', '123456'), ('MYSQL_DB', 'demo')])}
      3. [2020-07-10 15:25:13,371][read_data.py 35][INFO]: 加載 C:\Users\heguanghua\Downloads\pytestDemo-master\config\setting.ini 文件......
      4. {'user1': {'account': 'admin', 'password': '654321', 'message': '登錄成功'}, 'user2': {'account': 'admins', 'password': '654321', 'message': '登錄成功'}}
      5. [2020-07-10 15:25:13,372][read_data.py 28][INFO]: 加載 C:\Users\heguanghua\Downloads\pytestDemo-master\data\test_data.json 文件......
      6. [2020-07-10 15:25:13,372][read_data.py 31][INFO]: 讀到數(shù)據(jù) ==>> {'user1': {'account': 'admin', 'password': '654321', 'message': '登錄成功'}, 'user2': {'account': 'admins', 'password': '654321', 'message': '登錄成功'}}
      7. [2020-07-10 15:25:13,372][read_data.py 21][INFO]: 加載 C:\Users\heguanghua\Downloads\pytestDemo-master\data\api_test_data.yml 文件......
      8. {'test_update_user': [[4, '123456', '13500010014', '1', '深圳市寶安區(qū)', True, 0, '修改用戶信息成功'], [4, '123456', '1350001001', '1', '深圳市寶安區(qū)', False, 4008, '手機(jī)號(hào)格式不正確'], [111, '123456', '13500010014', '1', '深圳市寶安區(qū)', False, 4005, '用戶ID不存在']], 'test_get_all_user_info': [[True, '999999', '查詢成功!']], 'test_login_user': [['wintest', '123456', True, 0, '登錄成功'], ['測試test', '123456', False, 1003, '用戶名不存在']], 'test_delete_user': [['測試test', True, 0, '刪除用戶信息成功'], ['wintest3', False, 3006, '該用戶不允許刪除']], 'test_get_get_one_user_info': [['wintest4', True, 0, '查詢成功'], ['wintest1111', False, '1004', '查不到相關(guān)用戶']], 'test_register_user': [['測試test', '123456', '13599999999', '1', '深圳市寶安區(qū)', True, 0, '注冊(cè)成功'], ['測試test', '123456', '13599999999', '3', '深圳市寶安區(qū)', False, 2003, '輸入的性別只能是 0(男) 或 1(女)'], ['wintest4', '123456', '13599999999', '1', '深圳市寶安區(qū)', False, 2002, '用戶名已存在']]}
      9. [2020-07-10 15:25:13,385][read_data.py 24][INFO]: 讀到數(shù)據(jù) ==>> {'test_update_user': [[4, '123456', '13500010014', '1', '深圳市寶安區(qū)', True, 0, '修改用戶信息成功'], [4, '123456', '1350001001', '1', '深圳市寶安區(qū)', False, 4008, '手機(jī)號(hào)格式不正確'], [111, '123456', '13500010014', '1', '深圳市寶安區(qū)', False, 4005, '用戶ID不存在']], 'test_get_all_user_info': [[True, '999999', '查詢成功!']], 'test_login_user': [['wintest', '123456', True, 0, '登錄成功'], ['測試test', '123456', False, 1003, '用戶名不存在']], 'test_delete_user': [['測試test', True, 0, '刪除用戶信息成功'], ['wintest3', False, 3006, '該用戶不允許刪除']], 'test_get_get_one_user_info': [['wintest4', True, 0, '查詢成功'], ['wintest1111', False, '1004', '查不到相關(guān)用戶']], 'test_register_user': [['測試test', '123456', '13599999999', '1', '深圳市寶安區(qū)', True, 0, '注冊(cè)成功'], ['測試test', '123456', '13599999999', '3', '深圳市寶安區(qū)', False, 2003, '輸入的性別只能是 0(男) 或 1(女)'], ['wintest4', '123456', '13599999999', '1', '深圳市寶安區(qū)', False, 2002, '用戶名已存在']]}

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多