Best Python code snippet using hypothesis
plane_seating.py
Source:plane_seating.py  
...124    return remaining_seats125# This function assigns all seats to regular economy passengers after economy plus passengers have been seated126# This function will also utilize swapping and reseating functions below to assure that all blocks of127# regular economy passengers are seated together128def assign_rows(plane, remaining_seats, economy_sold):129    avail_seats_in_row = list(remaining_seats.values())130    num_purchased_seats = list(economy_sold.values())131    num_purchased_seats.sort()132    num_purchased_seats.reverse()133    total_avail = sum(avail_seats_in_row)134    total_needed = sum(num_purchased_seats)135    rc = 0 # remaining_seats counter136    remaining_seats_row = list(remaining_seats.keys())137    sold_seat_name = list(economy_sold.keys())138    sold_seat_name.sort()139    sold_seat_name.reverse()140    while total_needed > 0:141        if avail_seats_in_row[rc] >= num_purchased_seats[0]:142            row = int(remaining_seats_row[rc])143            start = find_first_empty_seat_in_row(plane[row], num_purchased_seats[0])144            for i in range(num_purchased_seats[0]):145                if plane[row][i + start] == "avail" or plane[row][i + start] == "win":146                    plane[row][i + start] = sold_seat_name[0]147            total_avail -= num_purchased_seats[0]148            total_needed -= num_purchased_seats[0]149            avail_seats_in_row[rc] -= num_purchased_seats[0]150            sold_seat_name.pop(0)151            num_purchased_seats.pop(0)152            rc = 0153        elif avail_seats_in_row[rc] < num_purchased_seats[0] and rc == len(plane) - 1:154            eWRows = locate_avail_win_seat(plane)155            eNRows = locate_avail_non_win_seat(plane)156            if len(eWRows) == 0 and len(eNRows) > 0:157                plane = make_avail_block(plane, eNRows, num_purchased_seats[0])158            elif len(eWRows) > 0 and len(eNRows) == 0:159                plane = make_avail_block_win(plane, eWRows, num_purchased_seats[0])160            else:161                plane = win_seat_swap(plane, eWRows, eNRows)162            remaining_seats = find_empty_seats(plane)163            avail_seats_in_row = list(remaining_seats.values())164            remaining_seats_row = list(remaining_seats.keys())165            rc = 0166        else:167            if rc < len(plane) - 1:168                rc += 1169            else:170                rc = 0171# creates a list of all rows with an available window seat172# used in assign_rows function173def locate_avail_win_seat(plane):174    row_with_empty_win_seat = []175    count_row = 0176    for row in plane:177        for i in range(len(row) -1, -1, -1):178            if row[i] == "win":179                row_with_empty_win_seat.append(count_row)180        count_row += 1181    return row_with_empty_win_seat182# creates a list of all rows with an available non-window seat183# used in assign_rows function184def locate_avail_non_win_seat(plane):185    row_with_empty_non_win_seat = []186    count_row = 0187    for row in plane:188        for i in range(len(row) -1, -1, -1):189            if row[i] == "avail":190                row_with_empty_non_win_seat.append(count_row)191        count_row += 1192    return row_with_empty_non_win_seat193#swaps economy plus passenger in window seat to a different window seat194# to make two or more open seats together195def win_seat_swap(plane, empty_win_rows, empty_non_win_rows):196    eWRow = empty_win_rows[0]197    eNRow = empty_non_win_rows[0]198    plane[eWRow][len(plane[eWRow]) -1] = plane[eNRow][len(plane[eNRow]) -1]199    plane[eNRow][len(plane[eNRow]) -1] = "win"200    return plane201# swaps economy plus passenger in non-window seat to a different non-window seat202# to make two or more open seats together203def make_avail_block(plane, empty_nw_row, num_seats):204    full_row = find_full_row(plane)205    for i in range(num_seats):206        avail_seat = plane[empty_nw_row[i]].index("avail")207        plane[empty_nw_row[i]][avail_seat] = plane[full_row][i + 1]208        plane[full_row][i + 1] = "avail"209    return plane210# swaps economy plus passenger in non-window seat to a different window seat211# to make two or more open seats together212def make_avail_block_win(plane, empty_w_row, num_seats):213    full_row = find_full_row(plane)214    for i in range(num_seats):215        avail_seat = plane[empty_w_row[i]].index("win")216        plane[empty_w_row[i]][avail_seat] = plane[full_row][i + 1]217        plane[full_row][i + 1] = "avail"218    return plane219# used in make_avail_block & make_avail_block_win functions220def find_full_row(plane):221    for row in plane:222        for seat in row:223            if not(seat.startswith("e")):224                break225            else:226                return plane.index(row)227#used to locate seat in row to place block of passengers in228# checks to see there are enough seats together to accommodate number of passengers in block229def find_first_empty_seat_in_row(row, num_seats):230    if num_seats == 1:231        for i in range(len(row)):232            if row[i] == "avail" or row[i] == "win":233                    return i234    elif num_seats == 2:235        for i in range(len(row)):236            if row[i] == "avail" or row[i] == "win":237                if row[i + 1] == "avail" or row[i + 1] == "win":238                    return i239    else:240        for i in range(len(row)):241            if row[i] == "avail" or row[i] == "win":242                if row[i + 1] == "avail" or row[i + 1] == "win":243                    if row[i + (num_seats - 1)] == "avail" or row[i + (num_seats - 1)] == "win":244                        return i245def purchase_economy_block(plane,economy_sold,number,name):246    """247    Purchase regular economy seats. As long as there are sufficient seats248    available, store the name and number of seats purchased in the249    economy_sold dictionary and return the new dictionary250    """251    seats_avail = get_total_seats(plane)252    seats_avail = seats_avail - get_number_economy_sold(economy_sold)253    if seats_avail >= number: # if there are more seats available than the number requested254        economy_sold[name]=number255    return economy_sold256def fill_plane(plane):257    """258    Params: plane - a list of lists representing a plane259    comments interspersed in the code260    """261    economy_sold={}262    total_seats = get_total_seats(plane)263    # these are for naming the pasengers and families by264    # appending a number to either "ep" for economy plus or "u" for unassigned economy seat265    ep_number=1266    u_number=1267    # MODIFY THIS268    # you will probably want to change parts of this269    # for example, when to stop purchases, the probabilities, maybe the size for the random270    # regular economy size271    max_family_size = 3272    while total_seats > 1:273        r = random.randrange(100)274        if r > 30: # Someone wants to buy window seat275            plane = purchase_economy_plus(plane,economy_sold,"ep-%d"%ep_number)276            ep_number = ep_number + 1277            total_seats = get_avail_seats(plane,economy_sold) # reset total_seats to remaining available seats278        else:279            current_block_size = 1+random.randrange(max_family_size)280            if total_seats >= current_block_size: # makes sure flight cannot be oversold281                economy_sold = purchase_economy_block(plane,economy_sold,current_block_size,"u-%d"%u_number)282                u_number = u_number + 1283                total_seats = get_avail_seats(plane,economy_sold)284            else:285                pass286    empty_rows = find_empty_seats(plane)287    assign_rows(plane, empty_rows, economy_sold)288    return plane289def main():290    plane = create_plane(10,5)291    # print(get_plane_string(plane))292    plane = fill_plane(plane)293    print(get_plane_string(plane))294if __name__=="__main__":...__main__.py
Source:__main__.py  
...5from airtable_matcher import TableMatcher6from asana_taskmaster import Taskmaster7from util.date import *8# TODO: Consider moving the notes field to match structure in Profile9def assign_rows(taskmaster, table_rows, note_fields):10    """11    Assigns rows in :param table_rows to the Asana workspace known by :param12    taskmaster13    :param taskmaster: Taskmaster object14    :param table_rows: All matches filtered through TableMatcher.prepMatches()15    :param note_fields: Note fields from profile the user wants included in16    the match sent to the Asana API17    :return: void.18    """19    if table_rows == -1:20        print('No new tasks to add to Asana')21    else:22        for row in table_rows:23            notes = assign_rows_helper(note_fields, row)24            taskmaster.add_task(row['title'], notes)25            print('Task named "{}" added to workspace'.format(row['title']))26    print('Done')27def assign_rows_helper(note_fields, table_row):28    """29    Builds and returns a String of notes from the fields specified in :param30    note_fields and populated with the data for those fields in :param31    table_row32    :param note_fields: Note fields from profile the user wants included in33    the match sent to the Asana API34    :param table_row:35    :return: String. A formatted string containing the notes listed in :param36    note_fields.37    """38    notes = ''39    for note_field in note_fields:40        notes += '{}: {}\n\n'.format(note_field.capitalize(),41                                     table_row[note_field])42    return notes43def initialize_objects(profile, file):44    """45    Instantiates objects needed for the program with profile data46    :param profile: profile to pull data from/send to47    :param file: file path of the profile48    :return: TableMatcher instance, Taskmaster instance49    """50    if profile['name'] == 'TEST PROFILE':  # ensures proper imports in terminal51        file = (Path(__file__).parent / "./profile_example.json").resolve()52    airtable = Airtable(profile['airtable']['base'],53                        profile['airtable']['table'],54                        api_key=profile['airtable']['api'])55    matcher = TableMatcher(airtable, profile,56                           get_latest_datetime(profile['name'], file))57    taskmaster = Taskmaster(profile)58    set_latest_datetime(matcher, profile['name'], file)59    return matcher, taskmaster60if __name__ == '__main__':61    print("""  62        **************************************63        *************   Airsana   ************64        **************************************65        Enter 'q' to quit at any time66        """)67    fpath = (Path(__file__).parent / "./profiles.json").resolve()68    prof = main_loop(fpath)69    if prof is not None:70        nf_list = prof['asana']['note_fields']71        m, t = initialize_objects(prof, fpath)72        prepped_matches = m.prep_matches()73        if m is not None:74            assign_rows(t, prepped_matches, nf_list)75    print("""76        *****************************77        ********** Goodbye **********78        *****************************...politics_g20_drinkingage.py
Source:politics_g20_drinkingage.py  
...3FONT = calibri4BARBG = "#AAAAAA80"5atlas = pd.read_csv("datasets/countries.csv").split_columns('country', "|").explode('country').set_index("country")6df = pd.read_csv("datasets/g20_drinkingage.csv")7df = df.assign_rows(parity = lambda d, i: (i+1) % 2)8df = df.set_index("country")9df = df.assign_rows(gap = lambda d: get_non(d, 'max', d['min']) - d['min'])10df = df.assign_rows(illegal = lambda d, i: 0 if i not in ["Saudi Arabia", "India"] else 30 - d['max'])11df = df.assign_rows(bar = lambda d: 0 if d['parity'] else 30 - d['illegal'] - get_non(d, 'max', d['min']))1213def rlabel(r):14    img = Image.from_row([15        Image.from_text(df.index[r].replace("\\n","\n"), FONT(16), "black", align="center"),16        Image.from_url_with_cache(atlas.flag[df.index[r]]).convert("RGBA").resize((60,40)).trim(1).pad(1, "grey")17    ], padding=(2,0))18    return img.pad_to_aspect(150,40,bg=None if df.parity[df.index[r]] else BARBG, align=1)1920def label(c,r,v):21    if r == 0 and c == 2: return "illegal at any age"22    elif r == 0 or c > 0: return None23    elif r == 1: return "18-25 and illegal in some states"24    elif non(df['max'][df.index[r]]): return str(int(v))25    else: return "{}-{}".format(int(df['min'][df.index[r]]), int(df['max'][df.index[r]]))
...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!!
