Skip to content

Functions to add functions

Steven Li edited this page Mar 23, 2017 · 2 revisions

Test_Steps provides a way to add your own pass/fail functions via a simple way. addBioOperator, getOpWrapper

addBiOperator(op, func)

To add a pass/fail function, and map a operator to it. e.g. addBiOperator('=d=', compDate) This is to add compDate to the pass/fail functions (to add auto-log function), and =d= is the operator could be used in step/steps functions.

getOpWrapper(op)

Return a pass/fail function using the op defined in addBiOperator.

Example, Add more operators/check functions via 3 steps

For different product, or scenarios, some other operation you may want to define and add them for logging, it's easy based on this framework.

Define a comparing function for two expressions, e.g., to compare to date string

compDate('1/4/2015', '01-04-2015') return True

def compDate(date1, date2): import re pattern = re.compile(r'(\d+).(\d+).(\d+)') match1 = pattern.match(date1) match2 = pattern.match(date2) day1, month1, year1 = (int(i) for i in match1.group(1,2,3)) day2, month2, year2 = (int(i) for i in match2.group(1,2,3)) return (year1==year2) and (month1==month2) and (day1==day2) Register it into the test_steps framework:

bind the compDate function with '=d=' operator

After this step, you can directly use the operator in step/steps/s functions

addBiOperator('=d=', compDate) Get the opWapperFunction sameDate = getOpWrapper('=d=') Now, everything is good, you can write the following steps in your scripts now, and everything will be auto logged.

sameDate("01/03/2015", "1-3-2015", "description: this step should pass") check(" '03/05/2014' =d= '3/5/2014' ") Currently, just binary operators are supported.

Init_testbed function

Pre-defined pass/fail functions

Test Step/steps functions

Test Log functions

Functions to add functions

Clone this wiki locally