refactor(): 优化测试用例数据的处理,优化代码结构
- 新增用例生成器和注册器 - 优化文件处理
This commit is contained in:
34
commons/file_processors/base_processor.py
Normal file
34
commons/file_processors/base_processor.py
Normal file
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env python
|
||||
# coding=utf-8
|
||||
|
||||
"""
|
||||
@author: CNWei
|
||||
@Software: PyCharm
|
||||
@contact: t6i888@163.com
|
||||
@file: base
|
||||
@date: 2025/3/4 17:23
|
||||
@desc:
|
||||
"""
|
||||
import abc
|
||||
from pathlib import Path
|
||||
from typing import Union
|
||||
|
||||
|
||||
class BaseFileProcessor(abc.ABC): # 使用 abc 模块定义抽象基类
|
||||
"""
|
||||
文件处理器的抽象基类。
|
||||
定义了所有子类必须实现的方法。
|
||||
"""
|
||||
def __init__(self, filepath: Union[str, Path], **kwargs):
|
||||
|
||||
self.filepath: Path = Path(filepath) # 确保 filepath 是 Path 对象
|
||||
|
||||
@abc.abstractmethod
|
||||
def load(self) -> dict:
|
||||
"""加载."""
|
||||
raise NotImplementedError
|
||||
|
||||
@abc.abstractmethod
|
||||
def save(self, data: dict, new_filepath: Union[str, Path, None] = None) -> None:
|
||||
"""将数据保存."""
|
||||
raise NotImplementedError
|
||||
Reference in New Issue
Block a user