1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import json
- import os
- import yaml
- # 获取项目根目录
- def get_project_path():
- return os.path.abspath(os.getcwd().split("common")[0])
- # 读取
- def read_yaml(key):
- with open(os.getcwd() + '/extract.yaml', mode='r', encoding='utf-8') as f:
- value = yaml.load(stream=f, Loader=yaml.FullLoader)
- return value[key]
- # 读取
- # 写入
- def write_yaml(data):
- with open(os.getcwd() + '/extract.yaml', mode='a', encoding='utf-8') as f:
- value = yaml.dump(data, stream=f, allow_unicode=True)
- return value
- # 清空
- def clear_yaml():
- with open(os.getcwd() + '/extract.yaml', mode='w', encoding='utf-8') as f:
- f.truncate()
- def clear_out_yaml():
- with open(os.getcwd() + '/out_time_url.yaml', mode='w', encoding='utf-8') as f:
- f.truncate()
- # 读取测试用列
- def read_testcase(yaml_path):
- with open(yaml_path, mode='r', encoding='utf-8') as f:
- value = yaml.load(stream=f, Loader=yaml.FullLoader)
- return value
- # 读取conftest,yaml
- def read_config_yaml(one_node, two_nede):
- with open(get_project_path() + '/config.yaml', mode='r', encoding='utf-8') as f:
- value = yaml.load(f, Loader=yaml.FullLoader)
- return value[one_node][two_nede]
- def read_yaml_out_time_url():
- with open(get_project_path() + '/out_time_url.yaml', mode='r', encoding='utf-8') as f:
- value = yaml.load(f, Loader=yaml.FullLoader)
- return value
- def write_yaml_out_time_url(data):
- with open(os.getcwd() + '/out_time_url.yaml', mode='a', encoding='utf-8') as f:
- value = yaml.dump(data, stream=f, allow_unicode=True)
- return value
- # #读取数据得yaml
- def read_data_yaml(yaml_path):
- with open(get_project_path() + yaml_path, mode='r', encoding='utf-8') as f:
- value = yaml.load(stream=f, Loader=yaml.FullLoader)
- return value
- def read_case(yaml_path):
- with open(os.getcwd() + yaml_path, mode='r', encoding='utf-8') as f:
- value = yaml.load(stream=f, Loader=yaml.FullLoader)
- return value
- if __name__ == '__main__':
- print(os.path.abspath(os.getcwd().split("common")[0]))
|