Best Python code snippet using green
data_display.py
Source:data_display.py  
1#! /usr/bin/python2# encoding=utf-83# this module is for formatting raw data into html-friendly data4DATA_MODE_BASE = ['base', 'base', 'base', 'base', 'base', 'base']5DATA_MODE_FULL = ['full', 'full', 'full', 'full', 'full', 'full']6DATA_MODE_MASKED = ['masked', 'masked', 'masked', 'masked', 'masked', 'masked']7DATA_MODE_MINIMUM = ['masked', 'partial', 'partial', 'partial', 'full', 'masked']8DATA_MODE_MODERATE = ['partial', 'partial', 'partial', 'partial', 'full', 'masked']9def get_string_display(attr1, attr2, helper1, helper2, attribute_mode):10    """11    get the attribute mode for string12    attribute mode can be:13    'base', 'full', 'partial', 'masked'14    Note that some attribute does not have partial mode, in this case, partial mode will return masked mode15    Remeber to call has_partial_mode function to check if it actually has partial mode!16    Example: 17    Input:18        attr1: '1000151475'19        attr2: '1000151575'20        helper1: '*******4**'21        helper2: '*******5**'22        attribute_mode: 'partial'23    Output:24        ['*******<span style="color:red">4</span>**', '*******<span style="color:red">5</span>**']25    """26    if attribute_mode == 'base':27        attr1_display = attr128        attr2_display = attr229        return [attr1_display, attr2_display]30    elif attribute_mode == 'full':31        if not attr1 or not attr2:32            if not attr1:33                attr1_display = '<img src="../static/images/site/missing.png" alt="missing" class="missing_icon">'34            else:35                attr1_display = attr136            if not attr2:37                attr2_display = '<img src="../static/images/site/missing.png" alt="missing" class="missing_icon">'38            else:39                attr2_display = attr240        else:41            if '*' not in helper1 and '*' not in helper2:42                attr1_display = attr143                attr2_display = attr244            else:45                attr1_display = ''46                attr2_display = ''47                i = 048                j = 049                k = 050                while k < len(helper1):51                    if helper1[k] == '*':52                        attr1_display += attr1[i]53                        attr2_display += attr2[j]54                        k += 155                        i += 156                        j += 157                    elif k+1 < len(helper1) and i+1 < len(attr1) and j+1 < len(attr2) and \58                    helper1[k] not in ['*', '_', '?'] and helper1[k+1] not in ['*', '_', '?'] and attr1[i] == attr2[j+1] and attr1[i+1] == attr2[j]:59                        attr1_display += '<span class="transpose_text">' + attr1[i] + attr1[i+1] + '</span>'60                        attr2_display += '<span class="transpose_text">' + attr2[j] + attr2[j+1] + '</span>'61                        k += 262                        i += 263                        j += 264                    elif helper1[k] == '_' or helper1[k] == '?':65                        attr2_display += '<span class="indel_text">' + attr2[j] + '</span>'66                        k += 167                        j += 168                    elif helper2[k] == '_' or helper2[k] == '?':69                        attr1_display += '<span class="indel_text">' + attr1[i] + '</span>'70                        k += 171                        i += 172                    else:73                        attr1_display += '<span class="replace_text">' + attr1[i] + '</span>'74                        attr2_display += '<span class="replace_text">' + attr2[j] + '</span>'75                        k += 176                        i += 177                        j += 178        return [attr1_display, attr2_display]79    elif attribute_mode == 'partial':80        if not attr1 or not attr2:81            if not attr1:82                attr1_display = '<img src="../static/images/site/missing.png" alt="missing" class="missing_icon">'83            else:84                attr1_display = '*'*len(attr1)85            if not attr2:86                attr2_display = '<img src="../static/images/site/missing.png" alt="missing" class="missing_icon">'87            else:88                attr2_display = '*'*len(attr2)89        else:90            if '*' not in helper1 and '*' not in helper2:91                attr1_display = len(attr1)*'@'92                attr2_display = len(attr2)*'&'93            elif helper1 == helper2:94                attr1_display = '<img src="../static/images/site/checkmark.png" alt="checkmark" class="freq_icon">'95                attr2_display = '<img src="../static/images/site/checkmark.png" alt="checkmark" class="freq_icon">'96            else:97                attr1_display = ''98                attr2_display = ''99                i = 0100                j = 0101                k = 0102                while k < len(helper1):103                    if helper1[k] == '*':104                        attr1_display += '*'105                        attr2_display += '*'106                        k += 1107                        i += 1108                        j += 1109                    elif k+1 < len(helper1) and i+1 < len(attr1) and j+1 < len(attr2) and \110                    helper1[k] not in ['*', '_', '?'] and helper1[k+1] not in ['*', '_', '?'] and attr1[i] == attr2[j+1] and attr1[i+1] == attr2[j]:111                        attr1_display += '<span class="transpose_text">' + attr1[i] + attr1[i+1] + '</span>'112                        attr2_display += '<span class="transpose_text">' + attr2[j] + attr2[j+1] + '</span>'113                        k += 2114                        i += 2115                        j += 2116                    elif helper1[k] == '_' or helper1[k] == '?':117                        attr2_display += '<span class="indel_text">' + attr2[j] + '</span>'118                        k += 1119                        j += 1120                    elif helper2[k] == '_' or helper2[k] == '?':121                        attr1_display += '<span class="indel_text">' + attr1[i] + '</span>'122                        k += 1123                        i += 1124                    else:125                        attr1_display += '<span class="replace_text">' + attr1[i] + '</span>'126                        attr2_display += '<span class="replace_text">' + attr2[j] + '</span>'127                        k += 1128                        i += 1129                        j += 1130        return [attr1_display, attr2_display]131    elif attribute_mode == 'masked':132        if not attr1 or not attr2:133            if not attr1:134                attr1_display = '<img src="../static/images/site/missing.png" alt="missing" class="missing_icon">'135            else:136                attr1_display = '*'*len(attr1)137            if not attr2:138                attr2_display = '<img src="../static/images/site/missing.png" alt="missing" class="missing_icon">'139            else:140                attr2_display = '*'*len(attr2)141        else:142            if '*' not in helper1 and '*' not in helper2:143                attr1_display = len(attr1)*'@'144                attr2_display = len(attr2)*'&'145            elif helper1 == helper2:146                attr1_display = '<img src="../static/images/site/checkmark.png" alt="checkmark" class="freq_icon">'147                attr2_display = '<img src="../static/images/site/checkmark.png" alt="checkmark" class="freq_icon">'148            else:149                attr1_display = ''150                attr2_display = ''151                i = 0152                j = 0153                k = 0154                while k < len(helper1):155                    if helper1[k] == '*':156                        attr1_display += '*'157                        attr2_display += '*'158                        k += 1159                        i += 1160                        j += 1161                    elif k+1 < len(helper1) and i+1 < len(attr1) and j+1 < len(attr2) and \162                    helper1[k] not in ['*', '_', '?'] and helper1[k+1] not in ['*', '_', '?'] and attr1[i] == attr2[j+1] and attr1[i+1] == attr2[j]:163                        attr1_display += '<span class="transpose_text">' + '@&' + '</span>'164                        attr2_display += '<span class="transpose_text">' + '&@' + '</span>'165                        k += 2166                        i += 2167                        j += 2168                    elif helper1[k] == '_' or helper1[k] == '?':169                        attr2_display += '<span class="indel_text">' + '&' + '</span>'170                        k += 1171                        j += 1172                    elif helper2[k] == '_' or helper2[k] == '?':173                        attr1_display += '<span class="indel_text">' + '@' + '</span>'174                        k += 1175                        i += 1176                    else:177                        attr1_display += '<span class="replace_text">' + '@' + '</span>'178                        attr2_display += '<span class="replace_text">' + '&' + '</span>'179                        k += 1180                        i += 1181                        j += 1182        return [attr1_display, attr2_display]183def get_date_display(attr1, attr2, helper1, helper2, attribute_mode):184    """185    get the attribute mode for date186    attribute mode can be:187    'base', 'full', 'partial', 'masked'188    Note that some attribute does not have partial mode, in this case, partial mode will return masked mode189    Remeber to call has_partial_mode function to check if it actually has partial mode!190    Example: 191    Input:192        attr1 = '12/28/1950'193        attr2 = '12/28/1905'194        helper1 = '**/**/**50'195        helper2 = '**/**/**05'196        attribute_mode: 'partial'197    Output:198        ['**/**/**<span style="color:blue">50</span>', '**/**/**<span style="color:blue">05</span>']199    """200    if attribute_mode == 'base':201        attr1_display = attr1202        attr2_display = attr2203        return [attr1_display, attr2_display]204    elif attribute_mode == 'full':205        if not attr1 or not attr2:206            if not attr1:207                attr1_display = '<img src="../static/images/site/missing.png" alt="missing" class="missing_icon">'208            else:209                attr1_display = attr1210            if not attr2:211                attr2_display = '<img src="../static/images/site/missing.png" alt="missing" class="missing_icon">'212            else:213                attr2_display = attr2214        else:215            if '*' not in helper1 and '*' not in helper2:216                attr1_display = attr1217                attr2_display = attr2218            elif helper1 == helper2:219                attr1_display = attr1220                attr2_display = attr2221            else:222                attr1_display = ''223                attr2_display = ''224                M1 = helper1[0:2]225                M2 = helper2[0:2]226                D1 = helper1[3:5]227                D2 = helper2[3:5]228                Y1 = helper1[6:]229                Y2 = helper2[6:]230                k = 0231                if M1 != '**' and D1 != '**' and M1 == D2 and M2 == D1:232                    attr1_display += attr1[0:6]233                    attr2_display += attr2[0:6]234                    k = 6235                while k < 10:236                    if helper1[k] == '/':237                        attr1_display += '/'238                        attr2_display += '/'239                        k += 1240                    elif k+1 < 10 and helper1[k] != '*' and helper1[k+1] != '*' and helper1[k] == helper2[k+1] and helper1[k+1] == helper2[k]:241                        attr1_display += '<span class="transpose_text">' + helper1[k:k+2] + '</span>'242                        attr2_display += '<span class="transpose_text">' + helper2[k:k+2] + '</span>'243                        k += 2244                    elif helper1[k] != '*':245                        attr1_display += '<span class="replace_text">' + attr1[k] + '</span>'246                        attr2_display += '<span class="replace_text">' + attr2[k] + '</span>'247                        k += 1248                    else:249                        attr1_display += attr1[k]250                        attr2_display += attr2[k]251                        k += 1252        return [attr1_display, attr2_display]253    elif attribute_mode == 'partial':254        if not attr1 or not attr2:255            if not attr1:256                attr1_display = '<img src="../static/images/site/missing.png" alt="missing" class="missing_icon">'257            else:258                attr1_display = '**/**/****'259            if not attr2:260                attr2_display = '<img src="../static/images/site/missing.png" alt="missing" class="missing_icon">'261            else:262                attr2_display = '**/**/****'263        else:264            if '*' not in helper1 and '*' not in helper2:265                attr1_display = '@@/@@/@@@@'266                attr2_display = '&&/&&/&&&&'267            elif helper1 == helper2:268                attr1_display = '<img src="../static/images/site/checkmark.png" alt="checkmark" class="freq_icon">'269                attr2_display = '<img src="../static/images/site/checkmark.png" alt="checkmark" class="freq_icon">'270            else:271                attr1_display = ''272                attr2_display = ''273                M1 = helper1[0:2]274                M2 = helper2[0:2]275                D1 = helper1[3:5]276                D2 = helper2[3:5]277                Y1 = helper1[6:]278                Y2 = helper2[6:]279                k = 0280                if M1 != '**' and D1 != '**' and M1 == D2 and M2 == D1:281                    attr1_display += attr1[0:6]282                    attr2_display += attr2[0:6]283                    k = 6284                while k < 10:285                    if helper1[k] == '/':286                        attr1_display += '/'287                        attr2_display += '/'288                        k += 1289                    elif k+1 < 10 and helper1[k] != '*' and helper1[k+1] != '*' and helper1[k] == helper2[k+1] and helper1[k+1] == helper2[k]:290                        attr1_display += '<span class="transpose_text">' + helper1[k:k+2] + '</span>'291                        attr2_display += '<span class="transpose_text">' + helper2[k:k+2] + '</span>'292                        k += 2293                    elif helper1[k] != '*':294                        attr1_display += '<span class="replace_text">' + attr1[k] + '</span>'295                        attr2_display += '<span class="replace_text">' + attr2[k] + '</span>'296                        k += 1297                    else:298                        attr1_display += '*'299                        attr2_display += '*'300                        k += 1301        return [attr1_display, attr2_display]302    elif attribute_mode == 'masked':303        if not attr1 or not attr2:304            if not attr1:305                attr1_display = '<img src="../static/images/site/missing.png" alt="missing" class="missing_icon">'306            else:307                attr1_display = '**/**/****'308            if not attr2:309                attr2_display = '<img src="../static/images/site/missing.png" alt="missing" class="missing_icon">'310            else:311                attr2_display = '**/**/****'312        else:313            if '*' not in helper1 and '*' not in helper2:314                attr1_display = '@@/@@/@@@@'315                attr2_display = '&&/&&/&&&&'316            elif helper1 == helper2:317                attr1_display = '<img src="../static/images/site/checkmark.png" alt="checkmark" class="freq_icon">'318                attr2_display = '<img src="../static/images/site/checkmark.png" alt="checkmark" class="freq_icon">'319            else:320                attr1_display = ''321                attr2_display = ''322                M1 = helper1[0:2]323                M2 = helper2[0:2]324                D1 = helper1[3:5]325                D2 = helper2[3:5]326                Y1 = helper1[6:]327                Y2 = helper2[6:]328                k = 0329                if M1 != '**' and D1 != '**' and M1 == D2 and M2 == D1:330                    attr1_display += '@@/&&/'331                    attr2_display += '&&/@@/'332                    k = 6333                while k < 10:334                    if helper1[k] == '/':335                        attr1_display += '/'336                        attr2_display += '/'337                        k += 1338                    elif k+1 < 10 and helper1[k] != '*' and helper1[k+1] != '*' and helper1[k] == helper2[k+1] and helper1[k+1] == helper2[k]:339                        attr1_display += '<span class="transpose_text">' + '@&' + '</span>'340                        attr2_display += '<span class="transpose_text">' + '&@' + '</span>'341                        k += 2342                    elif helper1[k] != '*':343                        attr1_display += '<span class="replace_text">' + '@' + '</span>'344                        attr2_display += '<span class="replace_text">' + '&' + '</span>'345                        k += 1346                    else:347                        attr1_display += '*'348                        attr2_display += '*'349                        k += 1350        return [attr1_display, attr2_display]351def get_character_display(attr1, attr2,  helper1, helper2, attribute_mode):352    """353    """354    if attribute_mode == 'base' or attribute_mode == 'full':355        if not attr1:356            attr1 = '<img src="../static/images/site/missing.png" alt="missing" class="missing_icon">'357        if not attr2:358            attr2 = '<img src="../static/images/site/missing.png" alt="missing" class="missing_icon">'359        return [attr1, attr2]360    else:361        if not attr1 or not attr2:362            if not attr1:363                attr1_display = '<img src="../static/images/site/missing.png" alt="missing" class="missing_icon">'364            else:365                attr1_display = '*'366            if not attr2:367                attr2_display = '<img src="../static/images/site/missing.png" alt="missing" class="missing_icon">'368            else:369                attr2_display = '*'370        elif attr1 == attr2:371            attr1_display = '<img src="../static/images/site/checkmark.png" alt="checkmark" class="freq_icon">'372            attr2_display = '<img src="../static/images/site/checkmark.png" alt="checkmark" class="freq_icon">'373        else:374            attr1_display = '@'375            attr2_display = '&'376        return [attr1_display, attr2_display]377def get_name_freq(freq, mode):378    if mode == 'base':379        return ''380    freq = int(freq)381    if freq == 1:382        return '<img src="../static/images/site/unique.png" alt="unique" class="freq_icon">'383    elif freq <= 5:384        return '<img src="../static/images/site/rare.png" alt="rare" class="freq_icon">'385    elif freq <= 100:386        return '<img src="../static/images/site/common.png" alt="common" class="freq_icon">'387    else:388        return '<img src="../static/images/site/infinity.png" alt="infinity" class="freq_icon">'389def get_ffreq(freq, mode='full'):390    return get_name_freq(freq, mode)391def get_lfreq(freq, mode='full'):392    return get_name_freq(freq, mode)393def format_pair(p1, p2, data_mode):394    result1 = list()395    result2 = list()396    if data_mode == 'base':397        mode = DATA_MODE_BASE398    elif data_mode == 'full':399        mode = DATA_MODE_FULL400    elif data_mode == 'masked':401        mode = DATA_MODE_MASKED402    elif data_mode == 'minimum':403        mode = DATA_MODE_MINIMUM404    elif data_mode == 'moderate':405        mode = DATA_MODE_MODERATE406    # pair id407    result1.append(p1[0])408    result2.append(p2[0])409    # record attribute ID410    id_format = get_string_display(p1[1], p2[1], p1[9], p2[9], mode[0])411    result1.append(id_format[0])412    result2.append(id_format[1])413    # first name frequency414    freq_mode = 'full'415    if data_mode == 'base':416        freq_mode = 'base'417    result1.append(get_ffreq(p1[2], mode=freq_mode))418    result2.append(get_ffreq(p2[2], mode=freq_mode))419    # first name420    first_name_format = get_string_display(p1[3], p2[3], p1[10], p2[10], mode[1])421    result1.append(first_name_format[0])422    result2.append(first_name_format[1])423    # last name424    last_name_format = get_string_display(p1[4], p2[4], p1[11], p2[11], mode[2])425    result1.append(last_name_format[0])426    result2.append(last_name_format[1])427    # special case: first name and last name swap428    if mode[1] in ['partial', 'masked'] and mode[2] in ['partial', 'masked']:429        if p1[3] != p2[3] and p1[4] != p2[4] and p1[3] == p2[4] and p1[4] == p2[3]:430            result1[3] = '@'*len(p1[3])431            result2[3] = '&'*len(p2[3])432            result1[4] = '&'*len(p1[4])433            result2[4] = '@'*len(p2[4])434    # last name frequency435    result1.append(get_lfreq(p1[5], mode=freq_mode))436    result2.append(get_lfreq(p2[5], mode=freq_mode))437    # DoB438    DoB_format = get_date_display(p1[6], p2[6], p1[12], p2[12], mode[3])439    result1.append(DoB_format[0])440    result2.append(DoB_format[1])441    # gender442    gender_format = get_character_display(attr1=p1[7], attr2=p2[7], helper1='', helper2='', attribute_mode=mode[4])443    result1.append(gender_format[0])444    result2.append(gender_format[1])445    # race446    race_format = get_character_display(attr1=p1[8], attr2=p2[8], helper1='', helper2='', attribute_mode=mode[5])447    result1.append(race_format[0])448    result2.append(race_format[1])449    450    return [result1, result2]451def format_data(data, data_mode):452    """453    INPUT: 454        data - raw data455        data_mode - 'base', 'full', 'masked', 'minimum', 'moderate'456    OUTPUT: data for display457    Example:458    input: 459    data = [460        ['1','','206','NELSON','MITCHELL','1459','03/13/1975','M','B','','******','********___','03/13/1975','*','*','34','6','0'],461        ['1','1000142704,174','NELSON','MITCHELL SR','1314','07/03/1949','M','B','1000142704','******','******** SR','07/03/1949','*','*','34','6','0']462    ]463    data_mode = full464    output: [465        ['1', '<img src="../static/images/site/missing.png" alt="missing" class="missing_icon">', '<img src="../static/images/site/infinity.png" alt="infinity" class="freq_icon">', 'NELSON', 'MITCHELL', '<img src="../static/images/site/infinity.png" alt="infinity" class="freq_icon">', '03/13/1975','M','B'],466        ['1', '1000142704', '<img src="../static/images/site/infinity.png" alt="infinity" class="freq_icon">', 'NELSON', 'MITCHELL <span style="color:green">SR</span>', '<img src="../static/images/site/infinity.png" alt="infinity" class="freq_icon">', '07/03/1949','M','B']467    ]468    """469    ret = list()470    for i in range(0, len(data), 2):471        result = format_pair(data[i], data[i+1], data_mode)472        ret += result473    return ret474def get_icon_string(s1, s2, helper1, helper2):475    if not s1 or not s2:476        return ''477    else:478        if s1 == s2:479            return ''480        else:481            if '*' not in helper1 and '*' not in helper2:482                return '<embed class="diff_icon" src="../static/images/site/diff.svg" type="image/svg+xml" />'483            else:484                ret = ''485                i = 0486                j = 0487                k = 0488                while k < len(helper1):489                    if helper1[k] == '*':490                        ret += '<span class="hidden_element">*</span>'491                        k += 1492                        i += 1493                        j += 1494                    elif k+1 < len(helper1) and i+1 < len(s1) and j+1 < len(s2) and helper1[k] not in ['*', '_', '?'] and helper1[k+1] not in ['*', '_', '?'] and s1[i] == s2[j+1] and s1[i+1] == s2[j]:495                        ret += '<img class="transpose_icon" src="../static/images/site/transpose.png" alt="transpose">'496                        k += 2497                        i += 2498                        j += 2499                    elif helper1[k] == '_' or helper1[k] == '?':500                        ret += '<img class="indel_icon" src="../static/images/site/indel.png" alt="indel">'501                        k += 1502                        j += 1503                    elif helper2[k] == '_' or helper2[k] == '?':504                        ret += '<img class="indel_icon" src="../static/images/site/indel.png" alt="indel">'505                        k += 1506                        i += 1507                    else:508                        ret += '<img class="replace_icon" src="../static/images/site/replace.png" alt="replace">'509                        k += 1510                        i += 1511                        j += 1512                return ret513def get_icon_nameswap(n11, n12, n21, n22):514    if n11 != n21 and n12 != n22 and n11 == n22 and n21 == n12:515        return '<embed class="name_swap_icon" src="../static/images/site/name_swap.svg" type="image/svg+xml" />'516    else:517        return ''518def get_icon_date(d1, d2, helper1, helper2):519    if not d1 or not d2:520        return ''521    else:522        if d1 == d2:523            return ''524        else:525            if '*' not in helper1 and '*' not in helper2:526                return '<embed class="diff_icon" src="../static/images/site/diff.svg" type="image/svg+xml" />'527            else:528                ret = ''529                M1 = helper1[0:2]530                M2 = helper2[0:2]531                D1 = helper1[3:5]532                D2 = helper2[3:5]533                Y1 = helper1[6:]534                Y2 = helper2[6:]535                k = 0536                if M1 != '**' and D1 != '**' and M1 == D2 and M2 == D1:537                    ret += '<embed class="swap_date_icon" src="../static/images/site/swap_date.svg" type="image/svg+xml" />'538                    k = 6539                while k < 10:540                    if helper1[k] == '/':541                        ret += '<span class="hidden_element">/</span>'542                        k += 1543                    elif k+1 < 10 and helper1[k] != '*' and helper1[k+1] != '*' and helper1[k] == helper2[k+1] and helper1[k+1] == helper2[k]:544                        ret += '<img class="transpose_icon" src="../static/images/site/transpose.png" alt="transpose">'545                        k += 2546                    elif helper1[k] != '*':547                        ret += '<img class="replace_icon" src="../static/images/site/replace.png" alt="replace">'548                        k += 1549                    else:550                        ret += '<span class="hidden_element">*</span>'551                        k += 1552                return ret553def get_icon_character(c1, c2):554    if c1 and c2 and c1 != c2:555        return '<embed class="diff_icon" src="../static/images/site/diff.svg" type="image/svg+xml" />'556    else:557        return ''558def get_icon_for_pair(p1, p2):559    icon = list()560    # icon for ID561    icon.append(get_icon_string(p1[1], p2[1], p1[9], p2[9]))562    # icon for firstname563    icon.append(get_icon_string(p1[3], p2[3], p1[10], p2[10]))564    # icon for name swap565    icon.append(get_icon_nameswap(p1[3], p1[4], p2[3], p2[4]))566    # icon for lastname567    icon.append(get_icon_string(p1[4], p2[4], p1[11], p2[11]))568    # icon for DoB569    icon.append(get_icon_date(p1[6], p2[6], p1[12], p2[12]))570    # icon for sex571    icon.append(get_icon_character(p1[7], p2[7]))572    # icon for race573    icon.append(get_icon_character(p1[8], p2[8]))574    if icon[2] != '':575        icon[1] = ''576        icon[3] = ''577    return icon578def generate_icon(data):579    """580    INPUT: 581        data - raw data582    OUTPUT: 583        icon - the markup icons : [id, firstname, name_swap, lastname, DoB, gender, race]584    Example:585    input: 586    data = [587        ['1','','206','NELSON','MITCHELL','1459','03/13/1975','M','B','','******','********___','03/13/1975','*','*','34','6','0'],588        ['1','1000142704,174','NELSON','MITCHELL SR','1314','07/03/1949','M','B','1000142704','******','******** SR','07/03/1949','*','*','34','6','0']589    ]590    output: [591        ['', '', '<span class="hidden_element">MITCHELL</span><img class="indel_icon" src="../static/images/site/indel.png" alt="indel"><img class="indel_icon" src="../static/images/site/indel.png" alt="indel"><img class="indel_icon" src="../static/images/site/indel.png" alt="indel">', '<embed class="diff_icon" src="../static/images/site/diff.svg" type="image/svg+xml" />', '', '']592    ]593    """594    ret = list()595    for i in range(0, len(data), 2):596        result = get_icon_for_pair(data[i], data[i+1])597        ret.append(result)598    return ret599if __name__ == '__main__':600    attr1 = 'AUSTIN'601    attr2 = 'AUTWELL'602    helper1 = attr1603    helper2 = attr2604    res = get_string_display(attr1, attr2, helper1, helper2, 'full')605    print res606    res = get_string_display(attr1, attr2, helper1, helper2, 'partial')607    print res608    res = get_string_display(attr1, attr2, helper1, helper2, 'masked')609    print res610    attr1 = '1022119365'611    attr2 = '1022119365'612    helper1 = '**********'613    helper2 = '**********'614    res = get_string_display(attr1, attr2, helper1, helper2, 'full')615    print res616    res = get_string_display(attr1, attr2, helper1, helper2, 'partial')617    print res618    res = get_string_display(attr1, attr2, helper1, helper2, 'masked')619    print res620    attr1 = '1000151475'621    attr2 = '1000151575'622    helper1 = '*******4**'623    helper2 = '*******5**'624    res = get_string_display(attr1, attr2, helper1, helper2, 'full')625    print res626    res = get_string_display(attr1, attr2, helper1, helper2, 'partial')627    print res628    res = get_string_display(attr1, attr2, helper1, helper2, 'masked')629    print res630    attr1 = 'SHIESHA'631    attr2 = 'SHAMEESHA'632    helper1 = '**I__****'633    helper2 = '**AME****'634    res = get_string_display(attr1, attr2, helper1, helper2, 'full')635    print res636    res = get_string_display(attr1, attr2, helper1, helper2, 'partial')637    print res638    res = get_string_display(attr1, attr2, helper1, helper2, 'masked')639    print res640    attr1 = '1530042971'641    attr2 = '1350082931'642    helper1 = '*53**4**7*'643    helper2 = '*35**8**3*'644    res = get_string_display(attr1, attr2, helper1, helper2, 'full')645    print res646    res = get_string_display(attr1, attr2, helper1, helper2, 'partial')647    print res648    res = get_string_display(attr1, attr2, helper1, helper2, 'masked')649    print res650    attr1 = '12/27/1944'651    attr2 = '12/27/1904'652    helper1 = '**/**/**4*'653    helper2 = '**/**/**0*'654    res = get_date_display(attr1, attr2, helper1, helper2, 'full')655    print res656    res = get_date_display(attr1, attr2, helper1, helper2, 'partial')657    print res658    res = get_date_display(attr1, attr2, helper1, helper2, 'masked')659    print res660    attr1 = '12/28/1950'661    attr2 = '12/28/1905'662    helper1 = '**/**/**50'663    helper2 = '**/**/**05'664    res = get_date_display(attr1, attr2, helper1, helper2, 'full')665    print res666    res = get_date_display(attr1, attr2, helper1, helper2, 'partial')667    print res668    res = get_date_display(attr1, attr2, helper1, helper2, 'masked')669    print res670    attr1 = '01/09/1960'671    attr2 = '09/01/1960'672    helper1 = '01/09/****'673    helper2 = '09/01/****'674    res = get_date_display(attr1, attr2, helper1, helper2, 'full')675    print res676    res = get_date_display(attr1, attr2, helper1, helper2, 'partial')677    print res678    res = get_date_display(attr1, attr2, helper1, helper2, 'masked')679    print res680    attr1 = '01/09/1935'681    attr2 = '01/09/1935'682    helper1 = '**/**/****'683    helper2 = '**/**/****'684    res = get_date_display(attr1, attr2, helper1, helper2, 'full')685    print res686    res = get_date_display(attr1, attr2, helper1, helper2, 'partial')687    print res688    res = get_date_display(attr1, attr2, helper1, helper2, 'masked')689    print res690    attr1 = '10/01/1990'691    attr2 = '09/19/1995'692    helper1 = '10/01/1990'693    helper2 = '09/19/1995'694    res = get_date_display(attr1, attr2, helper1, helper2, 'full')695    print res696    res = get_date_display(attr1, attr2, helper1, helper2, 'partial')697    print res698    res = get_date_display(attr1, attr2, helper1, helper2, 'masked')699    print res700    pairs = list()701    pairs.append(['1','1002415935','303','DARIUS','FLOWE','163','05/11/1994','M','B','*********5','***IUS','*****','**/**/****','*','*','8','2','0'])702    pairs.append(['1','1002415936','270','DARREN','FLOWE','184','05/11/1994','M','B','*********6','***REN','*****','**/**/****','*','*','8','2','0'])703    pairs.append(['2','1000255792','10','SOL','BADAME','1','07/16/1914','M','W','1000255792','SOL','BADAME','**/**/****','*','*','33','6','1'])704    pairs.append(['2','','1','BADAME','SOL','1','07/16/1914','M','W','','BADAME','SOL','**/**/****','*','*','33','6','1'])705    data = format_data(pairs, 'base')706    print data707    data = format_data(pairs, 'full')708    print data...test_cprofile.py
Source:test_cprofile.py  
1"""Test suite for the cProfile module."""2import sys3from test.support import run_unittest, TESTFN, unlink4# rip off all interesting stuff from test_profile5import cProfile6from test.test_profile import ProfileTest, regenerate_expected_output7from test.profilee import testfunc8class CProfileTest(ProfileTest):9    profilerclass = cProfile.Profile10    profilermodule = cProfile11    expected_max_output = "{built-in method builtins.max}"12    def get_expected_output(self):13        return _ProfileOutput14    # Issue 3895.15    def test_bad_counter_during_dealloc(self):16        import _lsprof17        # Must use a file as StringIO doesn't trigger the bug.18        orig_stderr = sys.stderr19        try:20            with open(TESTFN, 'w') as file:21                sys.stderr = file22                try:23                    obj = _lsprof.Profiler(lambda: int)24                    obj.enable()25                    obj = _lsprof.Profiler(1)26                    obj.disable()27                    obj.clear()28                finally:29                    sys.stderr = orig_stderr30        finally:31            unlink(TESTFN)32def test_main():33    run_unittest(CProfileTest)34def main():35    if '-r' not in sys.argv:36        test_main()37    else:38        regenerate_expected_output(__file__, CProfileTest)39# Don't remove this comment. Everything below it is auto-generated.40#--cut--------------------------------------------------------------------------41_ProfileOutput = {}42_ProfileOutput['print_stats'] = """\43       28    0.028    0.001    0.028    0.001 profilee.py:110(__getattr__)44        1    0.270    0.270    1.000    1.000 profilee.py:25(testfunc)45     23/3    0.150    0.007    0.170    0.057 profilee.py:35(factorial)46       20    0.020    0.001    0.020    0.001 profilee.py:48(mul)47        2    0.040    0.020    0.600    0.300 profilee.py:55(helper)48        4    0.116    0.029    0.120    0.030 profilee.py:73(helper1)49        2    0.000    0.000    0.140    0.070 profilee.py:84(helper2_indirect)50        8    0.312    0.039    0.400    0.050 profilee.py:88(helper2)51        8    0.064    0.008    0.080    0.010 profilee.py:98(subhelper)"""52_ProfileOutput['print_callers'] = """\53profilee.py:110(__getattr__)                      <-      16    0.016    0.016  profilee.py:98(subhelper)54profilee.py:25(testfunc)                          <-       1    0.270    1.000  <string>:1(<module>)55profilee.py:35(factorial)                         <-       1    0.014    0.130  profilee.py:25(testfunc)56                                                        20/3    0.130    0.147  profilee.py:35(factorial)57                                                           2    0.006    0.040  profilee.py:84(helper2_indirect)58profilee.py:48(mul)                               <-      20    0.020    0.020  profilee.py:35(factorial)59profilee.py:55(helper)                            <-       2    0.040    0.600  profilee.py:25(testfunc)60profilee.py:73(helper1)                           <-       4    0.116    0.120  profilee.py:55(helper)61profilee.py:84(helper2_indirect)                  <-       2    0.000    0.140  profilee.py:55(helper)62profilee.py:88(helper2)                           <-       6    0.234    0.300  profilee.py:55(helper)63                                                           2    0.078    0.100  profilee.py:84(helper2_indirect)64profilee.py:98(subhelper)                         <-       8    0.064    0.080  profilee.py:88(helper2)65{built-in method builtins.hasattr}                <-       4    0.000    0.004  profilee.py:73(helper1)66                                                           8    0.000    0.008  profilee.py:88(helper2)67{built-in method sys.exc_info}                    <-       4    0.000    0.000  profilee.py:73(helper1)68{method 'append' of 'list' objects}               <-       4    0.000    0.000  profilee.py:73(helper1)"""69_ProfileOutput['print_callees'] = """\70<string>:1(<module>)                              ->       1    0.270    1.000  profilee.py:25(testfunc)71profilee.py:110(__getattr__)                      ->72profilee.py:25(testfunc)                          ->       1    0.014    0.130  profilee.py:35(factorial)73                                                           2    0.040    0.600  profilee.py:55(helper)74profilee.py:35(factorial)                         ->    20/3    0.130    0.147  profilee.py:35(factorial)75                                                          20    0.020    0.020  profilee.py:48(mul)76profilee.py:48(mul)                               ->77profilee.py:55(helper)                            ->       4    0.116    0.120  profilee.py:73(helper1)78                                                           2    0.000    0.140  profilee.py:84(helper2_indirect)79                                                           6    0.234    0.300  profilee.py:88(helper2)80profilee.py:73(helper1)                           ->       4    0.000    0.004  {built-in method builtins.hasattr}81profilee.py:84(helper2_indirect)                  ->       2    0.006    0.040  profilee.py:35(factorial)82                                                           2    0.078    0.100  profilee.py:88(helper2)83profilee.py:88(helper2)                           ->       8    0.064    0.080  profilee.py:98(subhelper)84profilee.py:98(subhelper)                         ->      16    0.016    0.016  profilee.py:110(__getattr__)85{built-in method builtins.hasattr}                ->      12    0.012    0.012  profilee.py:110(__getattr__)"""86if __name__ == "__main__":...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
