def test_parse_txml_keys_values(stc): plLogger = PLLogger.GetLogger("test_parse_txml_keys_values") plLogger.LogInfo("begin") attr1 = "Object.Property1" attr2 = "Object.Property2" attr3 = "Object.Property3" attr4 = "Object.Property4" val1 = 12 val2 = "twelve" val3 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] val4 = "12" # Input XML input_xml = str( "<test>" + "<wizard displayName=\"Unit Test Parse Key Vals\" " + "description=\"test parsing key values in TXML\" " + "image=\"\">" + "<page displayName=\"stuff\" description=\"descript\" >" + "<group displayName=\"gbox\">" + "<property id=\"" + attr1 + "\" value=\"" + str(val1) + "\" " + "displayName=\"attr1\" />" + "<property id=\"" + attr2 + "\" value=\"" + str(val2) + "\" " + "displayName=\"attr2\" />" + "<property id=\"" + attr3 + "\" value=\"" + str(val3) + "\" " + "displayName=\"attr3\" />" + "</group></page>" + "<page displayName=\"page2\" description=\"descript\">" + "<group displayName=\"gbox\">" + "<property id=\"" + attr4 + "\" value=\"" + str(val4) + "\" " + "displayName=\"attr4\" />" + "</group></page></wizard></test>") plLogger.LogInfo("input_xml: " + str(input_xml)) root = etree.fromstring(input_xml) assert root is not None key_val_dict, gui_key_val_dict = RunCmd.parse_txml_keys_values(root) assert key_val_dict is not None assert gui_key_val_dict == {} plLogger.LogInfo("key_val_dict: " + str(key_val_dict)) assert len(key_val_dict.keys()) == 4 # Check the keys for kv_pair in zip([attr1, attr2, attr3, attr4], [str(val1), str(val2), str(val3), str(val4)]): assert kv_pair[0] in key_val_dict.keys() assert key_val_dict[kv_pair[0]] == kv_pair[1]
def test_parse_txml_table_keys_values(stc): plLogger = PLLogger.GetLogger("test_parse_table_txml_keys_values") plLogger.LogInfo("begin") attr1 = "Object.Property1" attr2 = "Object.Property2" attr3 = "Object.Property3" attr4 = "Object.Property4" val1 = 12 val2 = "twelve" val3 = True val4 = "331" # Input XML input_xml = str( "<test>" + "<wizard displayName=\"Unit Test Parse Key Vals\" " + "description=\"test parsing key values in TXML\" " + "image=\"\">" + "<page displayName=\"stuff\" description=\"descript\" >" + "<group displayName=\"gbox\">" + "<property id=\"" + attr1 + "\" value=\"" + str(val1) + "\" " + "displayName=\"attr1\">" + "<data>13</data>" + "<data>14</data>" + "<data>15.5</data>" + "</property>" + "<property id=\"" + attr2 + "\" value=\"" + str(val2) + "\" " + "displayName=\"attr2\">" + "<data>thirteen</data>" + "<data>fourteen</data>" + "<data>fifteen and a half</data>" + "</property>" + "<property id=\"" + attr3 + "\" value=\"" + str(val3) + "\" " + "displayName=\"attr3\">" + "<data>True</data>" + "<data>False</data>" + "<data>True</data>" + "</property>" + "<property id=\"" + attr4 + "\" value=\"" + str(val4) + "\" " + "displayName=\"attr4\" />" + "</group></page></wizard></test>") plLogger.LogInfo("input_xml: " + str(input_xml)) root = etree.fromstring(input_xml) assert root is not None key_val_dict, gui_key_val_dict = RunCmd.parse_txml_keys_values(root) assert key_val_dict is not None assert gui_key_val_dict == {} plLogger.LogInfo("key_val_dict: " + str(key_val_dict)) assert len(key_val_dict.keys()) == 4 # Check the key-value pairs (single property) assert attr4 in key_val_dict.keys() assert key_val_dict[attr4] == val4 # Check the key-value pairs (table) for exp_kv_pair in zip([attr1, attr2, attr3], [["13", "14", "15.5"], ["thirteen", "fourteen", "fifteen and a half"], ["True", "False", "True"]]): assert exp_kv_pair[0] in key_val_dict.keys() assert key_val_dict[exp_kv_pair[0]] == exp_kv_pair[1]