How to use send_events method in localstack

Best Python code snippet using localstack_python

main.test.py

Source:main.test.py Github

copy

Full Screen

1import unittest2import json3from helpers import getActiveLanguage4usFixture = [5 {6 "identifier": "6058:20564:ThinkPad_Extra_Buttons",7 "name": "ThinkPad Extra Buttons",8 "vendor": 6058,9 "product": 20564,10 "type": "keyboard",11 "xkb_layout_names": [12 "English (US)",13 "Greek"14 ],15 "xkb_active_layout_index": 0,16 "xkb_active_layout_name": "English (US)",17 "libinput": {18 "send_events": "enabled"19 }20 },21 {22 "identifier": "2:10:TPPS/2_IBM_TrackPoint",23 "name": "TPPS/2 IBM TrackPoint",24 "vendor": 2,25 "product": 10,26 "type": "pointer",27 "libinput": {28 "send_events": "enabled",29 "accel_speed": 0,30 "accel_profile": "adaptive",31 "natural_scroll": "disabled",32 "left_handed": "disabled",33 "middle_emulation": "disabled",34 "scroll_method": "on_button_down",35 "scroll_button": 27436 }37 },38 {39 "identifier": "2:7:SynPS/2_Synaptics_TouchPad",40 "name": "SynPS/2 Synaptics TouchPad",41 "vendor": 2,42 "product": 7,43 "type": "touchpad",44 "libinput": {45 "send_events": "enabled",46 "tap": "enabled",47 "tap_button_map": "lrm",48 "tap_drag": "enabled",49 "tap_drag_lock": "disabled",50 "accel_speed": 0,51 "accel_profile": "none",52 "natural_scroll": "disabled",53 "left_handed": "disabled",54 "click_method": "button_areas",55 "middle_emulation": "disabled",56 "scroll_method": "two_finger",57 "dwt": "enabled"58 }59 },60 {61 "identifier": "1:1:AT_Translated_Set_2_keyboard",62 "name": "AT Translated Set 2 keyboard",63 "vendor": 1,64 "product": 1,65 "type": "keyboard",66 "xkb_layout_names": [67 "English (US)",68 "Greek"69 ],70 "xkb_active_layout_index": 0,71 "xkb_active_layout_name": "English (US)",72 "libinput": {73 "send_events": "enabled"74 }75 },76 {77 "identifier": "1226:28774:Integrated_Camera:_Integrated_C",78 "name": "Integrated Camera: Integrated C",79 "vendor": 1226,80 "product": 28774,81 "type": "keyboard",82 "xkb_layout_names": [83 "English (US)",84 "Greek"85 ],86 "xkb_active_layout_index": 0,87 "xkb_active_layout_name": "English (US)",88 "libinput": {89 "send_events": "enabled"90 }91 },92 {93 "identifier": "0:3:Sleep_Button",94 "name": "Sleep Button",95 "vendor": 0,96 "product": 3,97 "type": "keyboard",98 "xkb_layout_names": [99 "English (US)",100 "Greek"101 ],102 "xkb_active_layout_index": 0,103 "xkb_active_layout_name": "English (US)",104 "libinput": {105 "send_events": "enabled"106 }107 },108 {109 "identifier": "0:5:Lid_Switch",110 "name": "Lid Switch",111 "vendor": 0,112 "product": 5,113 "type": "switch",114 "libinput": {115 "send_events": "enabled"116 }117 },118 {119 "identifier": "0:6:Video_Bus",120 "name": "Video Bus",121 "vendor": 0,122 "product": 6,123 "type": "keyboard",124 "xkb_layout_names": [125 "English (US)",126 "Greek"127 ],128 "xkb_active_layout_index": 0,129 "xkb_active_layout_name": "English (US)",130 "libinput": {131 "send_events": "enabled"132 }133 },134 {135 "identifier": "0:1:Power_Button",136 "name": "Power Button",137 "vendor": 0,138 "product": 1,139 "type": "keyboard",140 "xkb_layout_names": [141 "English (US)",142 "Greek"143 ],144 "xkb_active_layout_index": 0,145 "xkb_active_layout_name": "English (US)",146 "libinput": {147 "send_events": "enabled"148 }149 }150]151elFixture = [152 {153 "identifier": "6058:20564:ThinkPad_Extra_Buttons",154 "name": "ThinkPad Extra Buttons",155 "vendor": 6058,156 "product": 20564,157 "type": "keyboard",158 "xkb_layout_names": [159 "English (US)",160 "Greek"161 ],162 "xkb_active_layout_index": 0,163 "xkb_active_layout_name": "English (US)",164 "libinput": {165 "send_events": "enabled"166 }167 },168 {169 "identifier": "2:10:TPPS/2_IBM_TrackPoint",170 "name": "TPPS/2 IBM TrackPoint",171 "vendor": 2,172 "product": 10,173 "type": "pointer",174 "libinput": {175 "send_events": "enabled",176 "accel_speed": 0,177 "accel_profile": "adaptive",178 "natural_scroll": "disabled",179 "left_handed": "disabled",180 "middle_emulation": "disabled",181 "scroll_method": "on_button_down",182 "scroll_button": 274183 }184 },185 {186 "identifier": "2:7:SynPS/2_Synaptics_TouchPad",187 "name": "SynPS/2 Synaptics TouchPad",188 "vendor": 2,189 "product": 7,190 "type": "touchpad",191 "libinput": {192 "send_events": "enabled",193 "tap": "enabled",194 "tap_button_map": "lrm",195 "tap_drag": "enabled",196 "tap_drag_lock": "disabled",197 "accel_speed": 0,198 "accel_profile": "none",199 "natural_scroll": "disabled",200 "left_handed": "disabled",201 "click_method": "button_areas",202 "middle_emulation": "disabled",203 "scroll_method": "two_finger",204 "dwt": "enabled"205 }206 },207 {208 "identifier": "1:1:AT_Translated_Set_2_keyboard",209 "name": "AT Translated Set 2 keyboard",210 "vendor": 1,211 "product": 1,212 "type": "keyboard",213 "xkb_layout_names": [214 "English (US)",215 "Greek"216 ],217 "xkb_active_layout_index": 1,218 "xkb_active_layout_name": "English (US)",219 "libinput": {220 "send_events": "enabled"221 }222 },223 {224 "identifier": "1226:28774:Integrated_Camera:_Integrated_C",225 "name": "Integrated Camera: Integrated C",226 "vendor": 1226,227 "product": 28774,228 "type": "keyboard",229 "xkb_layout_names": [230 "English (US)",231 "Greek"232 ],233 "xkb_active_layout_index": 0,234 "xkb_active_layout_name": "English (US)",235 "libinput": {236 "send_events": "enabled"237 }238 },239 {240 "identifier": "0:3:Sleep_Button",241 "name": "Sleep Button",242 "vendor": 0,243 "product": 3,244 "type": "keyboard",245 "xkb_layout_names": [246 "English (US)",247 "Greek"248 ],249 "xkb_active_layout_index": 0,250 "xkb_active_layout_name": "English (US)",251 "libinput": {252 "send_events": "enabled"253 }254 },255 {256 "identifier": "0:5:Lid_Switch",257 "name": "Lid Switch",258 "vendor": 0,259 "product": 5,260 "type": "switch",261 "libinput": {262 "send_events": "enabled"263 }264 },265 {266 "identifier": "0:6:Video_Bus",267 "name": "Video Bus",268 "vendor": 0,269 "product": 6,270 "type": "keyboard",271 "xkb_layout_names": [272 "English (US)",273 "Greek"274 ],275 "xkb_active_layout_index": 0,276 "xkb_active_layout_name": "English (US)",277 "libinput": {278 "send_events": "enabled"279 }280 },281 {282 "identifier": "0:1:Power_Button",283 "name": "Power Button",284 "vendor": 0,285 "product": 1,286 "type": "keyboard",287 "xkb_layout_names": [288 "English (US)",289 "Greek"290 ],291 "xkb_active_layout_index": 0,292 "xkb_active_layout_name": "English (US)",293 "libinput": {294 "send_events": "enabled"295 }296 }297]298class TestSum(unittest.TestCase):299 def test_active_layout(self):300 self.assertEqual(getActiveLanguage(usFixture), 0, "will return index 0")301 def test_active_layout_changed(self):302 self.assertEqual(getActiveLanguage(elFixture), 1, "will return index 1")303if __name__ == '__main__':...

