Best Python code snippet using ATX
eventos - copia.py
Source:eventos - copia.py
...85 i = actual - tiempo86 #el programa funciona por milisegundos, osea entrara al while 100 veces mientras el tiempo solo aumentara de 0 a 3087 if selec_nom == "mago_old":88 if i == 14: 89 player_pj.handle_event(0)90 player_enemigo.handle_event(0)91 magia.handle_event(14)92 atacar(selec, enemigo, player_pj, imagen_player, player_enemigo, imagen_enemigo, turno)93 salir = False94 elif i < 7:95 player_pj.handle_event(i)96 player_enemigo.handle_event(0)97 i += 198 elif i < 13 and i > 7:99 magia.handle_event(13)100 player_pj.handle_event(i)101 player_enemigo.handle_event(0)102 pantalla.blit(magia.parte,magia.rect)103 i += 1104 105 elif selec_nom == "megaman":106 if i == 17: 107 bala.handle_event(17)108 player_pj.handle_event(0)109 atacar(selec, enemigo, player_pj, imagen_player, player_enemigo, imagen_enemigo, turno)110 salir = False111 elif i < 7:112 player_enemigo.handle_event(0)113 player_pj.handle_event(i)114 i += 1 115 elif i < 17 and i > 6:116 bala.handle_event(i)117 player_pj.handle_event(0)118 pantalla.blit(bala.parte,bala.rect)119 i += 1120 else:121 if i == cant_animaciones: 122 player_pj.handle_event(0)123 player_enemigo.handle_event(0)124 atacar(selec, enemigo, player_pj, imagen_player, player_enemigo, imagen_enemigo, turno)125 salir = False 126 elif i < cant_animaciones:127 player_pj.handle_event(i)128 player_enemigo.handle_event(0)129 i += 1130 #menu_stats131 pantalla.blit(barra1,(180,500))132 pantalla.blit(imagen_player,(70,435))133 pantalla.blit(barra2,(730,130))134 pantalla.blit(imagen_enemigo,(610,60))135 pantalla.blit(player_enemigo.parte,player_enemigo.rect)136 pantalla.blit(player_pj.parte,player_pj.rect)137 cargar_barras(selec, enemigo)138 game.display.update()139 140 if not menuC.validar_vida(enemigo):141 salir = True142 tiempo = game.time.get_ticks()/vel_enemigo143 while salir == True:144 pantalla.blit(fondo,(0,0))145 actual = game.time.get_ticks()/vel_enemigo146 i = actual - tiempo147 if i == cant_animaciones_enemigo: 148 player_pj.handle_event(0)149 player_enemigo.handle_event(0)150 atacar_boss(selec, enemigo, player_pj, imagen_player, player_enemigo, imagen_enemigo, turno)151 salir = False 152 elif i < cant_animaciones_enemigo:153 player_pj.handle_event(0)154 player_enemigo.handle_event(i)155 i += 1156 #menu_stats157 pantalla.blit(barra1,(180,500))158 pantalla.blit(imagen_player,(70,435))159 pantalla.blit(barra2,(730,130))160 pantalla.blit(imagen_enemigo,(610,60))161 pantalla.blit(player_enemigo.parte,player_enemigo.rect)162 pantalla.blit(player_pj.parte,player_pj.rect)163 cargar_barras(selec, enemigo)164 game.display.update()165 if turno == 2:166 if not menuC.validar_vida(enemigo):167 salir = True168 tiempo = game.time.get_ticks()/vel_enemigo169 while salir == True:170 pantalla.blit(fondo,(0,0))171 actual = game.time.get_ticks()/vel_enemigo172 i = actual - tiempo173 if i == cant_animaciones_enemigo: 174 player_pj.handle_event(0)175 player_enemigo.handle_event(0)176 atacar_boss(selec, enemigo, player_pj, imagen_player, player_enemigo, imagen_enemigo, turno)177 salir = False 178 elif i < cant_animaciones_enemigo:179 player_pj.handle_event(0)180 player_enemigo.handle_event(i)181 i += 1182 #menu_stats183 pantalla.blit(barra1,(180,500))184 pantalla.blit(imagen_player,(70,435))185 pantalla.blit(barra2,(730,130))186 pantalla.blit(imagen_enemigo,(610,60))187 pantalla.blit(player_enemigo.parte,player_enemigo.rect)188 pantalla.blit(player_pj.parte,player_pj.rect)189 cargar_barras(selec, enemigo)190 game.display.update()191 192 if not menuC.validar_vida(selec):193 salir = True194 tiempo = game.time.get_ticks()/vel_pj195 while salir == True:196 pantalla.blit(fondo,(0,0))197 actual = game.time.get_ticks()/vel_pj198 i = actual - tiempo199 #el programa funciona por milisegundos, osea entrara al while 100 veces mientras el tiempo solo aumentara de 0 a 30200 if selec_nom == "mago_old":201 if i == 14: 202 player_pj.handle_event(0)203 player_enemigo.handle_event(0)204 magia.handle_event(14)205 atacar(selec, enemigo, player_pj, imagen_player, player_enemigo, imagen_enemigo, turno)206 salir = False207 elif i < 7:208 player_pj.handle_event(i)209 player_enemigo.handle_event(0)210 i += 1211 elif i < 13 and i > 7:212 magia.handle_event(13)213 player_pj.handle_event(i)214 player_enemigo.handle_event(0)215 pantalla.blit(magia.parte,magia.rect)216 i += 1217 218 elif selec_nom == "megaman":219 if i == 17: 220 bala.handle_event(17)221 player_pj.handle_event(0)222 atacar(selec, enemigo, player_pj, imagen_player, player_enemigo, imagen_enemigo, turno)223 salir = False224 elif i < 7:225 player_enemigo.handle_event(0)226 player_pj.handle_event(i)227 i += 1 228 elif i < 17 and i > 6:229 bala.handle_event(i)230 player_pj.handle_event(0)231 pantalla.blit(bala.parte,bala.rect)232 i += 1233 else:234 if i == cant_animaciones: 235 player_pj.handle_event(0)236 player_enemigo.handle_event(0)237 atacar(selec, enemigo, player_pj, imagen_player, player_enemigo, imagen_enemigo, turno)238 salir = False 239 elif i < cant_animaciones:240 player_pj.handle_event(i)241 player_enemigo.handle_event(0)242 i += 1243 #menu_stats244 pantalla.blit(barra1,(180,500))245 pantalla.blit(imagen_player,(70,435))246 pantalla.blit(barra2,(730,130))247 pantalla.blit(imagen_enemigo,(610,60))248 pantalla.blit(player_enemigo.parte,player_enemigo.rect)249 pantalla.blit(player_pj.parte,player_pj.rect)250 cargar_barras(selec, enemigo)251 game.display.update()252def cargar_barras(selec, enemigo):253 vida_max = menuC.estado.vida_max[selec]254 vida = menuC.estado.vida[selec]255 color = pintar(vida_max,vida)...
state_machine_test.py
Source:state_machine_test.py
...14 # IDLE STATE15 #16 def testIdle_StartPatrol(self):17 sm = StateMachine()18 sm.handle_event(Event.START_PATROL)19 self.assertEqual(sm.get_state(), State.PATROLLING, "IDLE + START_PATROL -> PATROLLING is valid")20 def testIdle_ArrivedAtMolehill(self):21 sm = StateMachine()22 with self.assertRaises(InvalidEventException, msg="IDLE + ARRIVED_AT_MOLEHILL is not valid"):23 sm.handle_event(Event.ARRIVED_AT_MOLEHILL)24 def testIdle_DoneScaring(self):25 sm = StateMachine()26 with self.assertRaises(InvalidEventException, msg="IDLE + DONE_SCARING is not valid"):27 sm.handle_event(Event.DONE_SCARING)28 def testIdle_LowBattery(self):29 sm = StateMachine()30 sm.handle_event(Event.LOW_BATTERY)31 self.assertEqual(sm.get_state(), State.RETURNING_TO_BASE, "IDLE + LOW_BATTERY -> RETURNING_TO_BASE is valid")32 def testIdle_FullyCharged(self):33 sm = StateMachine()34 with self.assertRaises(InvalidEventException, msg="IDLE + FULLY_CHARGED is not valid"):35 sm.handle_event(Event.FULLY_CHARGED)36 def testIdle_ArrivedAtBase(self):37 sm = StateMachine()38 with self.assertRaises(InvalidEventException, msg = "IDLE + ARRIVED_AT_BASE is not valid"):39 sm.handle_event(Event.ARRIVED_AT_BASE)40 def testIdle_ScanningTime(self):41 sm = StateMachine()42 with self.assertRaises(InvalidEventException, msg = "IDLE + SCANNING_TIME is not valid"):43 sm.handle_event(Event.SCANNING_TIME)44 def testIdle_DoneScanning(self):45 sm = StateMachine()46 with self.assertRaises(InvalidEventException, msg = "IDLE + DONE_SCANNING is not valid"):47 sm.handle_event(Event.DONE_SCANNING)48 def testIdle_DonePatrolling(self):49 sm = StateMachine()50 with self.assertRaises(InvalidEventException, msg = "IDLE + DONE_PATROLLING is not valid"):51 sm.handle_event(Event.DONE_PATROLLING)52 #53 # PATROLLING54 #55 def testPatrolling_StartPatrol(self):56 sm = StateMachine()57 sm.handle_event(Event.START_PATROL)58 with self.assertRaises(InvalidEventException, msg = "PATROLLING + START_PATROL is not valid"):59 sm.handle_event(Event.START_PATROL)60 def testPatrolling_ArrivedAtMolehill(self):61 sm = StateMachine()62 sm.handle_event(Event.START_PATROL)63 sm.handle_event(Event.ARRIVED_AT_MOLEHILL)64 self.assertEqual(sm.get_state(), State.SCARING, "PATROLLING + ARRIVED_AT_MOLEHILL -> SCARING is valid")65 def testPatrolling_DoneScaring(self):66 sm = StateMachine()67 sm.handle_event(Event.START_PATROL)68 with self.assertRaises(InvalidEventException, msg = "PATROLLING + DONE_SCARING is not valid"):69 sm.handle_event( Event.DONE_SCARING)70 def testPatrolling_LowBattery(self):71 sm = StateMachine()72 sm.handle_event(Event.START_PATROL)73 sm.handle_event(Event.LOW_BATTERY)74 self.assertEqual(sm.get_state(), State.RETURNING_TO_BASE, "PATROLLING + LOW_BATTERY -> RETURNING_TO_BASE is valid")75 def testPatrolling_FullyCharged(self):76 sm = StateMachine()77 sm.handle_event(Event.START_PATROL)78 with self.assertRaises(InvalidEventException, msg = "PATROLLING + FULLY_CHARGED is not valid"):79 sm.handle_event(Event.FULLY_CHARGED)80 def testPatrolling_ArrivedAtBase(self):81 sm = StateMachine()82 sm.handle_event(Event.START_PATROL)83 with self.assertRaises(InvalidEventException, msg = "PATROLLING + ARRIVED_AT_BASE is not valid"):84 sm.handle_event(Event.ARRIVED_AT_BASE)85 def testPatrolling_ScanningTime(self):86 sm = StateMachine()87 sm.handle_event(Event.START_PATROL)88 sm.handle_event(Event.SCANNING_TIME)89 self.assertEqual(sm.get_state(), State.SCANNING, "PATROLLING + SCANNING_TIME -> SCANNING is valid")90 def testPatrolling_DoneScanning(self):91 sm = StateMachine()92 sm.handle_event(Event.START_PATROL)93 with self.assertRaises(InvalidEventException, msg = "PATROLLING + DONE_SCANNING is not valid"):94 sm.handle_event(Event.DONE_SCANNING)95 def testPatrolling_DonePatrolling(self):96 sm = StateMachine()97 sm.handle_event(Event.START_PATROL)98 sm.handle_event(Event.DONE_PATROLLING)99 self.assertEqual(sm.get_state(), State.IDLE, "PATROLLING + DONE_PATROLLING -> IDLE is valid")100 #101 # RETURNING TO BASE102 #103 def testReturningToBase_StartPatrol(self):104 sm = StateMachine()105 sm.handle_event(Event.LOW_BATTERY)106 with self.assertRaises(InvalidEventException, msg = "RETURNING_TO_BASE + START_PATROL is invalid"):107 sm.handle_event(Event.START_PATROL)108 def testReturningToBase_ArrivedAtMolehill(self):109 sm = StateMachine()110 sm.handle_event(Event.LOW_BATTERY)111 with self.assertRaises(InvalidEventException, msg = "RETURNING_TO_BASE + LOW_BATTERY is invalid"):112 sm.handle_event(Event.ARRIVED_AT_MOLEHILL)113 def testReturningToBase_DoneScaring(self):114 sm = StateMachine()115 sm.handle_event(Event.LOW_BATTERY)116 with self.assertRaises(InvalidEventException, msg = "RETURNING_TO_BASE + DONE_SCARING is invalid"):117 sm.handle_event(Event.DONE_SCARING)118 def testReturningToBase_LowBattery(self):119 sm = StateMachine()120 sm.handle_event(Event.LOW_BATTERY)121 with self.assertRaises(InvalidEventException, msg = "RETURNING_TO_BASE + LOW_BATTERY is invalid"):122 sm.handle_event(Event.LOW_BATTERY)123 def testReturningToBase_FullyCharged(self):124 sm = StateMachine()125 sm.handle_event(Event.LOW_BATTERY)126 with self.assertRaises(InvalidEventException, msg = "RETURNING_TO_BASE + FULLY_CHARGED is invalid"):127 sm.handle_event(Event.FULLY_CHARGED)128 def testReturningToBase_ArrivedAtBase(self):129 sm = StateMachine()130 sm.handle_event(Event.LOW_BATTERY)131 sm.handle_event(Event.ARRIVED_AT_BASE)132 self.assertEqual(sm.get_state(), State.CHARGING, "RETURNING_TO_BASE + ARRIVED_AT_BASE -> CHARGING is valid")133 def testReturningToBase_ScanningTime(self):134 sm = StateMachine()135 sm.handle_event(Event.LOW_BATTERY)136 with self.assertRaises(InvalidEventException, msg = "RETURNING_TO_BASE + SCANNING_TIME is invalid"):137 sm.handle_event(Event.SCANNING_TIME)138 def testReturningToBase_DoneScanning(self):139 sm = StateMachine()140 sm.handle_event(Event.LOW_BATTERY)141 with self.assertRaises(InvalidEventException, msg = "RETURNING_TO_BASE + DONE_SCANNING is invalid"):142 sm.handle_event(Event.DONE_SCANNING)143 def testReturningToBase_DonePatrolling(self):144 sm = StateMachine()145 sm.handle_event(Event.LOW_BATTERY)146 with self.assertRaises(InvalidEventException, msg = "RETURNING_TO_BASE + DONE_PATROLLING is invalid"):147 sm.handle_event(Event.DONE_PATROLLING)148 #149 # CHARGING150 #151 def testCharging_StartPatrol(self):152 sm = StateMachine()153 sm.handle_event(Event.LOW_BATTERY)154 sm.handle_event(Event.ARRIVED_AT_BASE)155 with self.assertRaises(InvalidEventException, msg = "CHARGING + START_PATROL is invalid"):156 sm.handle_event(Event.START_PATROL)157 def testCharging_ArrivedAtMolehill(self):158 sm = StateMachine()159 sm.handle_event(Event.LOW_BATTERY)160 sm.handle_event(Event.ARRIVED_AT_BASE)161 with self.assertRaises(InvalidEventException, msg = "RETURNING_TO_BASE + ARRIVED_AT_MOLEHILL is invalid"):162 sm.handle_event(Event.ARRIVED_AT_MOLEHILL)163 def testCharging_DoneScaring(self):164 sm = StateMachine()165 sm.handle_event(Event.LOW_BATTERY)166 sm.handle_event(Event.ARRIVED_AT_BASE)167 with self.assertRaises(InvalidEventException, msg = "RETURNING_TO_BASE + DONE_SCARING is invalid"):168 sm.handle_event(Event.DONE_SCARING)169 def testCharging_LowBattery(self):170 sm = StateMachine()171 sm.handle_event(Event.LOW_BATTERY)172 sm.handle_event(Event.ARRIVED_AT_BASE)173 with self.assertRaises(InvalidEventException, msg = "RETURNING_TO_BASE + LOW_BATTERY is invalid"):174 sm.handle_event(Event.LOW_BATTERY)175 def testCharging_FullyCharged(self):176 sm = StateMachine()177 sm.handle_event(Event.LOW_BATTERY)178 sm.handle_event(Event.ARRIVED_AT_BASE)179 sm.handle_event(Event.FULLY_CHARGED)180 self.assertEqual(sm.get_state(), State.IDLE, "RETURNING_TO_BASE + FULLY_CHARGED -> IDLE is valid")181 def testCharging_ArrivedAtBase(self):182 sm = StateMachine()183 sm.handle_event(Event.LOW_BATTERY)184 sm.handle_event(Event.ARRIVED_AT_BASE)185 with self.assertRaises(InvalidEventException, msg = "RETURNING_TO_BASE + ARRIVED_AT_BASE is invalid"):186 sm.handle_event(Event.ARRIVED_AT_BASE)187 def testCharging_ScanningTime(self):188 sm = StateMachine()189 sm.handle_event(Event.LOW_BATTERY)190 sm.handle_event(Event.ARRIVED_AT_BASE)191 with self.assertRaises(InvalidEventException, msg = "RETURNING_TO_BASE + SCANNING_TIME is invalid"):192 sm.handle_event(Event.SCANNING_TIME)193 def testCharging_DoneScanning(self):194 sm = StateMachine()195 sm.handle_event(Event.LOW_BATTERY)196 sm.handle_event(Event.ARRIVED_AT_BASE)197 with self.assertRaises(InvalidEventException, msg = "RETURNING_TO_BASE + DONE_SCANNING is invalid"):198 sm.handle_event(Event.DONE_SCANNING)199 def testCharging_DonePatrolling(self):200 sm = StateMachine()201 sm.handle_event(Event.LOW_BATTERY)202 sm.handle_event(Event.ARRIVED_AT_BASE)203 with self.assertRaises(InvalidEventException, msg = "RETURNING_TO_BASE + DONE_PATROLLING is invalid"):204 sm.handle_event(Event.DONE_PATROLLING)205 #206 # SCARING207 #208 def testScaring_StartPatrol(self):209 sm = StateMachine()210 sm.handle_event(Event.START_PATROL)211 sm.handle_event(Event.ARRIVED_AT_MOLEHILL)212 with self.assertRaises(InvalidEventException, msg = "SCARING + START_PATROL is invalid"):213 sm.handle_event(Event.START_PATROL)214 def testScaring_ArrivedAtMolehill(self):215 sm = StateMachine()216 sm.handle_event(Event.START_PATROL)217 sm.handle_event(Event.ARRIVED_AT_MOLEHILL)218 with self.assertRaises(InvalidEventException, msg = "SCARING + is invalid"):219 sm.handle_event(Event.ARRIVED_AT_MOLEHILL)220 def testScaring_DoneScaring(self):221 sm = StateMachine()222 sm.handle_event(Event.START_PATROL)223 sm.handle_event(Event.ARRIVED_AT_MOLEHILL)224 sm.handle_event(Event.DONE_SCARING)225 self.assertEqual(sm.get_state(), State.PATROLLING, "SCARING + DONE_SCARING -> PATROLLING is valid")226 def testScaring_LowBattery(self):227 sm = StateMachine()228 sm.handle_event(Event.START_PATROL)229 sm.handle_event(Event.ARRIVED_AT_MOLEHILL)230 sm.handle_event(Event.LOW_BATTERY)231 self.assertEqual(sm.get_state(), State.PATROLLING, "SCARING + LOW_BATTERY -> PATROLLING is valid")232 def testScaring_FullyCharged(self):233 sm = StateMachine()234 sm.handle_event(Event.START_PATROL)235 sm.handle_event(Event.ARRIVED_AT_MOLEHILL)236 with self.assertRaises(InvalidEventException, msg = "SCARING + FULLY_CHARGED is invalid"):237 sm.handle_event(Event.FULLY_CHARGED)238 def testScaring_ArrivedAtBase(self):239 sm = StateMachine()240 sm.handle_event(Event.START_PATROL)241 sm.handle_event(Event.ARRIVED_AT_MOLEHILL)242 with self.assertRaises(InvalidEventException, msg = "SCARING + ARRIVED_AT_BASE is invalid"):243 sm.handle_event(Event.ARRIVED_AT_BASE)244 def testScaring_ScanningTime(self):245 sm = StateMachine()246 sm.handle_event(Event.START_PATROL)247 sm.handle_event(Event.ARRIVED_AT_MOLEHILL)248 with self.assertRaises(InvalidEventException, msg = "SCARING + SCANNING_TIME is invalid"):249 sm.handle_event(Event.SCANNING_TIME)250 def testScaring_DoneScanning(self):251 sm = StateMachine()252 sm.handle_event(Event.START_PATROL)253 sm.handle_event(Event.ARRIVED_AT_MOLEHILL)254 with self.assertRaises(InvalidEventException, msg = "SCARING + DONE_SCANNING is invalid"):255 sm.handle_event(Event.DONE_SCANNING)256 #257 # SCANNING258 #259 def testScanning_StartPatrol(self):260 sm = StateMachine()261 sm.handle_event(Event.START_PATROL)262 sm.handle_event(Event.SCANNING_TIME)263 with self.assertRaises(InvalidEventException, msg = "SCANNING + START_PATROL is invalid"):264 sm.handle_event(Event.START_PATROL)265 def testScanning_ArrivedAtMolehill(self):266 sm = StateMachine()267 sm.handle_event(Event.START_PATROL)268 sm.handle_event(Event.SCANNING_TIME)269 with self.assertRaises(InvalidEventException, msg = "SCANNING + ARRIVED_AT_MOLEHILL is invalid"):270 sm.handle_event(Event.ARRIVED_AT_MOLEHILL)271 def testScanning_DoneScaring(self):272 sm = StateMachine()273 sm.handle_event(Event.START_PATROL)274 sm.handle_event(Event.SCANNING_TIME)275 with self.assertRaises(InvalidEventException, msg = "SCANNING + DONE_SCARING is invalid"):276 sm.handle_event(Event.DONE_SCARING)277 def testScanning_LowBattery(self):278 sm = StateMachine()279 sm.handle_event(Event.START_PATROL)280 sm.handle_event(Event.SCANNING_TIME)281 sm.handle_event(Event.LOW_BATTERY)282 self.assertEqual(sm.get_state(), State.PATROLLING, "SCANNING + LOW_BATTERY PATROLLING is valid")283 def testScanning_FullyCharged(self):284 sm = StateMachine()285 sm.handle_event(Event.START_PATROL)286 sm.handle_event(Event.SCANNING_TIME)287 with self.assertRaises(InvalidEventException, msg = "SCANNING + FULLY_CHARGED is invalid"):288 sm.handle_event(Event.FULLY_CHARGED)289 def testScanning_ArrivedAtBase(self):290 sm = StateMachine()291 sm.handle_event(Event.START_PATROL)292 sm.handle_event(Event.SCANNING_TIME)293 with self.assertRaises(InvalidEventException, msg = "SCANNING + ARRIVED_AT_BASE is invalid"):294 sm.handle_event(Event.ARRIVED_AT_BASE)295 def testScanning_ScanningTime(self):296 sm = StateMachine()297 sm.handle_event(Event.START_PATROL)298 sm.handle_event(Event.SCANNING_TIME)299 with self.assertRaises(InvalidEventException, msg = "SCANNING + SCANNING_TIME is invalid"):300 sm.handle_event(Event.SCANNING_TIME)301 def testScanning_DoneScanning(self):302 sm = StateMachine()303 sm.handle_event(Event.START_PATROL)304 sm.handle_event(Event.SCANNING_TIME)305 sm.handle_event(Event.DONE_SCANNING)306 self.assertEqual(sm.get_state(), State.PATROLLING, "SCANNING + DONE_SCANNING is invalid")307if __name__ == '__main__':...
test_SyntaxRecognizer.py
Source:test_SyntaxRecognizer.py
...10def test_empty_program():11 syntax_recognizer = SyntaxRecognizer(None)12 with io.StringIO() as f:13 with redirect_stdout(f):14 syntax_recognizer.handle_event(('open', 'source.bas'))15 syntax_recognizer.handle_event(('eof', None))16 s = f.getvalue()17 assert_source_matches(s, '''source_filename = "source.bas"18target triple = "x86_64-pc-linux-gnu"19; void @program(i8* %target_label) omitted because it's empty20define dso_local i32 @main() local_unnamed_addr #1 {21 ret i32 022}23''')24def test_minimal_program():25 syntax_recognizer = SyntaxRecognizer(None)26 with io.StringIO() as f:27 with redirect_stdout(f):28 syntax_recognizer.handle_event(('open', 'source.bas'))29 syntax_recognizer.handle_event(('number', '100'))30 syntax_recognizer.handle_event(('identifier', 'return'))31 syntax_recognizer.handle_event(('end_of_line', '\n'))32 syntax_recognizer.handle_event(('eof', None))33 s = f.getvalue()34 assert_source_matches(s, '''source_filename = "source.bas"35target triple = "x86_64-pc-linux-gnu"36define dso_local void @program(i8* %target_label) local_unnamed_addr #0 {37 indirectbr i8* %target_label, [ label %label_100 ]38label_100:39 ret void40}41define dso_local i32 @main() local_unnamed_addr #1 {42 tail call void @program(i8* blockaddress(@program, %label_100)) #043 ret i32 044}45''')46@pytest.mark.xfail(raises=SemanticError)47def test_undefined_label():48 syntax_recognizer = SyntaxRecognizer(None)49 syntax_recognizer.handle_event(('open', 'source.bas'))50 syntax_recognizer.handle_event(('number', '100'))51 syntax_recognizer.handle_event(('identifier', 'goto'))52 syntax_recognizer.handle_event(('number', '200'))53 syntax_recognizer.handle_event(('end_of_line', '\n'))54 syntax_recognizer.handle_event(('eof', None))55@pytest.mark.xfail(raises=SemanticError)56def test_undefined_label_at_gosub():57 syntax_recognizer = SyntaxRecognizer(None)58 syntax_recognizer.handle_event(('open', 'source.bas'))59 syntax_recognizer.handle_event(('number', '100'))60 syntax_recognizer.handle_event(('identifier', 'gosub'))61 syntax_recognizer.handle_event(('number', '200'))62 syntax_recognizer.handle_event(('end_of_line', '\n'))63 syntax_recognizer.handle_event(('eof', None))64@pytest.mark.xfail(raises=SemanticError)65def test_duplicate_label():66 syntax_recognizer = SyntaxRecognizer(None)67 syntax_recognizer.handle_event(('open', 'source.bas'))68 syntax_recognizer.handle_event(('number', '100'))69 syntax_recognizer.handle_event(('identifier', 'return'))70 syntax_recognizer.handle_event(('end_of_line', '\n'))71 syntax_recognizer.handle_event(('number', '100'))72 syntax_recognizer.handle_event(('identifier', 'return'))73 syntax_recognizer.handle_event(('end_of_line', '\n'))74 syntax_recognizer.handle_event(('eof', None))75@pytest.mark.xfail(raises=SemanticError)76def test_duplicate_label():77 syntax_recognizer = SyntaxRecognizer(None)78 syntax_recognizer.handle_event(('open', 'source.bas'))79 syntax_recognizer.handle_event(('number', '100'))80 syntax_recognizer.handle_event(('identifier', 'print'))81 syntax_recognizer.handle_event(('identifier', 'FNX'))82 syntax_recognizer.handle_event(('special', '('))83 syntax_recognizer.handle_event(('variable', 'x'))84 syntax_recognizer.handle_event(('special', ')'))85 syntax_recognizer.handle_event(('end_of_line', '\n'))86 syntax_recognizer.handle_event(('eof', None))87def test_data():88 syntax_recognizer = SyntaxRecognizer(None)89 with io.StringIO() as f:90 with redirect_stdout(f):91 syntax_recognizer.handle_event(('open', 'source.bas'))92 syntax_recognizer.handle_event(('number', '100'))93 syntax_recognizer.handle_event(('identifier', 'data'))94 syntax_recognizer.handle_event(('number', '10'))95 syntax_recognizer.handle_event(('special', ','))96 syntax_recognizer.handle_event(('special', '-'))97 syntax_recognizer.handle_event(('number', '20'))98 syntax_recognizer.handle_event(('special', ','))99 syntax_recognizer.handle_event(('special', '+'))100 syntax_recognizer.handle_event(('number', '30'))101 syntax_recognizer.handle_event(('special', ','))102 syntax_recognizer.handle_event(('number', '3.14e-0'))103 syntax_recognizer.handle_event(('special', ','))104 syntax_recognizer.handle_event(('number', '-.5'))105 syntax_recognizer.handle_event(('end_of_line', '\n'))106 syntax_recognizer.handle_event(('eof', None))107 s = f.getvalue()108 assert_source_matches(s, '''source_filename = "source.bas"109target triple = "x86_64-pc-linux-gnu"110@DATA = private unnamed_addr constant [5 x double] [double 10.0, double -20.0, double 30.0, double 3.14, double -0.5], align 16111@data_index = internal global i32 0, align 4112define dso_local void @program(i8* %target_label) local_unnamed_addr #0 {113 indirectbr i8* %target_label, [ label %label_100 ]114label_100:115 tail call void @exit(i32 0) noreturn #0116 unreachable117}118define dso_local i32 @main() local_unnamed_addr #1 {119 tail call void @program(i8* blockaddress(@program, %label_100)) #0120 ret i32 0...
test_member_event.py
Source:test_member_event.py
...12 'user_uuid': str(pytest.user_uuid),13 'league_uuid': str(pytest.league.uuid),14 'email': pytest.email15 }16 events.Member().handle_event(key=key, data=value)17 members = services.MemberService().find()18 assert members.total == 119 assert members.items[0].user_uuid == pytest.user_uuid20def test_member_display_name_updated_sync(reset_db, pause_notification, seed_league, seed_member,21 seed_member_materialized):22 """23 GIVEN 1 league instance, 1 member instance and 1 member materialized instance in the database24 WHEN directly calling event member handle_event display_name_updated25 THEN event member handle_event display_name_updated updates 1 member_materialized instance in the database26 """27 key = 'display_name_updated'28 value = {29 'uuid': str(pytest.member_uuid),30 'display_name': 'Oogly Boogly',31 }32 events.Member().handle_event(key=key, data=value)33 members = services.MemberMaterializedService().find()34 assert members.total == 135 assert members.items[0].display_name == 'Oogly Boogly'36def test_member_avatar_created_sync(reset_db, pause_notification, seed_league, seed_member,37 seed_member_materialized):38 """39 GIVEN 1 league instance, 1 member instance and 1 member materialized instance in the database40 WHEN directly calling event member handle_event avatar_created41 THEN event member handle_event avatar_created updates 1 member_materialized instance in the database42 """43 key = 'avatar_created'44 value = {45 'member_uuid': str(pytest.member_uuid),46 's3_filename': '123.jpg',47 }48 events.Member().handle_event(key=key, data=value)49 members = services.MemberMaterializedService().find()50 assert members.total == 151 assert members.items[0].avatar == '123.jpg'52def test_member_avatar_deleted_sync():53 """54 GIVEN 1 league instance, 1 member instance and 1 member materialized instance in the database55 WHEN directly calling event member handle_event avatar_deleted56 THEN event member handle_event avatar_deleted updates 1 member_materialized instance in the database57 """58 key = 'avatar_deleted'59 value = {60 'member_uuid': str(pytest.member_uuid),61 's3_filename': '123.jpg',62 }63 events.Member().handle_event(key=key, data=value)64 members = services.MemberMaterializedService().find()65 assert members.total == 166 assert members.items[0].avatar == None67def test_member_country_updated_sync(reset_db, pause_notification, seed_league, seed_member,68 seed_member_materialized):69 """70 GIVEN 1 league instance, 1 member instance and 1 member materialized instance in the database71 WHEN directly calling event member handle_event country_updated72 THEN event member handle_event country_updated updates 1 member_materialized instance in the database73 """74 key = 'country_updated'75 value = {76 'uuid': str(pytest.member_uuid),77 'user_uuid': str(pytest.user_uuid),78 'country': 'US',79 }80 events.Member().handle_event(key=key, data=value)81 members = services.MemberMaterializedService().find()82 assert members.total == 1...
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!!