How to use sort_fn method in avocado

Best Python code snippet using avocado_python

views.py

Source:views.py Github

copy

Full Screen

1from django.shortcuts import render2from django.urls import reverse3from django.http import HttpResponse, HttpResponseRedirect4from django.http import JsonResponse5from . import amazon, flipkart, snapdeal, sort_fn, ShopClues6# Create your views here.7def home(request):8 if request.method == 'POST':9 product=request.POST.get('product')10 request.session['query']=product11 return HttpResponseRedirect(reverse('show_deal'))12 return render(request, 'scraper_app/index.html')13# def show_deal(request):14# query = request.session.get('query', None)15# a_items = sort_fn.RankProducts(amazon.scrape(query),10)16# f_items = sort_fn.RankProducts(flipkart.getItems(query),10)17# s_items = sort_fn.RankProducts(snapdeal.snapdeal(query),10)18# sc_items = sort_fn.RankProducts(ShopClues.scrape(query),10)19# items = a_items + s_items + f_items + sc_items20# deals = sort_fn.RankProducts(items,40,1)21# return render(request, 'scraper_app/show_deal.html', {'deals': deals, 'a_items':a_items, 'f_items':f_items, 's_items':s_items})22def show_deal(request, productName):23 # query = request.session.get('query', None)24 a_items=amazon.scrape(productName)25 f_items=flipkart.getItems(productName)26 s_items=snapdeal.snapdeal(productName)27 sc_items=ShopClues.scrape(productName)28 items2=a_items + s_items + f_items + sc_items29 if a_items!=[]:30 a_items = sort_fn.RankProducts(a_items, 10)31 if f_items!=[]:32 f_items = sort_fn.RankProducts(f_items, 10)33 if s_items!=[]:34 s_items = sort_fn.RankProducts(s_items, 10)35 if sc_items!=[]:36 sc_items = sort_fn.RankProducts(sc_items, 10)37 items = a_items + s_items + f_items + sc_items38 deals=[]39 if items!=[]:40 deals = sort_fn.RankProducts(items,40,1)41 # return render(request, 'scraper_app/show_deal.html', {'items':items})42 return JsonResponse({'deals':deals, 'items':items}, safe=False)43def getFilteredData(request, productName, minimum, maximum):44 #request.lower_bound, request.upper_bound45 #give these to sort function with items46 minimum=float(minimum)47 maximum=float(maximum)48 a_items=amazon.scrape(productName)49 f_items=flipkart.getItems(productName)50 s_items=snapdeal.snapdeal(productName)51 sc_items=ShopClues.scrape(productName)52 items2=a_items + s_items + f_items + sc_items53 items3=[]54 for item in items2:55 if item['price_inr']!='':56 item_price = float(item['price_inr'].strip().replace(',', ''))57 if item_price>=minimum and item_price<=maximum:58 items3.append(item)59 deals=[]60 if items3!=[]:61 deals = sort_fn.RankProducts(items3,40,1)...

Full Screen

Full Screen

test_sort.py

Source:test_sort.py Github

copy

Full Screen

...22 (merge_sort,[3,2,1],[1,2,3]),23 (merge_sort,[11, 25, 12, 22, 64],[11,12,22, 25, 64]),24 ])25def test_sort(sort_fn, input, expected):26 assert sort_fn(input) == expected27@pytest.mark.parametrize("sort_fn, sizes", [28 (bubble_sort, [10,100,1000,10000]), 29 (insertion_sort,[10,100,1000,10000]),30 (selection_sort,[10,100,1000,10000]),31 (merge_sort,[10,100,1000,10000,100000,1000000])32 ])33def test_performance(sort_fn, sizes):34 for size in sizes:35 start = timer()36 sort_fn(reversed_list(size))37 end = timer()...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

...9 pos = n10 11 if self.sort_fn != None:12 for i in range(n):13 if self.sort_fn(element) < self.sort_fn(self.queue[i]):14 pos = i; break15 16 self.queue.insert(pos, element)17 def pop(self):18 return self.queue.pop(0)19 def remove(self, el):20 self.queue.remove(el)21 def find(self, find_fn):22 for e in self.queue:23 if find_fn(e):24 return e25 def index(self, element):26 for i in range(len(self.queue)):27 if element == self.queue[i]:...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful