Best Python code snippet using robotframework-ioslibrary_python
stroke_simulator.py
Source:stroke_simulator.py
1import time2import random3from PyQt5 import QtWidgets, QtCore, QtGui4class StrokeSimulator(QtCore.QThread):5 def __init__(self, set_position_callback, strokes_per_minute=30, mode='linear'):6 super().__init__(parent=None)7 self.mode = mode8 self.set_position_callback = set_position_callback9 self.strokes_per_minute = strokes_per_minute10 self.cycle_counter = 011 self.stop_simulator = False12 def set_strokes(self, strokes_per_minute):13 self.strokes_per_minute = strokes_per_minute14 def stop(self):15 self.stop_simulator = True16 def play_linear(self):17 while not self.stop_simulator:18 self.cycle_counter += 119 self.set_position_callback(position=99,20 interval=round(float(60)/self.strokes_per_minute*1000/2),21 respect_limits=True)22 time.sleep(60/self.strokes_per_minute/2)23 if self.stop_simulator: break24 self.set_position_callback(position=0,25 interval=round(float(60)/self.strokes_per_minute*1000/2),26 respect_limits=True)27 time.sleep(60/self.strokes_per_minute/2)28 def play_sequence(self, sequence):29 while not self.stop_simulator:30 self.cycle_counter += 131 for (seq_min, seq_max) in sequence:32 seq_dif = max((abs(seq_max - seq_min), 20))33 if self.stop_simulator:34 break35 self.set_position_callback(36 position=seq_min,37 interval=round(seq_dif/100.0 * float(60)/self.strokes_per_minute*1000/2),38 respect_limits=True)39 time.sleep(seq_dif/100.0 * (60/self.strokes_per_minute/2))40 if self.stop_simulator:41 break42 self.set_position_callback(43 position=seq_max,44 interval=round(seq_dif/100.0 * float(60)/self.strokes_per_minute*1000/2),45 respect_limits=True)46 time.sleep(seq_dif/100.0 * (60/self.strokes_per_minute/2))47 def rand_speed_by_distance(self, distance, speed_delta):48 mul = 100.0/max((2, distance))49 return random.randint(int(max((speed_delta, self.strokes_per_minute*mul - speed_delta))), int(self.strokes_per_minute*mul + speed_delta))50 def play_random(self):51 min_delta = 2052 speed_delta = int(self.strokes_per_minute / 33) # +-33%53 current_pos = 5054 max_top_pos = 9955 while not self.stop_simulator:56 self.cycle_counter += 157 rand_top_pos = random.randint(min_delta, max_top_pos)58 rand_up_speed = self.rand_speed_by_distance(abs(rand_top_pos - current_pos), speed_delta)59 # print('up:', rand_top_pos, rand_up_speed)60 self.set_position_callback(position=rand_top_pos,61 interval=round(float(60)/rand_up_speed*1000/2),62 respect_limits=False)63 time.sleep(60/rand_up_speed/2)64 current_pos = rand_top_pos65 if self.stop_simulator: break66 rand_bottom_pos = random.randint(0, max((1, rand_top_pos - min_delta - 1)))67 rand_down_speed = self.rand_speed_by_distance(abs(rand_bottom_pos - current_pos), speed_delta)68 # print('down:', rand_bottom_pos, rand_down_speed)69 self.set_position_callback(position=rand_bottom_pos,70 interval=round(float(60)/rand_down_speed*1000/2),71 respect_limits=False)72 time.sleep(60/rand_down_speed/2)73 current_pos = rand_bottom_pos74 def run(self):75 print('simulator mode', self.mode)76 if self.mode == 'random':77 self.play_random()78 elif self.mode == 'sequence_001':79 self.play_sequence([(0, 100), (50, 100)])80 elif self.mode == 'sequence_002':81 self.play_sequence([(0, 100), (50, 100), (50, 100)])82 else:...
serial_emulator.py
Source:serial_emulator.py
...35 while True:36 self.write_file_to_pt()37 38 except KeyboardInterrupt:39 self.stop_simulator()40 pass41 42 def start_emulator(self):43 self.emulate_device()44 def stop_simulator(self):45 os.close(self.master)46 os.close(self.slave)47 print("Terminated")48 49 50if __name__=='__main__':51 parser = argparse.ArgumentParser(description='Command line options for Serial emulator.\52 Press Ctrl-C to stop execution')53 parser.add_argument('-f','--file', required=True, type=str, dest='file',54 help='data file to simulate device')55 parser.add_argument('-s','--sample_time', default = 1, type=float, dest='sample_time',56 metavar='value',help='input sample time in seconds')57 58 args = parser.parse_args()...
com_read_file.py
Source:com_read_file.py
...35 while True:36 self.write_file_to_pt()37 38 except KeyboardInterrupt:39 self.stop_simulator()40 pass41 42 def start_emulator(self):43 self.emulate_device()44 def stop_simulator(self):45 os.close(self.master)46 os.close(self.slave)47 print("Terminated")48 49 50if __name__=='__main__':51 parser = argparse.ArgumentParser(description='Command line options for Serial emulator.\52 Press Ctrl-C to stop execution')53 parser.add_argument('-f','--file', required=True, type=str, dest='file',54 help='data file to simulate device')55 parser.add_argument('-s','--sample_time', default = 1, type=float, dest='sample_time',56 metavar='value',help='input sample time in seconds')57 58 args = parser.parse_args()...
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!!