How to use set_priority method in autotest

Best Python code snippet using autotest_python

priority_queue.py

Source:priority_queue.py Github

copy

Full Screen

1"""2Python implementation of a priority queue3The expected interface:4- insert(key, priority)5- set_priority(key, priority) / set_priority(new_key, priority)6- pop()7- size()8- empty()9Read the doc strings for more info10"""11class PriorityQueueElement(object):12 def __init__(self, key, priority):13 self.key = key14 self.priority = priority15 def __repr__(self):16 return '<%s: %s>' % (self.key, self.priority)17class PriorityQueue(object):18 """Base class with unimplemented comparator"""19 def __init__(self):20 self.arr = []21 self.positions = {} # Mapping from values to their current indexes22 def _heapify(self, idx):23 """24 Makes sure the heap constraints are satisfied in the sub heap25 starting at idx26 """27 if idx >= len(self.arr)/2:28 return29 left = self._left(idx)30 right = self._right(idx)31 if left >= self.size():32 return33 if right >= self.size():34 replace_idx = left35 else:36 compare = self._comparator(self.arr[left], self.arr[right])37 replace_idx = left if compare >= 0 else right38 if self._comparator(self.arr[idx], self.arr[replace_idx]) < 0:39 self._swap(idx, replace_idx)40 self._heapify(replace_idx)41 def _bubble_up(self, idx):42 """43 Moves the element at i, as close to the root as it can get44 to satisfy the heap invariant.45 Refer to insert for usage.46 """47 while idx > 0:48 parent = self._parent(idx)49 if self._comparator(self.arr[parent], self.arr[idx]) < 0:50 self._swap(parent, idx)51 idx = parent52 else:53 break54 def _swap(self, i1, i2):55 """Swaps elements at i1 and i2 in the underlying array"""56 self.positions[self.arr[i1].key] = i257 self.positions[self.arr[i2].key] = i158 self.arr[i1], self.arr[i2] = self.arr[i2], self.arr[i1]59 def _comparator(self, a, b):60 """61 Returns -1, 0 or 1 based on how a compares to b62 Min and Max heaps / priority queues implement this differently63 """64 raise NotImplementedError65 def pop(self):66 """67 Removes the top most element, rearranges the heap to retain its68 properties and returns the removed element69 """70 self._swap(0, self.size()-1)71 ret = self.arr.pop()72 if self.size():73 self._heapify(0)74 return ret75 def insert(self, key, priority):76 """77 Inserts the given value in the heap and ensures heap is still valid78 """79 self.arr.append(PriorityQueueElement(key, priority))80 self.positions[key] = len(self.arr)-181 self._bubble_up(len(self.arr)-1)82 def set_priority(self, key, priority):83 """84 Inserts the value with the given priority if it doesn't already exist85 Updates the priority if it does exist86 """87 if key not in self.positions:88 self.insert(key, priority)89 else:90 current_pos = self.positions[key]91 curr_element = self.arr[current_pos]92 self.arr[current_pos] = PriorityQueueElement(key, priority)93 if self._comparator(self.arr[current_pos], curr_element) >= 0:94 # If compares positively, we want to bubble it up95 # i.e. in MinPriorityQueue, new priority is lower than existing96 # and in MaxPriorityQueue, new priority is higher97 self._bubble_up(current_pos)98 else:99 # Otherwise, we want to bubble it down a.k.a. heapify100 self._heapify(current_pos)101 def _parent(self, idx):102 """Returns the parent index of the node at given index"""103 return (idx-1)/2104 def _left(self, idx):105 """Returns the left child index of the node at given index"""106 return 2*idx + 1107 def _right(self, idx):108 """Returns the right child index of the node at given index"""109 return 2*idx + 2110 def size(self):111 """Returns the size of the priority queue"""112 return len(self.arr)113 def empty(self):114 """Returns whether the priority queue is empty"""115 return self.size() == 0116class MinPriorityQueue(PriorityQueue):117 """PriorityQueue with least priority element at the top"""118 def _comparator(self, a, b):119 assert isinstance(a, PriorityQueueElement)120 assert isinstance(b, PriorityQueueElement)121 if a.priority < b.priority:122 return 1123 if a.priority == b.priority:124 return 0125 return -1126class MaxPriorityQueue(PriorityQueue):127 """PriorityQueue with highest priority element at the top"""128 def _comparator(self, a, b):129 assert isinstance(a, PriorityQueueElement)130 assert isinstance(b, PriorityQueueElement)131 if a.priority > b.priority:132 return 1133 if a.priority == b.priority:134 return 0135 return -1136if __name__ == '__main__':137 q = MinPriorityQueue()138 q.set_priority(1, 1000)139 q.insert(2, 2000)140 q.set_priority(3, 3000)141 q.insert(4, 4000)142 q.set_priority(3, 0)143 q.set_priority(4, 1)144 q.set_priority(2, 2)145 q.set_priority(1, 3)146 q.set_priority(3, 5)147 q.set_priority(4, 6)148 while not q.empty():149 print q.pop()150 q = MaxPriorityQueue()151 q.set_priority(1, 1000)152 q.insert(2, 2000)153 q.set_priority(3, 3000)154 q.insert(4, 4000)155 q.set_priority(3, 0)156 q.set_priority(4, 1)157 q.set_priority(2, 2)158 q.set_priority(1, 3)159 q.set_priority(3, 5)160 q.set_priority(4, 6)161 while not q.empty():...

Full Screen

Full Screen

