I have nested list below as test_data which is my input also and expected_data is the formatted output my question now is how to get expected output from test_data.
###Input given
###Expected Output --
##this is what I have tried
I have no clue how to restructure it in nested dictionary form as shown for expected_data
###Input given
Code:
test_data = [[u'', u'Sr. No.', u'TestCase ID', u'Iteration', u'Pre-requisites', u'Action:Parameter:Verification'],
[u'', 1.0, u'IAE_001', 1.0, u"SET_MOBILE_NETWORK:DUT1:DUT1,network='TBD'\nSET_MOBILE_NETWORK:DUT2:DUT2,network='TBD'",'SEND_SMS:DUT1,DUT2,Msg:DUT1,Msg="Test Message",MsgState=\'Delivered\'\nRECEIVE_SMS:DUT2,DUT1,Msg:DUT2,Msg="Test Message",MsgState=\'Read\''],
[u'', 2.0, u'IAE_002', 1.0, u"SET_MOBILE_NETWORK:DUT1:DUT1,network='TBD'\nSET_MOBILE_NETWORK:DUT2:DUT2,network='TBD'\nSET_MOBILE_DATA_ON:DUT1\nSET_MOBILE_DATA_ON:DUT2", u'SEND_SMS:DUT1,DUT2,Msg:DUT1,Msg="Test Message",MsgState=\'Delivered\'\nRECEIVE_SMS:DUT2,DUT1,Msg:DUT2,Msg="Test Message",MsgState=\'Read\'\nSET_MOBILE_DATA_OFF:DUT1\nSET_MOBILE_DATA_OFF:DUT2']]
Code:
expected_data = {
'AMBS_001':{
'Iteration': 1,
'Pre-requisites': ["ADV_MSG_ENABLE:DUT1:DUT1,mode='enabled'",
"ADV_MSG_ENABLE:DUT2:DUT1,mode='enabled'",
"WEB_APP_LOGIN:DUT1"],
'Action:Parameter:Verification':["SEND_SMS:DUT1,DUT2,Msg:DUT1,Msg=\"Test Message\",MsgState='Delivered',MsgMode='Pager'",
"READ_SMS:DUT1,DUT2,Msg:DUT2,Msg=\"Test Message\",MsgState='Read',MsgMode='Pager'"]
},
'AMBS_002':{
'Iteration': 2,
'Pre-requisites':["ADV_MSG_ENABLE:DUT1:DUT1,mode='enabled'",
"ADV_MSG_ENABLE:DUT2:DUT1,mode='enabled'",
"WEB_APP_LOGIN:DUT1",
"WEB_APP_LOGIN:DUT2"],
'Action:Parameter:Verification':["AIRPLANE_MODE_ON:DUT1:DUT1,mode='enabled' (AIRPLANE_MODE:DUT1,ON:DUT1,MODE=(ON))",
"SEND_SMS:DUT1,DUT2,Msg:DUT1,Msg=\"Test Message\",MsgState='Delivered',MsgMode='Pager'",
"AIRPLANE_MODE_OFF:DUT1:DUT1,mode='disabled'",
"WEB_APP_READ_SMS:DUT2,DUT1,Msg:DUT2,Msg=\"Test Message\",MsgState='Read',MsgMode='Pager'"]
}
}
Code:
heading=test_data.pop(0)
print heading
[u'', u'Sr. No.', u'TestCase ID', u'Iteration', u'Pre-requisites', u'Action:Parameter:Verification']
test_data1=test_data.pop(0)
print test_data1
[u'', 1.0, u'IAE_001', 1.0, u"SET_MOBILE_NETWORK:DUT1:DUT1,network='TBD'\nSET_MOBILE_NETWORK:DUT2:DUT2,network='TBD'", 'SEND_SMS:DUT1,DUT2,Msg:DUT1,Msg="Test Message",MsgState=\'Delivered\'\nRECEIVE_SMS:DUT2,DUT1,Msg:DUT2,Msg="Test Message",MsgState=\'Read\'']
test_data2=test_data.pop(0)
print test
Traceback (most recent call last):
File "<pyshell#56>", line 1, in <module>
print test
NameError: name 'test' is not defined
_
print test_data2
[u'', 2.0, u'IAE_002', 1.0, u"SET_MOBILE_NETWORK:DUT1:DUT1,network='TBD'\nSET_MOBILE_NETWORK:DUT2:DUT2,network='TBD'\nSET_MOBILE_DATA_ON:DUT1\nSET_MOBILE_DATA_ON:DUT2", u'SEND_SMS:DUT1,DUT2,Msg:DUT1,Msg="Test Message",MsgState=\'Delivered\'\nRECEIVE_SMS:DUT2,DUT1,Msg:DUT2,Msg="Test Message",MsgState=\'Read\'\nSET_MOBILE_DATA_OFF:DUT1\nSET_MOBILE_DATA_OFF:DUT2']
Comment