数据驱动,关键字驱动,混合驱动简单模型

数据驱动:

data=[(1,1,2),(2,2,4),(3,3,9)]

def execute(t):
    result=0
    for i in t[:-1]:
        result+=i
    return result

if __name__=="__main__":
    for i in data:
        actual_result=execute(i)
        expected_result=i[-1]
     try:
        assert actual_result== expected_result
        print("pass--->actual_result=%s expected_result=%s"%(actual_result,expected_result))
        except AssertionError:
        print("fail--->actual_result=%s expected_result=%s"%(actual_result,expected_result))

 

关键字驱动:

def add(*args):
    result=0
    for i in args:
        result+=i
    return result

def sub(*args):
    result=args[0]
    for i in args[1:]:
        result-=i
    return result

def handleTestData(filepath):
    with open(filepath) as fp:
        content=fp.readlines()
    data=[ i.split("||") for i in content ]
    return data

if __name__=="__main__":
    filepath="d:\\pydelete\\0628\\a.txt"
    data=handleTestData(filepath)
    for i in data:
        func=i[0]
        testdata=[ int(j) for j in i[1:-1]]
        expected_result=i[-1]
        try:
            if func=="add":
                actual_result=add(*testdata)
                assert actual_result==int(expected_result)
                print("pass--->func is %s actual_result=%s expected_result=%s" %(func,actual_result,expected_result))
            elif func=="sub":
                actual_result=sub(*testdata)
                assert actual_result==int(expected_result)
                print("pass--->func is %s actual_result=%s expected_result=%s" %(func,actual_result,expected_result))
        except AssertionError: 
            print("fail--->func is %s actual_result=%s expected_result=%s"%(func,actual_result,expected_result))

上一篇:解决 VSCode 编辑 vue 项目报错 Expected indentation of 2 spaces but found 4


下一篇:Parsing error: Expression expected.