priority_table.py

Source:priority_table.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2##############################################################################3#4# OpenERP, Open Source Management Solution5# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).6#7# This program is free software: you can redistribute it and/or modify8# it under the terms of the GNU Affero General Public License as9# published by the Free Software Foundation, either version 3 of the10# License, or (at your option) any later version.11#12# This program is distributed in the hope that it will be useful,13# but WITHOUT ANY WARRANTY; without even the implied warranty of14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15# GNU Affero General Public License for more details.16#17# You should have received a copy of the GNU Affero General Public License18# along with this program. If not, see <http://www.gnu.org/licenses/>.19#20##############################################################################21import openerp22from openerp import SUPERUSER_ID, api23from openerp import tools24from openerp.osv import fields, osv, expression # V725from openerp import models, fields, api, _ # v826from openerp.exceptions import except_orm,UserError, ValidationError27import re28import time29import datetime30from datetime import datetime31from time import gmtime, strftime32class priority_table(models.Model):33 _name = 'priority.table'34 name = fields.Text('Priority Name:')35 set_priority = fields.Selection([('true','True'),('false','False')],string ='Set Priority:')36 select_name = fields.Many2one('res.partner','Please Select Your Name:')37 @api.model38 def create(self,vals):39 print "Inside Create===================",self._context40 new_id = vals['select_name']41 print "NEW ID==================================",new_id42 # new_id = self._context.get('params')['id']43 # print "NEW ID================================",new_id44 b = self.env['priority.table'].search(['&',('select_name','=',new_id),('set_priority','=','true')])45 for each in b:46 print "====================B IS PRINTING=================",each.id47 print "=====================values======================",each.set_priority48 if vals['set_priority'] == 'true':49 print "Inside=================Create ONLY==============================="50 each.set_priority = 'false'51 return super(priority_table, self).create(vals)52 @api.multi53 def write(self,vals):54 print "Inside WRITE===================",self._context55 # new_id = self._context.get('params')['id']56 # print "NEW ID=WRITE===============================",new_id57 print "PARTNER ID===============================",self.select_name58 new_id = self.select_name.id59 b = self.env['priority.table'].search(['&',('select_name','=',new_id),('set_priority','=','true')])60 for each in b:61 print "====================B IS PRINTING(WRITE)=================",each.id62 print "=====================values(WRITE)======================",each.set_priority63 if vals['set_priority'] == 'true':64 print "Inside=================WRITE ONLY==============================="65 each.set_priority = 'false'66 return super(priority_table, self).write(vals)67 #68 # @api.multi69 # def write(self,vals):70 # print "Inside write+++++++++++++++++++++++++++++++++++++++++++++++++++",self._context71 #72 # new_id = self._context.get('params')['id']73 # print "NEW ID+++++++++++++++++++++++++++++++++++++++++++++++++",new_id74 #75 # for each in self.select_name:76 # b = self.env['priority.table'].search(['&',('select_name','=',new_id),('set_priority','=','true')])77 # print "+++++++++++++++++++++++values+++++++++++++++++++++++++++++++",b.set_priority78 #79 #80 # if vals['set_priority'] == 'true':81 # print "Inside Write ONLY++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"82 # b.set_priority = 'false'83 # return super(priority_table, self).write(vals)84class relation_priority(models.Model):85 _name = 'sale.order'86 _inherit = 'sale.order'87 relation = fields.Many2one('priority.table','Relation :')88 @api.onchange('partner_id')89 def change(self):90 a = self.partner_id91 print "a================================",a.id92 id=093 #Abhishek Help94 # for each in a.check_priority:95 # print "each=============================",each.id96 # if each.set_priority == 'true':97 # print "True================"98 # id = each.id99 #100 # print "ID============",id101 # self.relation = id102 inv = self.env['priority.table'].search(['&',('select_name','=',a.id),('set_priority','=','true')])103 for each in inv:104 print "INV===================================",each105 print "VALUES=================================",each.set_priority106 id = each.id107 # if each.set_priority == 'true':108 print "ID==============",id109 self.relation = id...

Full Screen

Full Screen

test_setpriority.py

Source:test_setpriority.py Github

copy

Full Screen

...10 assert set_priority.body_parameters() == {'priority': 10}11@unittest.mock.patch('requests.Session.request')12def test_setpriority_calls_requests(mock, engine_url):13 set_priority = pycamunda.externaltask.SetPriority(url=engine_url, id_='anId', priority=10)14 set_priority()15 assert mock.called16 assert mock.call_args[1]['method'].upper() == 'PUT'17@unittest.mock.patch('requests.Session.request', raise_requests_exception_mock)18def test_setpriority_raises_pycamunda_exception(engine_url):19 set_priority = pycamunda.externaltask.SetPriority(url=engine_url, id_='anId', priority=10)20 with pytest.raises(pycamunda.PyCamundaException):21 set_priority()22@unittest.mock.patch('requests.Session.request', not_ok_response_mock)23@unittest.mock.patch('pycamunda.base._raise_for_status')24def test_setpriority_raises_for_status(mock, engine_url):25 set_priority = pycamunda.externaltask.SetPriority(url=engine_url, id_='anId', priority=10)26 set_priority()27 assert mock.called28@unittest.mock.patch('requests.Session.request', unittest.mock.MagicMock())29def test_setpriority_returns_none(engine_url):30 set_priority = pycamunda.externaltask.SetPriority(url=engine_url, id_='anId', priority=10)31 result = set_priority()...

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 autotest 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