How to use _items method in autotest

Best Python code snippet using autotest_python

venmo_test.py

Source:venmo_test.py Github

copy

Full Screen

1"""2Unit tests of vemno3"""4# pylint: disable=protected-access,5import unittest6import sys7from src.config import LOGIN, LOGOUT, INVALID, CLEAR_CACHE8import os9from src.venmo import main10from src.venmo_api import wf11class TestVenmo(unittest.TestCase):12 """Unit tests of venmo"""13 def test_settings(self):14 """Test if settings are displayed properly"""15 wf._items = []16 sys.argv = ['venmo.py', '>']17 main(None)18 self.assertEqual(len(wf._items), 3)19 self.assertEqual(wf._items[0].title, LOGIN['title'])20 self.assertEqual(wf._items[1].title, LOGOUT['title'])21 self.assertEqual(wf._items[2].title, CLEAR_CACHE['title'])22 wf._items = []23 def test_invalid_options(self):24 """Test if invalid option items is displayed"""25 wf._items = []26 sys.argv = ['venmo.py', '> not here']27 main(None)28 self.assertEqual(len(wf._items), 1)29 self.assertEqual(wf._items[0].title, INVALID['title'])30 self.assertFalse(wf._items[0].valid)31 self.assertFalse(wf._items[0].arg)32 wf._items = []33 def test_login(self):34 """Test if login item is displayed"""35 sys.argv = ['venmo.py', '> login']36 main(None)37 self.assertEqual(len(wf._items), 1)38 self.assertEqual(wf._items[0].title, LOGIN['title'])39 self.assertEqual(wf._items[0].arg, LOGIN['arg'])40 self.assertTrue(wf._items[0].valid)41 wf._items = []42 sys.argv = ['venmo.py', '>login']43 main(None)44 self.assertEqual(len(wf._items), 1)45 self.assertEqual(wf._items[0].title, LOGIN['title'])46 self.assertEqual(wf._items[0].arg, LOGIN['arg'])47 self.assertTrue(wf._items[0].valid)48 wf._items = []49 sys.argv = ['venmo.py', '> login']50 main(None)51 self.assertEqual(len(wf._items), 1)52 self.assertEqual(wf._items[0].title, LOGIN['title'])53 self.assertEqual(wf._items[0].arg, LOGIN['arg'])54 self.assertTrue(wf._items[0].valid)55 wf._items = []56 sys.argv = ['venmo.py', '> Login']57 main(None)58 self.assertEqual(len(wf._items), 1)59 self.assertEqual(wf._items[0].title, LOGIN['title'])60 self.assertEqual(wf._items[0].arg, LOGIN['arg'])61 self.assertTrue(wf._items[0].valid)62 wf._items = []63 sys.argv = ['venmo.py', '> LOGIN']64 main(None)65 self.assertEqual(len(wf._items), 1)66 self.assertEqual(wf._items[0].title, LOGIN['title'])67 self.assertEqual(wf._items[0].arg, LOGIN['arg'])68 self.assertTrue(wf._items[0].valid)69 wf._items = []70 def test_logout(self):71 """Test if logout item is displayed properly"""72 wf._items = []73 sys.argv = ['venmo.py', '> logout']74 main(None)75 self.assertEqual(len(wf._items), 1)76 self.assertEqual(wf._items[0].title, LOGOUT['title'])77 self.assertEqual(wf._items[0].arg, LOGOUT['arg'])78 self.assertTrue(wf._items[0].valid)79 wf._items = []80 sys.argv = ['venmo.py', '>logout']81 main(None)82 self.assertEqual(len(wf._items), 1)83 self.assertEqual(wf._items[0].title, LOGOUT['title'])84 self.assertEqual(wf._items[0].arg, LOGOUT['arg'])85 self.assertTrue(wf._items[0].valid)86 wf._items = []87 sys.argv = ['venmo.py', '> logout']88 main(None)89 self.assertEqual(len(wf._items), 1)90 self.assertEqual(wf._items[0].title, LOGOUT['title'])91 self.assertEqual(wf._items[0].arg, LOGOUT['arg'])92 self.assertTrue(wf._items[0].valid)93 wf._items = []94 sys.argv = ['venmo.py', '> Logout']95 main(None)96 self.assertEqual(len(wf._items), 1)97 self.assertEqual(wf._items[0].title, LOGOUT['title'])98 self.assertEqual(wf._items[0].arg, LOGOUT['arg'])99 self.assertTrue(wf._items[0].valid)100 wf._items = []101 sys.argv = ['venmo.py', '> LOGOUT']102 main(None)103 self.assertEqual(len(wf._items), 1)104 self.assertEqual(wf._items[0].title, LOGOUT['title'])105 self.assertEqual(wf._items[0].arg, LOGOUT['arg'])106 self.assertTrue(wf._items[0].valid)107 wf._items = []108 def test_clear_cache(self):109 """Test if clear cache item is displayed properly"""110 wf._items = []111 sys.argv = ['venmo.py', '> cl']112 main(None)113 self.assertEqual(len(wf._items), 1)114 self.assertEqual(wf._items[0].title, CLEAR_CACHE['title'])115 self.assertEqual(wf._items[0].arg, CLEAR_CACHE['arg'])116 self.assertTrue(wf._items[0].valid)117 wf._items = []118 sys.argv = ['venmo.py', '> clear C']119 main(None)120 self.assertEqual(len(wf._items), 1)121 self.assertEqual(wf._items[0].title, CLEAR_CACHE['title'])122 self.assertEqual(wf._items[0].arg, CLEAR_CACHE['arg'])123 self.assertTrue(wf._items[0].valid)124 wf._items = []125 sys.argv = ['venmo.py', '>cl']126 main(None)127 self.assertEqual(len(wf._items), 1)128 self.assertEqual(wf._items[0].title, CLEAR_CACHE['title'])129 self.assertEqual(wf._items[0].arg, CLEAR_CACHE['arg'])130 self.assertTrue(wf._items[0].valid)131 wf._items = []132 sys.argv = ['venmo.py', '> clear cache']133 main(None)134 self.assertEqual(len(wf._items), 1)135 self.assertEqual(wf._items[0].title, CLEAR_CACHE['title'])136 self.assertEqual(wf._items[0].arg, CLEAR_CACHE['arg'])137 self.assertTrue(wf._items[0].valid)138 wf._items = []139 def setUp(self):140 # supress stdout of feedback141 sys.stdout = open(os.devnull, 'w')142if __name__ == '__main__':...

