testbase.resource
Package¶
资源管理模块
包括:协作机管理及测试资源文件管理
-
exception
testbase.resource.
DownloadFileError
(url, status_code, msg, headers, data)¶ 基类:
exceptions.Exception
download file failed
-
class
testbase.resource.
IResourceManagerBackend
¶ 基类:
object
测试资源管理后端接口定义
-
acquire_resource
(session_id, res_type, res_group, condition)¶ 申请资源
参数: - session_id (str) -- 会话ID
- res_type (str) -- 资源类型
- res_group -- 资源分组
- condition (dict) -- 资源属性匹配
返回: 资源
Rtypes: dict
-
destroy_session
(session_id)¶ 销毁会话
参数: session_id (str) -- 会话ID
-
get_file
(path)¶ 获取一个文件资源
参数: path (str) -- 相对于resources目录的文件路径 返回: 文件绝对路径 Rtypes: str
-
iter_managed_resource
()¶ 查询全部托管的资源(支持初始化&反初始化)
返回: iterator of (res_type, resource) Rtypes: iterator(res_type, resource)
-
list_dir
(path)¶ 获取一个文件资源
参数: path (str) -- 相对于resources目录的文件夹路径 返回: 文件绝对路径 Rtypes: str
-
release_resource
(session_id, res_type, resource_id)¶ 释放资源
参数: - session_id (str) -- 会话ID
- res_type (str) -- 资源类型
- resource_id (str) -- 资源ID
-
walk
(path)¶ 遍历一个文件路径
参数: path (str) -- 相对于resources目录的文件夹路径 返回: 返回一个迭代器,每次迭代对应一个(dir_path, dir_names, file_names)的元组 Rtypes: iterator
-
-
class
testbase.resource.
LocalCSVResourceHandler
(csv_path, resource_lock_type=<class 'testbase.resource.LocalResourceLock'>)¶ 基类:
testbase.resource.LocalResourceHandler
基于本地CSV文件管理资源
-
iter_resource
(res_type, res_group=None, condition=None)¶ 遍历全部资源(可以按照优先级顺序返回来影响申请资源的优先级)
参数: - res_type (str) -- 资源类型
- res_group (str) -- 资源分组
- condition (dict) -- 资源属性匹配
返回: iterator of resource
Rtypes: iterator(dict)
-
-
class
testbase.resource.
LocalResourceHandler
(resource_lock_type=<class 'testbase.resource.LocalResourceLock'>)¶ 基类:
object
本地资源处理句柄
-
acquire_resource
(session_id, res_type, res_group, condition)¶ 申请资源
参数: - session_id (str) -- 会话ID
- res_type (str) -- 资源类型
- res_group (str) -- 资源分组
- condition (dict) -- 资源属性匹配
返回: 资源
返回类型: dict
-
iter_managed_resource
(res_type)¶ 查询全部托管的资源(支持初始化&反初始化)
返回: iterator of resource Rtypes: iterator(dict)
-
iter_resource
(res_type, res_group=None, condition=None)¶ 遍历全部资源(可以按照优先级顺序返回来影响申请资源的优先级)
参数: - res_type (str) -- 资源类型
- res_group (str) -- 资源分组
- condition (dict) -- 资源属性匹配
返回: iterator of resource, dict type with key 'id'
Rtypes: iterator(dict)
-
release_resource
(session_id, res_type, resource_id)¶ 释放资源
参数: - session_id (str) -- 会话ID
- res_type (str) -- 资源类型
- resource_id (str) -- 资源ID
-
session_created
(session_id, timeout, testcase=None)¶ 通知会话创建
参数: - session_id (str) -- 会话ID
- timeout (int) -- 会话超时时间(秒)
- testcase (testbase.testcase.TestCase) -- 当前用例
-
session_destroyed
(session_id)¶ 通知会话销毁
参数: session_id (str) -- 会话ID
-
-
class
testbase.resource.
LocalResourceLock
(res_type, resource_id)¶ 基类:
object
本地资源锁
-
release
()¶ 释放
-
try_acquire
()¶ 尝试加锁
返回: 是否成功
-
-
class
testbase.resource.
LocalResourceManagerBackend
¶ 基类:
testbase.resource.IResourceManagerBackend
基本本地文件的方式的资源管理
-
abs_path
(relative_path)¶ get resource absolute path : type relative_path:string
param relative_path: ,资源文件相对描述符,相对于setting下的资源目录的路径,支持多级目录 :return:返回资源文件的绝对路径
-
acquire_resource
(session_id, res_type, res_group, condition)¶ 申请资源
-
create_session
(testcase=None)¶ 创建会话
-
destroy_session
(sessionid)¶ 销毁会话
-
get_file
(relative_path)¶ 查找某个文件
:type relative_path:string :param relative_path: 资源文件相对描述符,相对于setting下的资源目录的路径,支持多级目录 :return:返回资源文件的绝对路径
-
iter_managed_resource
()¶ 查询全部托管的资源(支持初始化&反初始化)
返回: iterator(res_type, resource)
-
list_dir
(relative_path)¶ 列出某个目录下的文件
:type relative_path:string :param relative_path: ,资源文件目录相对路径,相对于setting下的资源目录的路径,支持多级目录 :return:返回一个包含资源目录下所有文件或者文件下的相对路径列表
-
classmethod
register_resource_type
(res_type, handler)¶ 注册一个资源类型
-
release_resource
(session_id, res_type, resource_id)¶ 释放资源
-
walk
(path)¶ 获取目录下文件列表
参数: path (str) -- 相对于resources目录的路径,用于遍历文件夹 Return iterators: iterator of (dir_path, dirnames, filenames) tuples
-
-
exception
testbase.resource.
ResourceNotAvailable
¶ 基类:
exceptions.Exception
没有可用的资源
-
class
testbase.resource.
Session
(backend, session_id)¶ 基类:
object
会话
-
acquire_resource
(res_type, res_group=None, condition=None)¶ 申请资源
参数: - res_type (str) -- 资源类型
- res_group -- 资源分组
- condition (dict) -- 资源属性匹配
返回: 资源
Rtypes: dict
-
destroy
()¶ 销毁该会话(全部占用的资源会释放)
-
get_file
(path)¶ 获取测试文件资源
参数: path -- 文件引用路径(相对路径) 返回: 文件路径 Rtypes: str
-
list_dir
(path)¶ 获取目录下文件列表
参数: path -- 目录引用路径(相对路径) 返回: 一个包含该目录下所有文件的绝对路径的list Rtypes: list[str]
-
release_resource
(res_type, resource_id)¶ 释放资源
参数: - res_type (str) -- 资源类型
- resource_id (str) -- 资源ID
-
walk
(path)¶ 获取目录下文件列表
参数: path (str) -- 相对于resources目录的路径,用于遍历文件夹 Return iterators: iterator of (dir_path, dirnames, filenames) tuples
-
-
class
testbase.resource.
TestResourceManager
(backend)¶ 基类:
object
测试资源管理
-
iter_managed_resource
()¶ 查询全部托管的资源(支持初始化&反初始化)
返回: iterator of (res_type, resource) Rtypes: iterator(str, dict)
-
-
testbase.resource.
acquire_resource
(res_type, res_group=None, condition=None)¶ 申请资源
参数: - res_type (str) -- 资源类型
- res_group -- 资源分组
- condition (dict) -- 资源属性匹配
返回: 资源
Rtypes: dict
-
testbase.resource.
get_file
(path)¶ 查找某个文件 :param path: 相对于resources目录的路径,用于查找文件 :type path: str :return:返回资源文件的绝对路径
-
testbase.resource.
iter_resource_paths
()¶ 返回测试项目的全部resources目录
返回:
-
testbase.resource.
list_dir
(path)¶ 列出某个目录下的文件 :param path: 相对于resources目录的路径,用于查找文件夹 :type path: str :returns :返回一个包含资源目录下所有文件或者文件下的绝对路径的list
-
testbase.resource.
release_resource
(res_type, resource_id)¶ 释放资源
参数: - res_type (str) -- 资源类型
- resource_id (str) -- 资源ID
-
testbase.resource.
walk
(path)¶ 遍历某个路径
参数: path (str) -- 相对于resources目录的路径,用于遍历文件夹 Return iterators: iterator of (dir_path, dirnames, filenames) tuples