A WriteData function is used in the project to save the configurations entered by the user. in order to verify the user input requirements, the python modifier is used without affecting the interface usage, the code snippet demonstrates how to verify that the input parameters of the WriteData function call different verification function check inputs according to different configuration files. You can change the logic of the verification function as needed.
The code is as follows:
Def VerifyData (func ):
Def VerifyInt (data ):
Assert (int (data)> 0)
Def VerifyString (data ):
Assert (len (data)> 10)
Def inner (* args, ** kvargs ):
Print args
Print kvargs
Assert (len (args)> 1)
If args [1] = "int.txt ":
VerifyInt (args [0])
Elif args [1] = "string.txt ":
VerifyString (args [0])
Func (* args, ** kvargs)
Return inner
@ VerifyData
Def WriteData (text, filepath ):
Print "WriteData"
Print text
Print filepath
WriteData ("1234567890", "int.txt ")