Best Python code snippet using localstack_python
qr_reader.py
Source:qr_reader.py
1#!/usr/bin/env python2# Implementazione della classe QR_Reader. 3# Stima la posa globale (wrt MAP frame) della carrozzina utilizzando le informazioni pubblicate dal nodo visp_auto_tracker.4# NB: I qr code devono essere orientati con l'angolo vuoto in basso a destra rispetto alla posizione iniziale della carrozzina.5#6# Modalita di funzionamento: 7# -) gazebo: viene usato l'orientamento da gazebo per la stima della posa8# -) odom: viene usato l'orientamento dall'odometria per la stima della posa9# -) imu: viene usato l'orientamento dall'imu per la stima della posa10# -) qr: l'orientamento viene stimato dall'inclinazione dell'immagine. in questa modalita, per la stima vengono usati solo dati ottenuti dall'immagine.11#12# Subscribed Topics:13# -) /visp_auto_tracker/object_position_covariance14# -) /visp_auto_tracker/code_message15# -) /odometry/ekf_odom solo in modalita odom16# -) /odometry/ground_truth_odom solo in modalita gazebo17# -) /imu/data solo in modalita imu18# 19# Published Topics:20# -) /qr_pose21# 22# Attributes: 23# -) pose: 4x4 matrix, posizione stimata24#25# Methods: 26# -) get_pose(): ritorna True se e possibile calcolare la posa, mettendo il risultato in obj.pose. Viceversa, ritorna False.27# -) publish(T): pubblica la posa (T 4x4) in formato PoseWithCovarianceStamped sull'output topic /qr_pose.28import rospy29import numpy as np30import tf31import math32from geometry_msgs.msg import PoseWithCovarianceStamped33from nav_msgs.msg import Odometry34from sensor_msgs.msg import Imu35from std_msgs.msg import String36class QR_Reader ():37 def __init__(self, mode = 'gazebo'):38 39 ############# Public Attributes #############40 41 self.pose = None # Tf finale MAP -> BASE_FOOTPRINT42 43 44 ############# Protected Attributes #############45 46 self.t = tf.TransformListener()47 48 self._mode = mode 49 self._available_modes = ("imu", "odom", "qr", "gazebo")50 self._check_params()51 52 self.qr_pos = np.ones((4,1)) # Posizione del qr dal topic object_position_covariance53 self.qr_orientation = [0,0,0,1] # Orientamento del qr dal topic object_position_covariance54 self.qr_covariance = None # Covarianza del qr dal topic object_position_covariance55 self.qr_map = np.zeros((3,1)) # Posizione assoluta del qr dal topic code_message56 self.model_orientation = [0,0,0,1] # Orientamento carrozzina dall'odometria57 self.imu_model_orientation = [0,0,0,1] # Orientamento carrozzina dall'imu58 self.gazebo_model_position = [None,None,None] # Posizione carrozzina da Gazebo59 self.gazebo_model_orientation = [0,0,0,1] # Orientamento carrozzina da Gazebo60 61 62 self.room = 0 # ID dell'ambiente (attualmente inutilizzato)63 self.qr_presence = False # Presenza o no di un qr nell'inquadratura 64 65 self.T_l2r = np.array([[1,0,0,0],[0,0,1,0],[0,1,0,0],[0,0,0,1]]) # T da frame immagine sx a dx66 self.R_imm_QR = np.array([[0,0,-1,0],[1,0,0,0],[0,-1,0,0],[0,0,0,1]]) # R da frame immagine dx a QR 67 self.T_cam_bf = None # Tf CAMERA_LINK -> BASE_FOOTPRINT68 self.R_cam = None # R CAM -> CAMERA_LINK69 70 self.qr_pos_sub = rospy.Subscriber("/visp_auto_tracker/object_position_covariance", PoseWithCovarianceStamped, self._qr_pos_callback)71 self.qr_msg_sub = rospy.Subscriber("/visp_auto_tracker/code_message", String, self._qr_msg_callback)72 if self._mode == "odom": 73 self.odom_sub = rospy.Subscriber("/odometry/ekf_odom", Odometry, self._odom_sub_callback)74 if self._mode == "gazebo": 75 self.gazebo_sub = rospy.Subscriber("/odometry/ground_truth_odom", Odometry, self._gazebo_sub_callback)76 if self._mode == "imu": 77 self.imu_sub = rospy.Subscriber("/imu/data", Imu, self._imu_sub_callback)78 79 self.pub = rospy.Publisher("qr_pose", PoseWithCovarianceStamped, queue_size = 10)80 81 self._exit_code = 0 82 rospy.on_shutdown(self._shutdown)83 self._init_transforms()84 85 rospy.loginfo("QR Reader started in %s mode." % self._mode)86 87 88 89 ############# Public Methods #############90 91 def get_pose (self):92 93 if self.qr_presence: 94 # Trasformo posizione e orientamento del qr da frame immagine sx a dx95 new_pos, new_quat = self._left_hand_to_right_hand_frame(self.T_l2r)96 97 # Trovo la rotazione R_qr per compensare la rotazione del frame immagine dovuta al yaw della carrozzina, per poi trasformarlo in QR98 R_qr = self._get_qr_orientation(new_quat)99 100 # Trasformo il vettore qr_pos dal frame immagine al frame QR, che e orientato come MAP e centrato nel qr code.101 R_qr_cam = tf.transformations.concatenate_matrices(R_qr,self.R_imm_QR)102 p_qr_cam = np.dot(R_qr_cam,new_pos) 103 104 # Calcolo la tf MAP -> QR. La traslazione corrisponde alle coordinate scritte nel qr code, mentre l'orientamento e lo stesso.105 T_map_qr = self.t.fromTranslationRotation(self.qr_map.T,(0,0,0,1))106 107 # Calcolo la tf QR -> CAM. La traslazione e il vettore trasformato p_qr_cam, la rotazione e l'orientamento della carrozzina.108 T_qr_cam = R_qr109 T_qr_cam[:,3] = p_qr_cam.T110 111 # Concateno le tf MAP -> QR -> CAM -> CAMERA_LINK -> BASE_FOOTPRINT112 T_map_bf = tf.transformations.concatenate_matrices(T_map_qr,T_qr_cam,self.R_cam,self.T_cam_bf)113 self.pose = T_map_bf114 return True115 return False116 117 def publish (self, T):118 119 pos = tf.transformations.translation_from_matrix(T)120 quat = tf.transformations.quaternion_from_matrix(T)121 122 msg = PoseWithCovarianceStamped()123 msg.header.stamp = rospy.Time.now()124 msg.header.frame_id = "map"125 msg.pose.pose.position.x = pos[0]126 msg.pose.pose.position.y = pos[1]127 msg.pose.pose.position.z = pos[2]128 msg.pose.pose.orientation.x = quat[0]129 msg.pose.pose.orientation.y = quat[1]130 msg.pose.pose.orientation.z = quat[2]131 msg.pose.pose.orientation.w = quat[3]132 133 msg.pose.covariance = self.qr_covariance134 135 self.pub.publish(msg)136 137 138 ############# Protected Methods #############139 140 def _exit_code_bindings (self, code):141 _errors = { 142 20: "Timeout occurred while waiting for transform.",143 21: "An error occurred while getting the transform.",144 } 145 146 _warnings = { 147 10: "", 148 } 149 150 _info = { 151 0: "QR Reader is shutting down.", 152 } 153 154 if code in _info.keys():155 code_type = 0156 exit_message = _info.get(code) 157 158 if code in _warnings.keys():159 code_type = 1160 exit_message = _warnings.get(code) 161 162 if code in _errors.keys():163 code_type = 2164 exit_message = _errors.get(code) 165 166 return (code_type, exit_message)167 168 def _shutdown(self):169 type, error_message = self._exit_code_bindings(self._exit_code)170 171 if type == 0:172 rospy.loginfo(error_message)173 if type == 1:174 rospy.logwarn(error_message)175 if type == 2:176 rospy.logerr(error_message)177 def _qr_pos_callback (self, msg): 178 self.qr_pos[0] = msg.pose.pose.position.x179 self.qr_pos[1] = msg.pose.pose.position.y180 self.qr_pos[2] = msg.pose.pose.position.z181 182 self.qr_orientation[0] = msg.pose.pose.orientation.x183 self.qr_orientation[1] = msg.pose.pose.orientation.y184 self.qr_orientation[2] = msg.pose.pose.orientation.z185 self.qr_orientation[3] = msg.pose.pose.orientation.w186 187 self.qr_covariance = msg.pose.covariance188 def _qr_msg_callback (self, msg):189 # Pattern del messaggio del QR: "#xx#yy#zz#rr" 190 if msg.data != "":191 _var = msg.data.split("#")192 self.qr_map[0] = _var[1]193 self.qr_map[1] = _var[2]194 self.qr_map[2] = _var[3]195 self.room = _var[4]196 self.qr_presence = True197 else:198 self.qr_presence = False199 200 def _odom_sub_callback (self, msg):201 202 self.model_orientation[0] = msg.pose.pose.orientation.x203 self.model_orientation[1] = msg.pose.pose.orientation.y204 self.model_orientation[2] = msg.pose.pose.orientation.z205 self.model_orientation[3] = msg.pose.pose.orientation.w206 207 def _gazebo_sub_callback (self, msg):208 self.gazebo_model_position[0] = msg.pose.pose.position.x209 self.gazebo_model_position[1] = msg.pose.pose.position.y210 self.gazebo_model_position[2] = msg.pose.pose.position.z211 212 self.gazebo_model_orientation[0] = msg.pose.pose.orientation.x213 self.gazebo_model_orientation[1] = msg.pose.pose.orientation.y214 self.gazebo_model_orientation[2] = msg.pose.pose.orientation.z215 self.gazebo_model_orientation[3] = msg.pose.pose.orientation.w216 217 def _imu_sub_callback (self, msg):218 219 self.imu_model_orientation[0] = msg.orientation.x220 self.imu_model_orientation[1] = msg.orientation.y221 self.imu_model_orientation[2] = msg.orientation.z222 self.imu_model_orientation[3] = msg.orientation.w223 224 def _init_transforms (self):225 226 try:227 self.t.waitForTransform("camera_link","base_footprint",rospy.Time(),rospy.Duration(4))228 except tf.Exception:229 self._exit_code = 20230 rospy.signal_shutdown("") 231 232 try:233 _T_cam_bf = self.t.lookupTransform("camera_link","base_footprint",rospy.Time(0))234 self.T_cam_bf = self.t.fromTranslationRotation(_T_cam_bf[0],_T_cam_bf[1])235 self.R_cam = tf.transformations.quaternion_matrix([ 0, -0.7071068, 0, 0.7071068 ]) # Rotazione tra BASE_FOOTPRINT (CAM) e CAMERA_LINK236 except tf.Exception:237 self._exit_code = 21238 rospy.signal_shutdown("")239 240 def _check_params (self):241 242 if not (self._mode in self._available_modes):243 rospy.logwarn("The param mode is not correct. The default gazebo mode will be used.")244 self._mode = "gazebo"245 def _get_qr_orientation (self, qr_orient):246 247 # La rotazione del frame immagine corrisponde all'angolo di yaw della carrozzina248 if self._mode == "imu":249 R_qr = self.t.fromTranslationRotation((0,0,0),self.imu_model_orientation)250 251 if self._mode == "odom":252 R_qr = self.t.fromTranslationRotation((0,0,0),self.model_orientation)253 254 if self._mode == "gazebo":255 R_qr = self.t.fromTranslationRotation((0,0,0),self.gazebo_model_orientation)256 257 # Ricostruisco la rotazione del frame immagine dall'orientamento del qr 258 if self._mode == "qr": 259 260 # Le matrici di rotazione R_1 e R_2 sono state trovate sperimentalmente.261 # Vale la relazione R_1 * R(qr_orientation) * R_2 = R(yaw) 262 # TODO: Inizialmente si puo stimare la R_2 da: R_1 * R(qr_orientation) * R_2 = I (il yaw iniziale e sempre 0). 263 # In questo modo si rende dinamico l'algoritmo rispetto all'orientamento dei qr.264 265 R_1 = np.array([[0,0,1,0],[1,0,0,0],[0,1,0,0],[0,0,0,1]])266 R_2 = np.array([[1,0,0,0],[0,0,-1,0],[0,1,0,0],[0,0,0,1]]) 267 268 R_qr_orient = self.t.fromTranslationRotation((0,0,0),qr_orient)269 _R_qr = tf.transformations.concatenate_matrices(R_1, R_qr_orient, R_2)270 271 # Normalizzo la R_qr considerando una rotazione elementare sull'asse Z.272 R_qr = self._yaw_rotation_normalization(_R_qr)273 274 return R_qr275 276 def _left_hand_to_right_hand_frame (self, T):277 278 T_inv = np.linalg.inv(T)279 T_left = self.t.fromTranslationRotation(self.qr_pos[0:3].T,self.qr_orientation)280 T_right = tf.transformations.concatenate_matrices(T, T_left, T_inv) 281 282 pos = tf.transformations.translation_from_matrix(T_right)283 quat = tf.transformations.quaternion_from_matrix(T_right)284 return (np.append(pos,[1]), quat)285 286 def _yaw_rotation_normalization (self, R):287 288 roll, pitch, yaw = tf.transformations.euler_from_matrix(R)289 R_norm = tf.transformations.euler_matrix(0,0,yaw)290 291 return R_norm292 293#################################################################################################################################################294if __name__ == "__main__":295 rospy.init_node('qr_reader')296 297 # Check for mode param298 if rospy.has_param('~mode'):299 mode = rospy.get_param('~mode')300 obj = QR_Reader(mode) 301 else:302 obj = QR_Reader()303 304 rate = rospy.Rate(10) 305 rospy.sleep(0.5)306 307 try:308 while not rospy.is_shutdown():309 310 result = obj.get_pose()311 312 if result:313 T = obj.pose314 obj.publish(T)315 316 rate.sleep() 317 318 except rospy.exceptions.ROSInterruptException:319 pass...
Sensor_QR.py
Source:Sensor_QR.py
1# -*- coding: utf-8 -*-2import serial3import os, time4import commands5import lib.Control_Archivos as Ca6from serial import SerialException7import RPi.GPIO as GPIO #Libreria Python GPIO8GPIO.setmode (GPIO.BOARD)9 #chicharra10CC_Pin = 3111GPIO.setup(CC_Pin, GPIO.OUT)12GPIO.output(CC_Pin, GPIO.HIGH)13Leer = Ca.Leer_Led14Borrar = Ca.Borrar_Archivo15Escrivir_Estados = Ca.Escrivir_Estados16Escrivir = Ca.Escrivir_Archivo17Leer_Estado = Ca.Leer_Estado18# Enable Serial Communication19#res = commands.getoutput('ls /dev/ttyACM*')20Puerto_Serial = '/dev/ttyS0'21print Puerto_Serial22port = serial.Serial(Puerto_Serial, baudrate=9600, timeout=1)23#port = serial.Serial(Puerto_Serial, baudrate=57600, timeout=1)24"""25port =026while True:27 #res = commands.getoutput('ls /dev/ttyACM*')28 res = commands.getoutput('/dev/ttyS0')29 print res#.find("/dev/ttyACM*")30 if res.find("/dev/ttyACM*") == -1:31 print 'abrir puerto'32 #port.close()33 port = serial.Serial(res, baudrate=9600, timeout=1)34 break35"""36#port = serial.Serial(res, baudrate=9600, timeout=1)37#port = serial.Serial("/dev/ttyACM0", baudrate=9600, timeout=1)38#port.write('Inofrmacion serial'+'\n\r')39Eliminar_antes=040N_Cade=041C_armar=''42QR =''43QR_antes =''44Tinicio =045Tfin =046Tdiferencia =047TRepeticion = 248#---------------------49def Log_QR():50 Contador = str(int(Leer_Estado(12))+1)51 print 'Log QR: '+ Contador52 Borrar(12) # Borrar QR53 Escrivir(Contador,12) # Guardar QR54def Leer_datos_SensorQR():55 global Eliminar_antes56 global N_Cade57 global C_armar58 global QR59 global QR_antes60 global B_sensor61 global Tinicio62 global Tfin63 global Tdiferencia64 global TRepeticion65 global port66 global res67 while True:68 try :69 #-------------------------------70 #Para dispotitos CCCB71 #-------------------------------72 rele = Leer_Estado(38)73 if len(rele)>= 1:74 print rele75 port.write(rele)76 Borrar(38)77 #-------------------------------78 rcv = port.read(250)79 #-----------------------------------------80 # Analisis de Cadenas recojidas81 #-----------------------------------------82 T_rcv = len(rcv)83 #print T_rcv84 if T_rcv >= 1:85 QRT = rcv.split('\r')86 #print QRT87 for x in QRT:88 #print 'x Procesando: '+x89 N_Cade +=190 TaCadena = len (x)91 Inicio = x[0:1]92 Fin = x[TaCadena-1:TaCadena]93 if (Inicio == '<' ) and (Fin == '>'):94 N_Cade=095 C_armar=''96 QR = x97 if QR != QR_antes:98 #print 'OK QR: '+QR99 #-----------------------------------------100 Tfin = time.time()101 Tdiferencia = Tfin - Tinicio102 if Tdiferencia >= TRepeticion:103 print 'Procesar:'+QR + ' T_Diferencia:'+ str(Tdiferencia)104 QR_antes = QR105 QR = QR.replace ("<","")106 QR = QR.replace (">","")107 #Log_QR()108 Borrar(7) # Borrar QR109 Escrivir(QR,7) # Guardar QR110 Escrivir_Estados('1',8) # Cambiar estado del QR111 B_sensor = 2112 Tinicio = time.time()113 #-----------------------------------------114 else:115 #Log_QR()116 # si la foma es la del tiiqued proceesar denuevo117 puntos = QR.count(".")118 print puntos119 if puntos == 3:120 Escrivir_Estados('1',8) # Cambiar estado del QR121 else:122 Escrivir_Estados('2',11) # Estado QR repetido123 print 'QR YA: ' +QR124 else:125 C_armar=C_armar + x126 if (C_armar[0:1] == '<' ) and (C_armar[len (C_armar)-1:len (C_armar)] == '>'):127 QR = C_armar128 if QR != QR_antes:129 #print 'OK QR: '+QR130 #-----------------------------------------131 Tfin = time.time()132 Tdiferencia = Tfin - Tinicio133 if Tdiferencia >= TRepeticion:134 print 'Procesar:'+QR + ' T_Diferencia:'+ str(Tdiferencia)135 QR_antes = QR136 QR = QR.replace ("<","")137 QR = QR.replace (">","")138 #Log_QR()139 Borrar(7) # Borrar QR140 Escrivir(QR,7) # Guardar QR141 Escrivir_Estados('1',8) # Cambiar estado del QR142 B_sensor = 2143 Tinicio = time.time()144 #-----------------------------------------145 else:146 #Log_QR()147 puntos = QR.count(".")148 print puntos149 if puntos == 3:150 Escrivir_Estados('1',8) # Cambiar estado del QR151 else:152 Escrivir_Estados('2',11) # Estado QR repetido153 print 'QR YA: ' +QR154 N_Cade=0155 C_armar=''156 else:157 if len(x) >=2:158 if (Inicio == '<' ) or (Fin == '>'):159 a=0160 #print 'pertenese a un qr valido'161 else:162 print 'NO cumple parametros'163 print 'X: '+x164 QR = x165 if QR != QR_antes:166 #print 'X QR: '+QR167 QR_antes = QR168 print 'que pasa'169 if QR.find("Igual") != -1:170 """171 aqr = Leer_Estado(7) #QR172 aqr= aqr.strip()173 puntos = aqr.count(".")174 print puntos175 if puntos == 3:176 Escrivir_Estados('1',8) # Cambiar estado del QR177 else:178 Escrivir_Estados('2',11) # Estado QR repetido179 print 'QR YA: ' +QR180 """181 Escrivir_Estados('2',11) # Estado QR repetido182 print "Repetido"183 else:184 #Log_QR()185 Borrar(7) # Borrar QR186 Escrivir(QR,7) # Guardar QR187 Escrivir_Estados('1',8) # Cambiar estado del QR188 B_sensor = 2189 else:190 if QR.find("Igual") != -1:191 Escrivir_Estados('2',11) # Estado QR repetido192 print 'QR YA: ' +QR193 """194 aqr = Leer_Estado(7) #QR195 aqr= aqr.strip()196 puntos = aqr.count(".")197 print puntos198 if puntos == 3:199 Escrivir_Estados('1',8) # Cambiar estado del QR200 """201 else :202 Escrivir_Estados('2',11) # Estado QR repetido203 print 'QR YA: ' +QR204 205 print 'mmm'206 #----------------------------------207 # fin del for208 N_Cade = 0209 else:210 # Descartar por tiempo espirado211 Eliminar_antes +=1212 if Eliminar_antes >=5:213 #print 'Borado de cadenas y puesta en zero'214 Eliminar_antes=0215 N_Cade=0216 C_armar=''217 B_sensor = 0218 #print 'salida del while'219 break220 except SerialException:221 print 'algo paso'222 #port.close()223 while True:224 port = serial.Serial(Puerto_Serial, baudrate=9600, timeout=1)225 break226 """227 res = commands.getoutput('ls /dev/ttyACM*')228 print res#.find("/dev/ttyACM*")229 if res.find("/dev/ttyACM*") == -1:230 print 'abrir puerto'231 port.close()232 port = serial.Serial(res, baudrate=9600, timeout=1)233 break234 """235 #res=res.replace('"',"")236 #res=res.replace('\n',"")237 #redes =res.split("ESSID:")238 #---------------------------------------239 # fin de analisis de cadena240 #---------------------------------------241#---------------------242C_Sensor_IR_en_UNO = 0243B_sensor=0244Estado_Antes=0245GPIO.output(CC_Pin, GPIO.LOW)246while 1:...
tests.py
Source:tests.py
1import six2import qrcode3import qrcode.util4import qrcode.image.svg5try:6 import qrcode.image.pure7 import pymaging_png # ensure that PNG support is installed8except ImportError:9 pymaging_png = None10from qrcode.exceptions import DataOverflowError11from qrcode.util import (12 MODE_NUMBER, MODE_ALPHA_NUM, MODE_8BIT_BYTE)13try:14 import unittest2 as unittest15except ImportError:16 import unittest17UNICODE_TEXT = u'\u03b1\u03b2\u03b3'18class QRCodeTests(unittest.TestCase):19 def test_basic(self):20 qr = qrcode.QRCode(version=1)21 qr.add_data('a')22 qr.make(fit=False)23 def test_overflow(self):24 qr = qrcode.QRCode(version=1)25 qr.add_data('abcdefghijklmno')26 self.assertRaises(DataOverflowError, qr.make, fit=False)27 def test_fit(self):28 qr = qrcode.QRCode()29 qr.add_data('a')30 qr.make()31 self.assertEqual(qr.version, 1)32 qr.add_data('bcdefghijklmno')33 qr.make()34 self.assertEqual(qr.version, 2)35 def test_mode_number(self):36 qr = qrcode.QRCode()37 qr.add_data('1234567890123456789012345678901234', optimize=0)38 qr.make()39 self.assertEqual(qr.version, 1)40 self.assertEqual(qr.data_list[0].mode, MODE_NUMBER)41 def test_mode_alpha(self):42 qr = qrcode.QRCode()43 qr.add_data('ABCDEFGHIJ1234567890', optimize=0)44 qr.make()45 self.assertEqual(qr.version, 1)46 self.assertEqual(qr.data_list[0].mode, MODE_ALPHA_NUM)47 def test_regression_mode_comma(self):48 qr = qrcode.QRCode()49 qr.add_data(',', optimize=0)50 qr.make()51 self.assertEqual(qr.data_list[0].mode, MODE_8BIT_BYTE)52 def test_mode_8bit(self):53 qr = qrcode.QRCode()54 qr.add_data(u'abcABC' + UNICODE_TEXT, optimize=0)55 qr.make()56 self.assertEqual(qr.version, 1)57 self.assertEqual(qr.data_list[0].mode, MODE_8BIT_BYTE)58 def test_mode_8bit_newline(self):59 qr = qrcode.QRCode()60 qr.add_data('ABCDEFGHIJ1234567890\n', optimize=0)61 qr.make()62 self.assertEqual(qr.data_list[0].mode, MODE_8BIT_BYTE)63 def test_render_svg(self):64 qr = qrcode.QRCode()65 qr.add_data(UNICODE_TEXT)66 img = qr.make_image(image_factory=qrcode.image.svg.SvgImage)67 img.save(six.BytesIO())68 def test_render_svg_path(self):69 qr = qrcode.QRCode()70 qr.add_data(UNICODE_TEXT)71 img = qr.make_image(image_factory=qrcode.image.svg.SvgPathImage)72 img.save(six.BytesIO())73 @unittest.skipIf(not pymaging_png, "Requires pymaging with PNG support")74 def test_render_pymaging_png(self):75 qr = qrcode.QRCode()76 qr.add_data(UNICODE_TEXT)77 img = qr.make_image(image_factory=qrcode.image.pure.PymagingImage)78 img.save(six.BytesIO())79 def test_optimize(self):80 qr = qrcode.QRCode()81 text = 'A1abc12345def1HELLOa'82 qr.add_data(text, optimize=4)83 qr.make()84 self.assertEqual(len(qr.data_list), 5)85 self.assertEqual(qr.data_list[0].mode, MODE_8BIT_BYTE)86 self.assertEqual(qr.data_list[1].mode, MODE_NUMBER)87 self.assertEqual(qr.data_list[2].mode, MODE_8BIT_BYTE)88 self.assertEqual(qr.data_list[3].mode, MODE_ALPHA_NUM)89 self.assertEqual(qr.data_list[4].mode, MODE_8BIT_BYTE)90 self.assertEqual(qr.version, 2)91 def test_optimize_size(self):92 text = 'A1abc12345123451234512345def1HELLOHELLOHELLOHELLOa' * 593 qr = qrcode.QRCode()94 qr.add_data(text)95 qr.make()96 self.assertEqual(qr.version, 10)97 qr = qrcode.QRCode()98 qr.add_data(text, optimize=0)99 qr.make()100 self.assertEqual(qr.version, 11)101 def test_qrdata_repr(self):102 data = b'hello'103 data_obj = qrcode.util.QRData(data)...
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!!