zoukankan      html  css  js  c++  java
  • Behave step matcher

    • behave 提供3中step匹配模式
    • 'parse'
    • 'cfparse' 基于parse的扩展,  支持cardinality field syntax?
    • 're' 支持在step中定义正则表达式

    'parse'  是默认的step mathcer,  他被使用最多, 有以下特点

    • 上手容易, 易读性好, 好理解
    • 支持预定义的数据类型和用户自定义类型
    • 可以在自定义数据类型中使用re, 在step_impl中隐藏了re, 可读性好

    'cfparse' 是parse的扩展, 设计初衷是替代parse, 它有以下特点

    • 继承parse, 支持 the cardinality field syntax
    • 自动创建缺少的类型转换函数for fields with cardinality field part
    • 基于parse_type

    're'有以下特点

    • addresses some cases that cannot be solved otherwise (currently)
    • is backward compatible to cucumber (uses regular expressions)
    • is less ambiguous compared to the “parse” matcher (currently)

    定义step matcher的两种方法

    •  在environment.py中定义默认的matcher
      # -- FILE: features/environment.py
      from behave import use_step_matcher
      
      # -- SELECT DEFAULT STEP MATCHER: Use "re" matcher as default.
      # use_step_matcher("parse")
      # use_step_matcher("cfparse")
      use_step_matcher("re")
    • 在step definition文件中切换step matcher, 同样使用use_step_matcher("re")
      从切换step matcher行后的所有step_impl都使用你切换的step matcher, 除非你再次切换

    正则匹配

    # 简单的group捕获, 并赋值给P<test>
    #
    -- SIMPLE GROUP: foo @when(u'I try to match "(?P<foo>foo)"') def step_when_I_try_to_match_foo(context, foo): context.foo = foo # -- SIMPLE GROUP: anything else @when(u'I try to match "(?P<anything>.*)"') def step_when_I_try_to_match_anything_else(context, anything): context.anything = anything

    # 可选的的group: (?P<an_>an )?
    @when(u'I try to match (?P<an_>an )?optional "(?P<foo>foo)"') def step_when_I_try_to_match_an_optional_foo(context, an_, foo): context.foo = foo context.an_ = an_

    # 套嵌的正则

    @when(u'I try to match nested "(?P<foo>foo(?P<bar>bar)?)"') def step_when_I_try_to_match_nested_foobar(context, foo, bar): context.foo = foo context.bar = bar
     
  • 相关阅读:
    DIV 实现可拖拽 功能(留档)
    JS网站当前日期在IE9、Chrome和FireFox中年份显示为113年的解决方法 getFullYear();
    ASP.Net MVC C#画图 页面调用
    iOS NSDecimalNumber 货币计算 四舍五入
    [日记]寒假发生了什么
    [其他]寒假作业是什么
    [考试总结]近期第一次在下午考的一场考试
    [考试总结]不写部分分下场会很惨的一场考试
    [考试总结]毒瘤题×4的一场考试
    [考试总结]出数据变成做构造题的一场考试
  • 原文地址:https://www.cnblogs.com/v394435982/p/6402451.html
Copyright © 2011-2022 走看看