Full Screen

Full Screen

helpers.py

Source:helpers.py Github

copy

Full Screen

1from .._connection import *2from .._events import *3from .._state import *4def get_all_events(conn):5 got_events = []6 while True:7 event = conn.next_event()8 if event in (NEED_DATA, PAUSED):9 break10 got_events.append(event)11 if type(event) is ConnectionClosed:12 break13 return got_events14def receive_and_get(conn, data):15 conn.receive_data(data)16 return get_all_events(conn)17# Merges adjacent Data events, converts payloads to bytestrings, and removes18# chunk boundaries.19def normalize_data_events(in_events):20 out_events = []21 for event in in_events:22 if type(event) is Data:23 event.data = bytes(event.data)24 event.chunk_start = False25 event.chunk_end = False26 if out_events and type(out_events[-1]) is type(event) is Data:27 out_events[-1].data += event.data28 else:29 out_events.append(event)30 return out_events31# Given that we want to write tests that push some events through a Connection32# and check that its state updates appropriately... we might as make a habit33# of pushing them through two Connections with a fake network link in34# between.35class ConnectionPair:36 def __init__(self):37 self.conn = {CLIENT: Connection(CLIENT), SERVER: Connection(SERVER)}38 self.other = {CLIENT: SERVER, SERVER: CLIENT}39 @property40 def conns(self):41 return self.conn.values()42 # expect="match" if expect=send_events; expect=[...] to say what expected43 def send(self, role, send_events, expect="match"):44 if not isinstance(send_events, list):45 send_events = [send_events]46 data = b""47 closed = False48 for send_event in send_events:49 new_data = self.conn[role].send(send_event)50 if new_data is None:51 closed = True52 else:53 data += new_data54 # send uses b"" to mean b"", and None to mean closed55 # receive uses b"" to mean closed, and None to mean "try again"56 # so we have to translate between the two conventions57 if data:58 self.conn[self.other[role]].receive_data(data)59 if closed:60 self.conn[self.other[role]].receive_data(b"")61 got_events = get_all_events(self.conn[self.other[role]])62 if expect == "match":63 expect = send_events64 if not isinstance(expect, list):65 expect = [expect]66 assert got_events == expect...

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