Best Python code snippet using localstack_python
console.py
Source:console.py
1from Domain.obiect import creare_obiect, get_str2from Logic.functionalitati import modify_location, concat_string_descriere, pret_maxim_locatie, \3 ord_cresc_dupa_pret_achizitie, suma_pret_per_locatie4from Logic.general_logic import delete, read, update, create5def printMeniu():6 print('1. Adaugare obiect.')7 print('2. Afisare obiecte.')8 print('3. Stergere obiect.')9 print('4. Modificare obiect.')10 print('5. Detalii obiect.')11 print('6. Mutare obiecte intr-o alta locatie.')12 print('7. Concatenarea unui string la descrierea unui obiect care are pretul mai mare decat o valoare data.')13 print('8. Afisarea celui mai mare pret pentru fiecare locatie')14 print('9. Ordonarea obiectelor in ordine crescatoare dupa pretul achizitiei ')15 print('10. Afisare suma preturilor pentru fiecare locatie.')16 print('a. undo')17 print('b. redo')18 print('x. Iesire')19def handle_add(obiecte):20 try:21 id_obiect = int(input("Dati id-ul:"))22 nume_obiect = input("Dati numele obiectului:")23 descriere_obiect = input("Dati descrierea obiectului:")24 pret_obiect = int(input("Dati pretul:"))25 locatie_obiect = input("Dati locatia obiectului ,exact 4 caractere:")26 return create(obiecte, id_obiect, nume_obiect, descriere_obiect, pret_obiect, locatie_obiect)27 except ValueError as ve:28 print('Eroare: ', ve)29 return obiecte30def handle_delete(obiect):31 try:32 id_obiect = int(input("Dati id-ul obiectului pe care doriti sa il stergeti:"))33 return delete(obiect, id_obiect)34 except ValueError as ve:35 print('Eroare: ', ve)36 return obiect37def handle_modify_object(obiecte):38 try:39 id_obiect = int(input("Dati id-ul obiectului pe care doriti sa il modificati:"))40 nume_obiect = input("Dati numele obiectului:")41 descriere_obiect = input("Dati descrierea obiectului:")42 pret_obiect = int(input("Dati pretul:"))43 locatie_obiect = input("Dati locatia obiectului ,exact 4 caractere:")44 obiect = creare_obiect(id_obiect, nume_obiect, descriere_obiect, pret_obiect, locatie_obiect)45 return update(obiecte, obiect)46 except ValueError as ve:47 print('Eroare: ', ve)48 return obiecte49def handle_details(obiecte):50 try:51 id_obiect = int(input("Dati id-ul obiectului despre care vreti detalii:"))52 obiect = read(obiecte, id_obiect)53 return get_str(obiect)54 except ValueError as ve:55 print("Eroare:", ve)56 return obiecte57def handle_show_all(list_obiecte):58 for obiect in list_obiecte:59 print(get_str(obiect))60def handle_modify_location(obiecte):61 try:62 locatie_initiala = input("Dati locatia din care sa se mute obiectele (4 caractere):")63 locatie_noua = input("Dati locatia in care sa se mute obiectele (4 caractere):")64 obiecte = modify_location(obiecte, locatie_initiala, locatie_noua)65 except ValueError as ve:66 print("Eroare:", ve)67 return obiecte68def handle_concat_string_descriere(obiecte):69 try:70 string = input("Dati string-ul care va fi adaugat la descrierea obiectului: ")71 valoare = int(input("Dati o valoare pentru a compara pretul obiectului: "))72 obiecte = concat_string_descriere(obiecte, string, valoare)73 except ValueError as ve:74 print("Eroare: ", ve)75 return obiecte76def handle_pret_maxim_locatie(obiecte):77 result = pret_maxim_locatie(obiecte)78 for locatie in result:79 print("Locatia {} are pretul maxim {}".format(locatie, result[locatie]))80def handle_ord_cresc_dupa_pret_achizitie(obiecte):81 try:82 obiecte = ord_cresc_dupa_pret_achizitie(obiecte)83 return handle_show_all(obiecte)84 except ValueError as ve:85 print('Eroare:', ve)86 return obiecte87def handle_suma_pret_per_locatie(obiecte):88 result = suma_pret_per_locatie(obiecte)89 for locatie in result:90 print(f'{locatie} are suma preturilor {result[locatie]}')91def handle_new_list(list_versions, current_version, prajituri):92 while current_version < len(list_versions) - 1:93 list_versions.pop()94 list_versions.append(prajituri)95 current_version += 196 return list_versions, current_version97def handle_undo(list_versions, current_version):98 '''99 functie care anuleaza ultima functionalitate executata100 :param list_versions: versiunea actuala a listei101 :param current_version: numarul care reprezinta versiunea listei102 :return: lista actualizata103 '''104 try:105 if current_version < 1:106 print("Nu se mai poate face undo.")107 return list_versions[current_version], current_version108 current_version -= 1109 return list_versions[current_version], current_version110 except ValueError as ve:111 print('Eroare: ', ve)112def handle_redo(list_versions, current_version):113 '''114 functie care reface lista initiala in urma comenzii de undo115 :param list_versions: versiunea actuala a listei116 :param current_version: numarul care reprezinta versiunea listei117 :return: lista actualizata118 '''119 try:120 if current_version == len(list_versions) - 1:121 print("Nu se mai poate face redo.")122 return list_versions[current_version], current_version123 current_version += 1124 return list_versions[current_version], current_version125 except ValueError as ve:126 print('Eroare: ', ve)127def run_Menu(obiecte):128 list_versions = [obiecte]129 current_version = 0130 while True:131 printMeniu()132 optiune = input("Alegeti optiunea dorita:")133 if optiune == '1':134 obiecte = handle_add(obiecte)135 list_versions, current_version = handle_new_list(list_versions, current_version, obiecte)136 elif optiune == '2':137 handle_show_all(obiecte)138 list_versions, current_version = handle_new_list(list_versions, current_version, obiecte)139 elif optiune == '3':140 obiecte = handle_delete(obiecte)141 list_versions, current_version = handle_new_list(list_versions, current_version, obiecte)142 elif optiune == '4':143 obiecte = handle_modify_object(obiecte)144 list_versions, current_version = handle_new_list(list_versions, current_version, obiecte)145 elif optiune == '5':146 print(handle_details(obiecte))147 list_versions, current_version = handle_new_list(list_versions, current_version, obiecte)148 elif optiune == '6':149 obiecte = handle_modify_location(obiecte)150 print(obiecte)151 list_versions, current_version = handle_new_list(list_versions, current_version, obiecte)152 elif optiune == '7':153 obiecte = handle_concat_string_descriere(obiecte)154 print(obiecte)155 list_versions, current_version = handle_new_list(list_versions, current_version, obiecte)156 elif optiune == '8':157 obiecte = handle_pret_maxim_locatie(obiecte)158 list_versions, current_version = handle_new_list(list_versions, current_version, obiecte)159 elif optiune == '9':160 obiecte = handle_ord_cresc_dupa_pret_achizitie(obiecte)161 list_versions, current_version = handle_new_list(list_versions, current_version, obiecte)162 elif optiune == '10':163 obiecte = handle_suma_pret_per_locatie(obiecte)164 list_versions, current_version = handle_new_list(list_versions, current_version, obiecte)165 elif optiune == 'a':166 obiecte, current_version = handle_undo(list_versions, current_version)167 elif optiune == 'b':168 obiecte, current_version = handle_redo(list_versions, current_version)169 elif optiune == 'x':170 break171 else:172 print("Optiune invalida!")...
TestUndoRedo.py
Source:TestUndoRedo.py
1from UserInterface.interfata import handle_undo, handle_redo, handle_new_list2from Logic.logic import *3def test_undo_redo():4 list_versions = [[]]5 current_version = 06 lista = []7 lista = create(lista, 1, "Andrei", "economy plus", 180, "da")8 list_versions, current_version = handle_new_list(list_versions, current_version, lista)9 lista = create(lista, 2, "Carmen", "economy plus", 100, "nu")10 list_versions, current_version = handle_new_list(list_versions, current_version, lista)11 lista = create(lista, 3, "Andreea", "business", 249.9, "nu")12 list_versions, current_version = handle_new_list(list_versions, current_version, lista)13 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"},14 {"id": 2, "nume": "Carmen", "clasa": "economy plus", "pret": 100, "checkin": "nu"},15 {"id": 3, "nume": "Andreea", "clasa": "business", "pret": 249.9, "checkin": "nu"}]16 lista, current_version = handle_undo(list_versions, current_version)17 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"},18 {"id": 2, "nume": "Carmen", "clasa": "economy plus", "pret": 100, "checkin": "nu"}]19 lista, current_version = handle_undo(list_versions, current_version)20 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"}]21 lista, current_version = handle_undo(list_versions, current_version)22 assert lista == []23 lista = create(lista, 1, "Andrei", "economy plus", 180, "da")24 list_versions, current_version = handle_new_list(list_versions, current_version, lista)25 lista = create(lista, 2, "Carmen", "economy plus", 100, "nu")26 list_versions, current_version = handle_new_list(list_versions, current_version, lista)27 lista = create(lista, 3, "Andreea", "business", 249.9, "nu")28 list_versions, current_version = handle_new_list(list_versions, current_version, lista)29 lista, current_version = handle_redo(list_versions, current_version)30 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"},31 {"id": 2, "nume": "Carmen", "clasa": "economy plus", "pret": 100, "checkin": "nu"},32 {"id": 3, "nume": "Andreea", "clasa": "business", "pret": 249.9, "checkin": "nu"}]33 lista, current_version = handle_undo(list_versions, current_version)34 lista, current_version = handle_undo(list_versions, current_version)35 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"}]36 lista, current_version = handle_redo(list_versions, current_version)37 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"},38 {"id": 2, "nume": "Carmen", "clasa": "economy plus", "pret": 100, "checkin": "nu"}]39 lista, current_version = handle_redo(list_versions, current_version)40 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"},41 {"id": 2, "nume": "Carmen", "clasa": "economy plus", "pret": 100, "checkin": "nu"},42 {"id": 3, "nume": "Andreea", "clasa": "business", "pret": 249.9, "checkin": "nu"}]43 lista, current_version = handle_undo(list_versions, current_version)44 lista, current_version = handle_undo(list_versions, current_version)45 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"}]46 lista = create(lista, 4, "Mircea", "economy", 150, "da")47 list_versions, current_version = handle_new_list(list_versions, current_version, lista)48 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"},49 {"id": 4, "nume": "Mircea", "clasa": "economy", "pret": 150, "checkin": "da"}]50 lista, current_version = handle_redo(list_versions, current_version)51 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"},52 {"id": 4, "nume": "Mircea", "clasa": "economy", "pret": 150, "checkin": "da"}]53 lista, current_version = handle_undo(list_versions, current_version)54 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"}]55 lista, current_version = handle_undo(list_versions, current_version)56 assert lista == []57 lista, current_version = handle_redo(list_versions, current_version)58 lista, current_version = handle_redo(list_versions, current_version)59 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"},60 {"id": 4, "nume": "Mircea", "clasa": "economy", "pret": 150, "checkin": "da"}]61 lista, current_version = handle_redo(list_versions, current_version)62 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"},...
tetRedoUndo.py
Source:tetRedoUndo.py
1from UserInterface.interfata import handle_undo, handle_redo, handle_new_list2from Logic.logic import *3def test_undo_redo():4 list_versions = [[]]5 current_version = 06 lista = []7 lista = create(lista, 1, "Andrei", "economy plus", 180, "da")8 list_versions, current_version = handle_new_list(list_versions, current_version, lista)9 lista = create(lista, 2, "Carmen", "economy plus", 100, "nu")10 list_versions, current_version = handle_new_list(list_versions, current_version, lista)11 lista = create(lista, 3, "Andreea", "business", 249.9, "nu")12 list_versions, current_version = handle_new_list(list_versions, current_version, lista)13 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"},14 {"id": 2, "nume": "Carmen", "clasa": "economy plus", "pret": 100, "checkin": "nu"},15 {"id": 3, "nume": "Andreea", "clasa": "business", "pret": 249.9, "checkin": "nu"}]16 lista, current_version = handle_undo(list_versions, current_version)17 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"},18 {"id": 2, "nume": "Carmen", "clasa": "economy plus", "pret": 100, "checkin": "nu"}]19 lista, current_version = handle_undo(list_versions, current_version)20 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"}]21 lista, current_version = handle_undo(list_versions, current_version)22 assert lista == []23 lista = create(lista, 1, "Andrei", "economy plus", 180, "da")24 list_versions, current_version = handle_new_list(list_versions, current_version, lista)25 lista = create(lista, 2, "Carmen", "economy plus", 100, "nu")26 list_versions, current_version = handle_new_list(list_versions, current_version, lista)27 lista = create(lista, 3, "Andreea", "business", 249.9, "nu")28 list_versions, current_version = handle_new_list(list_versions, current_version, lista)29 lista, current_version = handle_redo(list_versions, current_version)30 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"},31 {"id": 2, "nume": "Carmen", "clasa": "economy plus", "pret": 100, "checkin": "nu"},32 {"id": 3, "nume": "Andreea", "clasa": "business", "pret": 249.9, "checkin": "nu"}]33 lista, current_version = handle_undo(list_versions, current_version)34 lista, current_version = handle_undo(list_versions, current_version)35 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"}]36 lista, current_version = handle_redo(list_versions, current_version)37 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"},38 {"id": 2, "nume": "Carmen", "clasa": "economy plus", "pret": 100, "checkin": "nu"}]39 lista, current_version = handle_redo(list_versions, current_version)40 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"},41 {"id": 2, "nume": "Carmen", "clasa": "economy plus", "pret": 100, "checkin": "nu"},42 {"id": 3, "nume": "Andreea", "clasa": "business", "pret": 249.9, "checkin": "nu"}]43 lista, current_version = handle_undo(list_versions, current_version)44 lista, current_version = handle_undo(list_versions, current_version)45 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"}]46 lista = create(lista, 4, "Mircea", "economy", 150, "da")47 list_versions, current_version = handle_new_list(list_versions, current_version, lista)48 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"},49 {"id": 4, "nume": "Mircea", "clasa": "economy", "pret": 150, "checkin": "da"}]50 lista, current_version = handle_redo(list_versions, current_version)51 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"},52 {"id": 4, "nume": "Mircea", "clasa": "economy", "pret": 150, "checkin": "da"}]53 lista, current_version = handle_undo(list_versions, current_version)54 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"}]55 lista, current_version = handle_undo(list_versions, current_version)56 assert lista == []57 lista, current_version = handle_redo(list_versions, current_version)58 lista, current_version = handle_redo(list_versions, current_version)59 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"},60 {"id": 4, "nume": "Mircea", "clasa": "economy", "pret": 150, "checkin": "da"}]61 lista, current_version = handle_redo(list_versions, current_version)62 assert lista == [{"id": 1, "nume": "Andrei", "clasa": "economy plus", "pret": 180, "checkin": "da"},...
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!!