Best Python code snippet using assertpy_python
performance_test.py
Source: performance_test.py
...64 for _ in range(size):65 values.append(random.uniform(-100000.0, 100000.0))66 values = set(values)67 @profile68 def test_ordered(dictionary):69 for v in values:70 dictionary[v] = str(v)71 previous = None72 for key in dictionary:73 assert key in values74 assert str(key) == dictionary[key]75 if previous:76 assert previous < key77 previous = key78 @profile79 def test_unordered(unordered):80 for v in values:81 unordered[v] = str(v)82 previous = None83 for key in unordered:84 assert key in values85 assert str(key) == unordered[key]86 if previous:87 assert previous != key88 previous = key89 print(f"C lib with {size} entries")90 test_ordered(asc)91 print(f"SortedDict Python lib with {size} entries")92 test_ordered(sorteddict)93 print(f"Orderbook SortedDict Python lib with {size} entries")94 test_ordered(python_sd)95 print(f"Python dict (non sorted) with {size} entries")96 test_unordered(raw_python)97def random_data_performance():98 for size in (10, 100, 200, 400, 500, 1000, 2000, 10000, 100000, 200000, 500000):99 random_data_test(size)100if __name__ == "__main__":101 print("Sorted Dict Performance\n")102 random_data_performance()103 print("\n\nOrderbook Overall\n")104 print("C lib OrderBook")105 profile_orderbook()106 print("Sortedcontainers OrderBook")107 profile_orderbook_sd()108 print("Python OrderBook")...
TestUnit.py
Source: TestUnit.py
...18 assert(get_scores_student(scores, student)[position - 1] == new_grade)19def test_lower_than(scores, score):20 returned_list = lower_than(scores, score)21 assert(returned_list == {'elev1': [], 'elev2': [], 'elev3': [], 'elev4': [1, 7], 'elev6': [8]})22def test_ordered(scores):23 scores_ordered = ordered(scores)24 assert(scores_ordered == {'elev1': [], 'elev2': [], 'elev3': [], 'elev4': [1, 7], 'elev6': [8], 'elev5': [5, 10]})25def test_bigger_than(scores, score):26 returned_list = bigger_than(scores, score)27 assert(returned_list == {'elev5': [5, 10]})28def test_media(scores, low, high):29 media = scores_range(scores, low, high)30 assert(media == 2.0)31def test_minimum(scores, low, high):32 try:33 min = minimum(scores, low, high)34 assert(False)35 except Exception as ex:36 assert(str(ex) == "Nu exista scor minim pe intervalul selectat!\n")37def test_multiple_of_10(scores, low, high):38 studs = multiple_of_10(scores, low, high)39 assert(studs == {'elev3': [10]})40def test_filter(scores, score):41 filter(scores, score)42 assert(scores == {'elev1': [], 'elev2': [], 'elev3': [10], 'elev4': [], 'elev5': [5, 10], 'elev6': []})43def test_filter_less_than(scores, score):44 filter_less_than(scores, score)45 assert(scores == {'elev1': [], 'elev2': [], 'elev3': [10], 'elev4': [], 'elev5': [], 'elev6': []})46def runAllTests():47 #Functia care ruleaza toate testele48 testing_scores_list = {"elev1": [1, 4, 5, 6], "elev2": [1, 5, 3], "elev3": [10], "elev4": [1, 5], "elev5": [5, 10]}49 test_add_new_score(testing_scores_list)50 test_insert_score(testing_scores_list, 3, 7)51 test_delete_score(testing_scores_list, 1)52 test_delete_range(testing_scores_list, 1, 3)53 test_replace(testing_scores_list, 4, 2, 7)54 test_lower_than(testing_scores_list, 9)55 test_ordered(testing_scores_list)56 test_bigger_than(testing_scores_list, 10)57 test_media(testing_scores_list, 1, 4)58 test_minimum(testing_scores_list, 1, 2)59 insert_score(testing_scores_list, 3, 10)60 test_multiple_of_10(testing_scores_list, 1, 3)61 test_filter(testing_scores_list, 5)...
checkbox_creator2.py
Source: checkbox_creator2.py
1import os2def test_ordered():3 folder = "dati"4 files = os.listdir(folder)5 x = enumerate(files)6 counter = 07 ckbx = ""8 for n,fname in x:9 print(n, fname)10 ch = int(input("choose > "))11 path = os.path.join(folder, os.listdir(folder)[ch])12 with open(path, "r", encoding="utf-8") as file:13 for line in file:14 if line != "\n":15 if counter != 0:16 ckbx = "[ ],"17 else:18 ckbx = ""19 counter = -120 print(ckbx, line.strip())21 counter += 122 return choose23def test_ordered():24 folder = "dati"25 files = os.listdir(folder)26 x = enumerate(files)27 counter = 028 ckbx = ""29 for n,fname in x:30 print(n, fname)31 ch = int(input("choose > "))32 path = os.path.join(folder, os.listdir(folder)[ch])33 with open(path, "r", encoding="utf-8") as file:34 for line in file:35 if line != "\n":36 if counter != 0:37 ckbx = "[ ],"38 answers.append(line)39 else:40 ckbx = ""41 counter = -142 print(line.strip())43 44 counter += 145 return choose46ch = test_ordered()...
Check out the latest blogs from LambdaTest on this topic:
I was once asked at a testing summit, “How do you manage a QA team using scrum?” After some consideration, I realized it would make a good article, so here I am. Understand that the idea behind developing software in a scrum environment is for development teams to self-organize.
Collecting and examining data from multiple sources can be a tedious process. The digital world is constantly evolving. To stay competitive in this fast-paced environment, businesses must frequently test their products and services. While it’s easy to collect raw data from multiple sources, it’s far more complex to interpret it properly.
Pair testing can help you complete your testing tasks faster and with higher quality. But who can do pair testing, and when should it be done? And what form of pair testing is best for your circumstance? Check out this blog for more information on how to conduct pair testing to optimize its benefits.
Greetings folks! With the new year finally upon us, we’re excited to announce a collection of brand-new product updates. At LambdaTest, we strive to provide you with a comprehensive test orchestration and execution platform to ensure the ultimate web and mobile experience.
If you pay close attention, you’ll notice that toggle switches are all around us because lots of things have two simple states: either ON or OFF (in binary 1 or 0).
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!!