Best Python code snippet using pyatom_python
todo.py
Source:todo.py
...17 todo_items = open_file().split('\n')18 todo_items.append(new_task)19 write_file(todo_items)20def list_todo():21 output = list_helper()22 for i in range(len(output)):23 if output[i][-1] == 'X':24 print(i+1, '. [x] ',output[i][0:len(output[i])-1], sep='')25 else:26 print(i+1, '. [ ] ',output[i], sep='')27def list_helper():28 todo_items = open_file().split('\n')29 output = []30 for item in todo_items:31 if item != '' and item[len(item)-1] != '*':32 output.append(item)33 return output34def remove_helper():35 todo_items = open_file().split('\n')36 output = []37 for item in todo_items:38 if item != '':39 output.append(item)40 return output41def remove_todo(task_id = ''):42 if task_id == '':43 list_todo()44 print('')45 task_id = input('Choose lists number: ')46 return remove_todo(task_id)47 items = list_helper()48 output = []49 task_id = int(task_id)50 for i in range(len(items)):51 if i != (task_id - 1):52 output.append(items[i])53 else:54 output.append(items[i] + '*')55 write_file(output)56def list_removed_todo():57 todo_items = open_file().split('\n')58 output = []59 print('Removed elements:')60 for item in todo_items:61 if item != '' and item[len(item)-1] == '*':62 if item != '' and item[len(item)-2] == 'X':63 output.append(item[:len(item)-2])64 else:65 output.append(item[:len(item)-1])66 for i in range(len(output)):67 print(output[i][0:len(item)-1])68def completed_todo(task_id = ''):69 if task_id == '':70 list_todo()71 print('')72 task_id = input('Choose lists number: ')73 return completed_todo(task_id)74 items = list_helper()75 output = []76 task_id = int(task_id)77 for i in range(len(items)):78 if i != (task_id - 1):79 output.append(items[i])80 else:81 output.append(items[i] + " X")82 write_file(output)83def uncompleted_todo(task_id = ''):84 if task_id == '':85 list_todo()86 print('')87 task_id = input('Choose lists number: ')88 return uncompleted_todo(task_id)89 items = list_helper()90 output = []91 task_id = int(task_id)92 for i in range(len(items)):93 if i != (task_id - 1):94 output.append(items[i])95 else:96 output.append(items[i][:len(items[i])-2])...
test_list.py
Source:test_list.py
1import random2import pytest3from test_data.list import records, incorrect_records4@pytest.mark.parametrize('record', records)5def test_correct_record(app, record):6 app.list_helper.insure_place_available()7 old_list = app.list_helper.get_record_list()8 app.list_helper.add_record(record)9 new_list = app.list_helper.get_record_list()10 assert len(old_list) + 1 == len(new_list)11 old_list.append(record)12 assert old_list == new_list13def test_delete_record(app):14 app.list_helper.insure_record_exists()15 old_list = app.list_helper.get_record_list()16 num = random.choice(range(0, len(old_list)))17 app.list_helper.remove_record(num)18 new_list = app.list_helper.get_record_list()19 assert len(old_list) == len(new_list) + 120 old_list[num: num + 1] = []21 assert old_list == new_list22 pass23def test_add_max_records_num(app):24 if len(app.list_helper.get_record_list()) == app.list_helper.max_list_len:25 assert True26 else:27 for i in range(app.list_helper.max_list_len - len(app.list_helper.get_record_list()) - 1):28 app.list_helper.add_record('lalala')29 old_list = app.list_helper.get_record_list()30 app.list_helper.add_record('lalala')31 new_list = app.list_helper.get_record_list()32 assert len(old_list) + 1 == len(new_list)33 old_list.append('lalala')34 assert old_list == new_list35def test_eleven_records(app):36 if len(app.list_helper.get_record_list()) < app.list_helper.max_list_len:37 for i in range(app.list_helper.max_list_len - len(app.list_helper.get_record_list())):38 app.list_helper.add_record('lalala')39 old_list = app.list_helper.get_record_list()40 app.list_helper.add_record('lalala')41 new_list = app.list_helper.get_record_list()42 assert len(old_list) == len(new_list)43 assert old_list == new_list44 assert app.my_helper.warning_shown()45@pytest.mark.parametrize('record', incorrect_records)46def test_incorrect_record_len(app, record):47 app.list_helper.insure_place_available()48 old_list = app.list_helper.get_record_list()49 app.list_helper.add_record(record)50 new_list = app.list_helper.get_record_list()51 assert old_list == new_list...
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!!