Full Screen

Full Screen

arrayqueue.py

Source:arrayqueue.py Github

copy

Full Screen

1"""2File: arrayqueue.py3Author: Zachary King4"""5from arrays import Array6from abstractcollection import AbstractCollection7class ArrayQueue(AbstractCollection):8 """An array-based queue implementation."""9 # Class variable10 DEFAULT_CAPACITY = 1011 # Constructor12 def __init__(self, sourceCollection = None):13 """Sets the initial state of self, which includes the14 contents of sourceCollection, if it's present."""15 self._front = self._rear = -116 self._items = Array(ArrayQueue.DEFAULT_CAPACITY)17 AbstractCollection.__init__(self, sourceCollection)18 # Accessor methods19 def __iter__(self):20 """Supports iteration over a view of self."""21 cursor = self._front22 while cursor != self._rear:23 yield self._items[cursor]24 if cursor == len(self._items) - 1:25 cursor = 026 else:27 cursor += 128 if cursor == self._rear and cursor != -1:29 yield self._items[cursor]30 def peek(self):31 """Returns the item at the front of the queue.32 Precondition: the queue is not empty.33 Raises: KeyError if queue is empty."""34 if self.isEmpty():35 raise KeyError("Queue is empty")36 return self._items[len(self) - 1]37 # Mutator methods38 def clear(self):39 """Makes self become empty."""40 self._size = 041 self._front = self._rear = -142 self._items = Array(ArrayQueue.DEFAULT_CAPACITY)43 def add(self, item):44 """Inserts item at rear of the queue."""45 # Resize array if full46 if len(self) == len(self._items):47 temp = Array(len(self._items) * 2)48 # Copy so that front is at 0 and rear is at len(self) - 149 i = 050 # Copy data from position front through the end of the array51 for j in range(self._front, len(self)):52 temp[i] = self._items[j]53 i += 154 if self._rear < len(self) - 1:55 # Copy data from position 0 through the rear56 for j in range(0, self._rear + 1):57 temp[i] = self._items[j]58 i += 159 self._items = temp60 # Normalize front and rear61 self._front = 062 self._rear = len(self) - 1 63 if self.isEmpty():64 self._front = self._rear = 065 elif self._rear == len(self._items) - 1:66 self._rear = 067 else:68 self._rear += 169 self._items[self._rear] = item70 self._size += 171 def pop(self):72 """Removes and returns the item at the front of the queue.73 Precondition: the queue is not empty.74 Raises: KeyError if queue is empty.75 Postcondition: the front item is removed from the queue."""76 if self.isEmpty():77 raise KeyError("Queue is empty")78 data = self._items[self._front]79 self._size -= 180 if self.isEmpty(): self._front = self._rear = -1 81 elif self._front == len(self._items) - 1:82 self._front = 083 else:84 self._front += 185 if len(self) <= .25 * len(self._items) and \86 ArrayQueue.DEFAULT_CAPACITY <= len(self._items) // 2:87 tempArray = Array(len(self._items) // 2)88 i = 089 for item in self:90 tempArray[i] = item91 i += 192 self._items = tempArray93 if not self.isEmpty():94 self._front = 095 self._rear = len(self) - 196 return data97 def remove(self, index):98 """Removes and returns the item at index,99 where index ranges from 0 (the front) to size - 1 (the rear).100 Precondition: 0 <= index < size of queue"""101 if index < 0 or index >= len(self):102 raise AttributeError("i must be >= 0 and < size of queue")103 # Compute the position in the queue and save the item104 oldPos = (self._front + index) % len(self._items)105 oldItem = self._items[oldPos]106 self._size -= 1107 if self.isEmpty():108 # Empty queue, so reset pointers to initial state109 self._rear = self._front = -1110 elif oldPos <= self._rear:111 # oldPos is before rear in the array, so close hole112 # from oldPos down to rear113 for probe in range(oldPos, self._rear):114 self._items[probe] = self._items[probe + 1]115 self._rear -= 1116 else:117 # rear has wrapped around the array and oldPos is118 # between front and the end of the array, so close119 # hole from front to oldPos120 for probe in range(oldPos, self._front, -1):121 self._items[probe] = self._items[probe - 1]122 self._front += 1123 return oldItem124 ...

