refactor(): 优化文件读取,变量替换等
- 优化用例加载模块器 - 新增JSON文件读取模块
This commit is contained in:
@@ -13,7 +13,6 @@ import copy
|
||||
import logging
|
||||
import re
|
||||
import string
|
||||
import inspect
|
||||
from commons.funcs import Funcs
|
||||
|
||||
|
||||
@@ -26,12 +25,6 @@ class Template(string.Template):
|
||||
2,参数也可以是变量
|
||||
"""
|
||||
|
||||
# FUNC_MAPPING = {
|
||||
# "int": int,
|
||||
# "float": float,
|
||||
# "bool": bool
|
||||
# } # 内置函数有的,直接放入mapping;内置函数没有的,在funcs中定义,自动放入mapping
|
||||
|
||||
call_pattern = re.compile(r"\${(?P<func_name>.*?)\((?P<func_args>.*?)\)}")
|
||||
|
||||
def render(self, mapping: dict) -> str:
|
||||
@@ -68,28 +61,3 @@ class Template(string.Template):
|
||||
|
||||
return self.call_pattern.sub(convert, template)
|
||||
|
||||
|
||||
# def hot_load():
|
||||
# from commons import funcs
|
||||
#
|
||||
# for func_name in dir(funcs): # 遍历模块中的所有函数
|
||||
# if func_name.startswith("_"):
|
||||
# continue
|
||||
# func_code = getattr(funcs, func_name) # 取到函数对象
|
||||
# # print(func_code)
|
||||
# if callable(func_code): # 如果是一个可以调用的函数
|
||||
# Template.FUNC_MAPPING[func_name] = func_code # 函数放到Template中
|
||||
# print(Template.FUNC_MAPPING)
|
||||
# # if inspect.isfunction(func_code): # 如果是一个可以调用的函数
|
||||
# # Template.FUNC_MAPPING[func_name] = func_code # 函数放到Template中
|
||||
# # print(Template.FUNC_MAPPING)
|
||||
|
||||
# def hot_load():
|
||||
# from commons.funcs import Funcs
|
||||
#
|
||||
# print(Funcs.FUNC_MAPPING)
|
||||
# # if inspect.isfunction(func_code): # 如果是一个可以调用的函数
|
||||
# # Template.FUNC_MAPPING[func_name] = func_code # 函数放到Template中
|
||||
# # print(Template.FUNC_MAPPING)
|
||||
#
|
||||
# hot_load()
|
||||
|
||||
Reference in New Issue
Block a user