Packaging tools need to use:
1, the package read the Excel-based tool, where the choices are pandas:
import pandas as pd path = 'test.xlsx' sheet_name = 'test_data' class with_excel: # Constructor runs when you call class DEF __init__ (Self, path = None, sheet_name = None): IF path and sheet_name: self.path = path self.sheet_name = sheet_name else: self.path = 'test.xlsx' self.sheet_name = 'test_data' self.data = self.open_excel() # Get tabular data DEF open_excel (Self): df = pd.read_excel(self.path, self.sheet_name) return df # Get the number of cells in the row table DEF get_lines (Self): Lines = self.data.shape [0] # Get the number of lines of the last row return Lines # Get the contents of a cell (multi-line content acquisition) DEF get_cell_data (Self, Row, COL): return self.data.iloc [Row, COL] # Tabular data transfer dictionary DEF to_dict (Self): TEST_DATA = [] for I in self.data.index.values: # acquires dictionary data corresponding to the header ROW_DATA = self.data.loc [I] .to_dict () test_data.append(row_data) return test_data if __name__ == '__main__': aa = with_excel(path, sheet_name)
2, the encapsulation process json tools:
import json class open_json: def __init__(self, filename): self.data = self.read_data(filename) # Open json file def read_data(self, filename): with open(filename) as fp: data = json.load(fp) return data Acquiring data corresponding to # json def get_data(self, data_id): return self.data[data_id]
3, the encapsulation method mock
import mock # Analog interface returns the data using mock def mock_test(mock_method, request_data, url, method, response_data): mock_method = mock.Mock(return_value=response_data) res = mock_method(url, method, request_data) return res
4, the package requests
import requests import json class RunMethod: def post_main(self, url, data, header): if header != None: res = requests.post(url=url, data=data, headers=header) else: res = requests.post(url=url, data=data) return res def get_main(self, url, data, header): if header !=None: res = requests.get(url=url, data=data, headers=header) else: res = requests.get(url=url, data=data) return res def run_main(self, method, url, data=None, header=None): if method == 'post': res = self.post_main(url, data, header) else: res = self.get_main(url, data, header) return json.dumps(res, ensure_ascii=False, sort_keys=True, indent=4)