Full Screen

Full Screen

heap_queue.py

Source:heap_queue.py Github

copy

Full Screen

...11 12 def _items_less_than(self, checked_method, n):13 return self._items[checked_method].k < self._items[n].k14 15 def _swap_items(self, checked_method, n):16 self._items[checked_method], self._items[n] = self._items[n], self._items[checked_method]17 18 def _make_heap(self, i):19 smallest = i20 21 l = 2*i + 122 if l < len(self._items) and self._items_less_than(l, smallest):23 smallest = l24 25 r = 2*i + 226 if r < len(self._items) and self._items_less_than(r, smallest):27 smallest = r28 29 if smallest != i:30 self._swap_items(i, smallest)31 self._make_heap(smallest)32 33 def heapify(self):34 for i in xrange(len(self._items)//2, -1, -1):35 self._make_heap(i)36 37 def head(self):38 return self._items[0].value39 40 def push(self, value):41 i = len(self._items)42 new_item = _HeapItem(self.key(value), value)43 self._items.append(new_item)44 while i > 0:45 p = int((i - 1) // 2)46 if self._items_less_than(p, i):47 break48 self._swap_items(i, p)49 i = p50 51 def pop(self):52 popped = self._items[0].value53 self._items[0] = self._items[-1]54 self._items.pop(-1)55 self._make_heap(0)56 return popped57 58 def pushpop(self, value):59 k = self.key(value)60 if k <= self._items[0].k:61 return value62 else:...

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