Best Python code snippet using localstack_python
web_test.py
Source:web_test.py
...31 return '%s-%s' % (name, id)3233class Test(unittest.TestCase):3435 def test_matches(self):36 # matched, not raw mapping:37 self.assertEquals((), _matches('/', False, '/'))38 self.assertEquals((), _matches('/abc', False, '/abc'))39 self.assertEquals((), _matches('/a/b/c', False, '/a/b/c'))40 self.assertEquals((), _matches('/a/', False, '/a/'))4142 self.assertEquals(('123',), _matches('/$', False, '/123'))43 self.assertEquals(('abc',), _matches('/$', False, '/abc'))44 self.assertEquals(('xyz',), _matches('/$/', False, '/xyz/'))45 self.assertEquals(('a', 'b', 'c'), _matches('/$/$/$/', False, '/a/b/c/'))46 self.assertEquals(('a', 'b', 'c'), _matches('/$-$-$/', False, '/a-b-c/'))47 self.assertEquals(('a', 'b', 'c'), _matches('/pro-$/$/$/', False, '/pro-a/b/c/'))4849 # not matched, not raw mapping:50 self.assertEquals(None, _matches('/', False, ''))51 self.assertEquals(None, _matches('/', False, '/abc'))52 self.assertEquals(None, _matches('/$', False, '/abc/'))53 self.assertEquals(None, _matches('/$/$/', False, '/a/b/c/'))54 self.assertEquals(None, _matches('/abc-$', False, '/abc.xyz'))5556 # matched, raw mapping:57 self.assertEquals((), _matches('/', True, '/'))58 self.assertEquals(('abc',), _matches('/(.*)', True, '/abc'))59 self.assertEquals(('abc/xyz',), _matches('/(.*)', True, '/abc/xyz'))60 self.assertEquals(('abc', 'xyz'), _matches('/(.*)/(.*)', True, '/abc/xyz'))61 self.assertEquals(('a', 'b', ''), _matches('/(.+)/(.+)/(.*)', True, '/a/b/'))6263 # not matched, raw mapping:64 self.assertEquals(None, _matches('/', True, ''))65 self.assertEquals(None, _matches('/abc(.+)', True, '/abc'))66 self.assertEquals(None, _matches('/(.+)/(.+)/(.+)', True, '/a/b/'))6768 def test_say(self):69 f = say70 self.assertTrue(f.support_get)71 self.assertFalse(f.support_post)72 self.assertFalse(f.raw_mapping)73 self.assertEquals('/say', f.pattern)74 self.assertEquals('say', f.__name__)75 self.assertEquals('hello', f())76 self.assertEquals((), f.matches('/say'))77 self.assertEquals(None, f.matches('/say/'))7879 def test_get_product(self):80 f = get_product
...
queue.py
Source:queue.py
1from django.core.cache import cache2from .models import TwitchUser, Match, Game3QUEUE_TIMEOUT = 60 * 60 * 244class Queue:5 def __init__(self, channel_name):6 self.channel_name = channel_name7 self.channel = TwitchUser.from_username(channel_name, True).get_or_create_channel()8 self._matches = []9 self._open = False10 @property11 def current_match(self):12 return self._matches[0] if self._matches else None13 def get_match(self, index):14 return self._matches[index - 1]15 def add_match(self, player1, player2):16 match = Match(player1=player1, player2=player2, channel=self.channel)17 match.save()18 self._matches.append(match)19 self.save()20 def insert_match(self, player1, player2, index):21 if len(self._matches) < index:22 self.add_match(player1, player2)23 return len(self)24 match = Match(player1=player1, player2=player2, channel=self.channel)25 match.save()26 self._matches.insert(index - 1, match)27 self.save()28 return index29 def move_match(self, old_index, new_index):30 match = self._matches.pop(old_index - 1)31 self._matches.insert(min(new_index - 1, len(self)), match)32 self.save()33 def remove_match(self, index):34 match = self._matches.pop(index - 1)35 match.delete()36 self.save()37 def end_match(self, ended_by):38 match = self._matches.pop(0)39 match.end(ended_by)40 self.save()41 def clear(self):42 for match in self._matches:43 match.delete()44 self._matches = []45 self.save()46 def save(self):47 cache.set(f"queues.{self.channel_name}", self, timeout=QUEUE_TIMEOUT)48 def open(self):49 self._open = True50 self.save()51 def close(self):52 self._open = False53 self.save()54 def declare_winner(self, winner, losing_score):55 self.current_match.add_game(winner, losing_score)56 self.save()57 def is_empty(self):58 return len(self._matches) == 059 def is_open(self):60 return self._open61 @staticmethod62 def get(channel_name):63 return cache.get(f"queues.{channel_name}")64 def __len__(self):65 return len(self._matches)66 def __iter__(self):67 return iter(self._matches)68 def __bool__(self):...
api.py
Source:api.py
1#!/usr/bin/python2from driver import send_command, get_encoding3import time4import logging5import sys6import re7import traceback8# ------------------ API Commands ----------------------9def get_general_status():10 try:11 logging.debug('Querying device general status...')12 _cmd = 'QPIGS'13 _crc = 'ss'14 _res = send_command(_cmd, _crc)15 logging.debug('Result returned: %s', _res)16 _regex = r"\b(\d{1,3}\.?\d{0,2})\b"17 _match = re.search(_regex, _res)18 _matches = [x.group() for x in re.finditer( _regex, str(_res))]19 _grid_volt = _matches[0]20 _grid_freq = _matches[1]21 _ac_output_volt = _matches[2]22 _ac_output_freq = _matches[3]23 _ac_output_apparent_power = _matches[4]24 _ac_output_active_power = _matches[5]25 _output_load_perc = _matches[6]26 _bus_volt = _matches[7]27 _battery_volt = _matches[8]28 _battery_charging_current = _matches[9]29 _battery_capacity = _matches[10]30 _inverter_heat_sink_temp = _matches[11]31 # _pv_input_current_for_battery = _matches[12]32 # _pv_input_volt = _matches[13]33 # _battery_volt_from_scc = _matches[14]34 # _battery_discharge_current = _matches[15]35 # _device_status = _matches[16]36 _dataset = {37 "query_cmd": _cmd,38 "data": {39 "grid_voltage": _grid_volt40 }41 }42 return _dataset['data']43 except Exception as e:44 raise...
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!!