hand模块¶
-
mohand_plugin_expect.hand.
expect
(*dargs, **dkwargs)[源代码]¶ 将被装饰函数封装为一个
click.core.Command
类,成为mohand
的子命令该装饰器可能被作为一个简单无参数的装饰器使用(如:
@hand.expect
) 或者包含定制其行为的含参数装饰器使用(如:@hand.expect(timeout=30)
)注解
该装饰器最终会通过插件系统被注册到
hands.hand
中。此处的
expect
装饰器本身是应该不支持无参数装饰的,但考虑到其作为样例实现, 故将其实现为兼容两种传参的装饰器参数: 返回: 被封装后的函数
返回类型: function
-
class
mohand_plugin_expect.hand.
Child
(*args, **kwargs)[源代码]¶ 基类:
object
pexpect实例创建后的返回子线程,支持一系列接口方法
-
action
(expect, sendline, before='', retry=3, timeout=5, expect_callback=None, **kwargs)[源代码]¶ 执行一个action,当检测到符合指定
before
的expect
后, 发送sendline
参数: - expect (str) – 期望的输入匹配行,支持多对象的列表,以及正则表达式对象 如:[‘good’, ‘bad’, re.compile(r’\d’), pexpect.EOF, pexpect.TIMEOUT]
- sendline (str or regex) – 发送一行字串,若为正则表达式,则发送匹配到的结果字串
- before (str) – 可选,用来辅助判定期望的输入匹配行,默认为
''
- retry (int) – (已弃用)可选,默认为
3
,重试次数 - timeout (int) – 可选,单位秒,默认为
5
, 单条动作中expect
的超时时间 - expect_callback (function(index)) – expect 的回调函数,传入 expect 列表中匹配到的对象的索引, 可在其中执行定制的处理逻辑
-