Added a verifyElementInList utility function

The purpose is to verify a given element in list
at a given position with few error checks like
list type,empty list and position
Returns appropriate codes based upon the inputs.
Can be used under tests instead of multiple asserts

Signed-off-by: Santhosh Edukulla <Santhosh.Edukulla@citrix.com>

Conflicts:
	tools/marvin/marvin/codes.py
This commit is contained in:
Santhosh Edukulla 2013-11-01 16:55:07 +05:30 committed by Girish Shilamkar
parent e7b6ee10ed
commit b18e730108
2 changed files with 45 additions and 0 deletions

View File

@ -35,3 +35,8 @@ RECURRING = "RECURRING"
ENABLED = "Enabled"
NETWORK_OFFERING = "network_offering"
ROOT = "ROOT"
INVALID_INPUT = "INVALID INPUT"
EMPTY_LIST = "EMPTY_LIST"
FAIL = 0
PASS = 1
MATCH_NOT_FOUND = "ELEMENT NOT FOUND IN THE INPUT"

View File

@ -351,3 +351,43 @@ def validateList(inp):
ret[2] = EMPTY_LIST
return ret
return [PASS, inp[0], None]
def verifyElementInList(inp, toverify, pos = 0):
'''
@name: verifyElementInList
@Description:
1. A utility function to validate
whether the input passed is a list.
The list is empty or not.
If it is list and not empty, verify
whether a given element is there in that list or not
at a given pos
@Input:
I : Input to be verified whether its a list or not
II : Element to verify whether it exists in the list
III : Position in the list at which the input element to verify
default to 0
@output: List, containing [ Result,Reason ]
Ist Argument('Result') : FAIL : If it is not a list
If it is list but empty
PASS : If it is list and not empty
and matching element was found
IIrd Argument( 'Reason' ): Reason for failure ( FAIL ),
default to None.
INVALID_INPUT
EMPTY_LIST
MATCH_NOT_FOUND
'''
if toverify is None or toverify == '' \
or pos is None or pos < -1 or pos == '':
return [FAIL, INVALID_INPUT]
out = validateList(inp)
if out[0] == FAIL:
return [FAIL, out[2]]
if out[0] == PASS:
if len(inp) > pos and inp[pos] == toverify:
return [PASS, None]
else:
return [FAIL, MATCH_NOT_FOUND]