How to use connect method in Cypress

Best JavaScript code snippet using cypress

genotypes.py

Source:genotypes.py Github

copy

Full Screen

1from collections import namedtuple2Genotype = namedtuple('Genotype', 'normal normal_concat reduce reduce_concat')3PRIMITIVES = [4 'none',5 'max_pool_3x3',6 'avg_pool_3x3',7 'skip_connect',8 'sep_conv_3x3',9 'sep_conv_5x5',10 'dil_conv_3x3',11 'dil_conv_5x5'12]13PDARTS_TS_CIFAR10 = Genotype(14 normal=[('sep_conv_3x3', 0), 15 ('sep_conv_3x3', 1), 16 ('sep_conv_3x3', 0), 17 ('dil_conv_3x3', 2), 18 ('skip_connect', 0), 19 ('dil_conv_3x3', 3), 20 ('skip_connect', 2), 21 ('dil_conv_5x5', 4)], 22 normal_concat=range(2, 6), 23 reduce=[('avg_pool_3x3', 0), 24 ('dil_conv_3x3', 1), 25 ('avg_pool_3x3', 0), 26 ('dil_conv_5x5', 2), 27 ('skip_connect', 0), 28 ('sep_conv_3x3', 3), 29 ('sep_conv_3x3', 0), 30 ('dil_conv_3x3', 2)], 31 reduce_concat=range(2, 6))32PDARTS_TS_CIFAR100 = Genotype(33 normal=[('sep_conv_3x3', 0), 34 ('sep_conv_5x5', 1), 35 ('skip_connect', 0), 36 ('sep_conv_3x3', 1), 37 ('sep_conv_3x3', 0), 38 ('skip_connect', 2), 39 ('sep_conv_3x3', 0), 40 ('sep_conv_3x3', 1)], 41 normal_concat=range(2, 6), 42 reduce=[('dil_conv_3x3', 0), 43 ('avg_pool_3x3', 1), 44 ('dil_conv_3x3', 1), 45 ('sep_conv_5x5', 2), 46 ('sep_conv_5x5', 1), 47 ('sep_conv_5x5', 2), 48 ('avg_pool_3x3', 0), 49 ('dil_conv_5x5', 2)], 50 reduce_concat=range(2, 6))51DARTS_MINUS_TS_CIFAR10_NEW = Genotype(52 normal=[('sep_conv_3x3', 1),53 ('sep_conv_3x3', 0),54 ('sep_conv_3x3', 0),55 ('sep_conv_5x5', 1),56 ('sep_conv_3x3', 0),57 ('skip_connect', 1),58 ('skip_connect', 0),59 ('skip_connect', 1)],60 normal_concat=range(2, 6),61 reduce=[('sep_conv_3x3', 1),62 ('sep_conv_3x3', 0),63 ('skip_connect', 2),64 ('max_pool_3x3', 1),65 ('skip_connect', 2),66 ('skip_connect', 3),67 ('skip_connect', 2),68 ('skip_connect', 3)],69 reduce_concat=range(2, 6))70DARTS_MINUS_TS_CIFAR100_NEW = Genotype(71 normal=[('sep_conv_3x3', 0),72 ('sep_conv_3x3', 1),73 ('sep_conv_3x3', 0),74 ('skip_connect', 1),75 ('dil_conv_5x5', 0),76 ('skip_connect', 1),77 ('skip_connect', 0),78 ('skip_connect', 1)],79 normal_concat=range(2, 6),80 reduce=[('sep_conv_3x3', 0),81 ('sep_conv_5x5', 1),82 ('skip_connect', 2),83 ('avg_pool_3x3', 1),84 ('skip_connect', 2),85 ('skip_connect', 3),86 ('skip_connect', 2),87 ('skip_connect', 3)],88 reduce_concat=range(2, 6))89DARTS_MINUS_CIFAR10 = Genotype(90 normal=[('sep_conv_3x3', 0),91 ('sep_conv_3x3', 1),92 ('sep_conv_3x3', 0),93 ('skip_connect', 1),94 ('skip_connect', 0),95 ('skip_connect', 1),96 ('skip_connect', 1),97 ('skip_connect', 0)],98 normal_concat=range(2, 6),99 reduce=[('sep_conv_3x3', 0),100 ('sep_conv_3x3', 1),101 ('skip_connect', 2),102 ('max_pool_3x3', 0),103 ('skip_connect', 2),104 ('skip_connect', 3),105 ('skip_connect', 2),106 ('skip_connect', 3)],107 reduce_concat=range(2, 6))108DARTS_MINUS_CIFAR100 = Genotype(109 normal=[('skip_connect', 0),110 ('sep_conv_3x3', 1),111 ('dil_conv_3x3', 0),112 ('skip_connect', 1),113 ('sep_conv_3x3', 0),114 ('skip_connect', 1),115 ('skip_connect', 1),116 ('skip_connect', 0)],117 normal_concat=range(2, 6),118 reduce=[('sep_conv_3x3', 0),119 ('avg_pool_3x3', 1),120 ('skip_connect', 2),121 ('avg_pool_3x3', 1),122 ('skip_connect', 2),123 ('skip_connect', 3),124 ('skip_connect', 2),125 ('skip_connect', 3)],126 reduce_concat=range(2, 6))127DARTS_MINUS_TS_CIFAR10 = Genotype(128 normal=[('sep_conv_3x3', 0),129 ('sep_conv_3x3', 1),130 ('sep_conv_5x5', 0),131 ('sep_conv_3x3', 1),132 ('dil_conv_3x3', 0),133 ('dil_conv_5x5', 1),134 ('skip_connect', 0),135 ('skip_connect', 1)],136 normal_concat=range(2, 6),137 reduce=[('max_pool_3x3', 1),138 ('max_pool_3x3', 0),139 ('skip_connect', 2),140 ('max_pool_3x3', 1),141 ('skip_connect', 2),142 ('skip_connect', 3),143 ('skip_connect', 2),144 ('skip_connect', 3)],145 reduce_concat=range(2, 6))146DARTS_MINUS_TS_CIFAR100 = Genotype(147 normal=[('sep_conv_3x3', 0),148 ('dil_conv_3x3', 1),149 ('skip_connect', 1),150 ('dil_conv_5x5', 0),151 ('skip_connect', 1),152 ('dil_conv_5x5', 0),153 ('skip_connect', 1),154 ('dil_conv_3x3', 0)],155 normal_concat=range(2, 6),156 reduce=[('sep_conv_3x3', 0),157 ('max_pool_3x3', 1),158 ('skip_connect', 2),159 ('sep_conv_3x3', 1),160 ('skip_connect', 2),161 ('skip_connect', 3),162 ('skip_connect', 2),163 ('skip_connect', 3)],164 reduce_concat=range(2, 6))165NASNet = Genotype(166 normal=[167 ('sep_conv_5x5', 1),168 ('sep_conv_3x3', 0),169 ('sep_conv_5x5', 0),170 ('sep_conv_3x3', 0),171 ('avg_pool_3x3', 1),172 ('skip_connect', 0),173 ('avg_pool_3x3', 0),174 ('avg_pool_3x3', 0),175 ('sep_conv_3x3', 1),176 ('skip_connect', 1),177 ],178 normal_concat=[2, 3, 4, 5, 6],179 reduce=[180 ('sep_conv_5x5', 1),181 ('sep_conv_7x7', 0),182 ('max_pool_3x3', 1),183 ('sep_conv_7x7', 0),184 ('avg_pool_3x3', 1),185 ('sep_conv_5x5', 0),186 ('skip_connect', 3),187 ('avg_pool_3x3', 2),188 ('sep_conv_3x3', 2),189 ('max_pool_3x3', 1),190 ],191 reduce_concat=[4, 5, 6],192)193AmoebaNet = Genotype(194 normal=[195 ('avg_pool_3x3', 0),196 ('max_pool_3x3', 1),197 ('sep_conv_3x3', 0),198 ('sep_conv_5x5', 2),199 ('sep_conv_3x3', 0),200 ('avg_pool_3x3', 3),201 ('sep_conv_3x3', 1),202 ('skip_connect', 1),203 ('skip_connect', 0),204 ('avg_pool_3x3', 1),205 ],206 normal_concat=[4, 5, 6],207 reduce=[208 ('avg_pool_3x3', 0),209 ('sep_conv_3x3', 1),210 ('max_pool_3x3', 0),211 ('sep_conv_7x7', 2),212 ('sep_conv_7x7', 0),213 ('avg_pool_3x3', 1),214 ('max_pool_3x3', 0),215 ('max_pool_3x3', 1),216 ('conv_7x1_1x7', 0),217 ('sep_conv_3x3', 5),218 ],219 reduce_concat=[3, 4, 6]220)221DARTS_V1 = Genotype(222 normal=[('sep_conv_3x3', 1),223 ('sep_conv_3x3', 0),224 ('skip_connect', 0),225 ('sep_conv_3x3', 1),226 ('skip_connect', 0),227 ('sep_conv_3x3', 1),228 ('sep_conv_3x3', 0),229 ('skip_connect', 2)],230 normal_concat=[2, 3, 4, 5],231 reduce=[('max_pool_3x3', 0),232 ('max_pool_3x3', 1),233 ('skip_connect', 2),234 ('max_pool_3x3', 0),235 ('max_pool_3x3', 0),236 ('skip_connect', 2),237 ('skip_connect', 2),238 ('avg_pool_3x3', 0)],239 reduce_concat=[2, 3, 4, 5])240DARTS_V2 = Genotype(241 normal=[('sep_conv_3x3', 0),242 ('sep_conv_3x3', 1),243 ('sep_conv_3x3', 0),244 ('sep_conv_3x3', 1),245 ('sep_conv_3x3', 1),246 ('skip_connect', 0),247 ('skip_connect', 0),248 ('dil_conv_3x3', 2)],249 normal_concat=[2, 3, 4, 5],250 reduce=[('max_pool_3x3', 0),251 ('max_pool_3x3', 1),252 ('skip_connect', 2),253 ('max_pool_3x3', 1),254 ('max_pool_3x3', 0),255 ('skip_connect', 2),256 ('skip_connect', 2),257 ('max_pool_3x3', 1)],258 reduce_concat=[2, 3, 4, 5])259DARTS = DARTS_V2260DARTS_CIFAR10_TS_1ST = Genotype(261 normal=[('sep_conv_3x3', 0),262 ('dil_conv_5x5', 1),263 ('skip_connect', 0),264 ('sep_conv_5x5', 1),265 ('skip_connect', 0),266 ('dil_conv_3x3', 1),267 ('skip_connect', 0),268 ('dil_conv_3x3', 1)],269 normal_concat=range(2, 6),270 reduce=[('max_pool_3x3', 0),271 ('max_pool_3x3', 1),272 ('skip_connect', 2),273 ('max_pool_3x3', 0),274 ('max_pool_3x3', 1),275 ('skip_connect', 2),276 ('skip_connect', 2),277 ('skip_connect', 3)],278 reduce_concat=range(2, 6))279DARTS_CIFAR100_TS_1ST = Genotype(280 normal=[('sep_conv_3x3', 0),281 ('sep_conv_3x3', 1),282 ('skip_connect', 0),283 ('skip_connect', 1),284 ('skip_connect', 0),285 ('skip_connect', 1),286 ('skip_connect', 0),287 ('skip_connect', 1)],288 normal_concat=range(2, 6),289 reduce=[('avg_pool_3x3', 0),290 ('avg_pool_3x3', 1),291 ('skip_connect', 2),292 ('avg_pool_3x3', 0),293 ('skip_connect', 2),294 ('avg_pool_3x3', 0),295 ('skip_connect', 2),296 ('avg_pool_3x3', 0)],297 reduce_concat=range(2, 6))298DARTS_CIFAR10_TS_18_V1 = Genotype(299 normal=[('sep_conv_3x3', 0),300 ('sep_conv_3x3', 1),301 ('skip_connect', 0),302 ('sep_conv_5x5', 1),303 ('sep_conv_3x3', 0),304 ('sep_conv_3x3', 1),305 ('skip_connect', 0),306 ('dil_conv_5x5', 1)],307 normal_concat=range(2, 6),308 reduce=[('avg_pool_3x3', 0),309 ('avg_pool_3x3', 1),310 ('avg_pool_3x3', 0),311 ('skip_connect', 2),312 ('skip_connect', 2),313 ('skip_connect', 3),314 ('avg_pool_3x3', 0),315 ('skip_connect', 2)],316 reduce_concat=range(2, 6))317DARTS_CIFAR10_TS_18_V2 = Genotype(318 normal=[('sep_conv_3x3', 0),319 ('sep_conv_3x3', 1),320 ('skip_connect', 0),321 ('sep_conv_5x5', 1),322 ('sep_conv_3x3', 0),323 ('sep_conv_3x3', 1),324 ('skip_connect', 0),325 ('dil_conv_5x5', 1)],326 normal_concat=range(2, 6),327 reduce=[('avg_pool_3x3', 0),328 ('avg_pool_3x3', 1),329 ('avg_pool_3x3', 0),330 ('skip_connect', 2),331 ('skip_connect', 2),332 ('avg_pool_3x3', 1),333 ('avg_pool_3x3', 0),334 ('skip_connect', 2)],335 reduce_concat=range(2, 6))336MY_DARTS_CIFAR10 = Genotype(337 normal=[('skip_connect', 0),338 ('sep_conv_3x3', 1),339 ('skip_connect', 0),340 ('dil_conv_5x5', 2),341 ('skip_connect', 0),342 ('dil_conv_5x5', 1),343 ('skip_connect', 0),344 ('sep_conv_3x3', 1)],345 normal_concat=range(2, 6),346 reduce=[('sep_conv_3x3', 1),347 ('max_pool_3x3', 0),348 ('skip_connect', 2),349 ('avg_pool_3x3', 0),350 ('skip_connect', 2),351 ('skip_connect', 3),352 ('skip_connect', 3),353 ('skip_connect', 2)],354 reduce_concat=range(2, 6))355DARTS_CIFAR10_TS_50 = Genotype(356 normal=[('sep_conv_3x3', 0), 357 ('sep_conv_3x3', 1),358 ('sep_conv_3x3', 0), 359 ('sep_conv_3x3', 1), 360 ('sep_conv_3x3', 0), 361 ('skip_connect', 1), 362 ('skip_connect', 0), 363 ('dil_conv_3x3', 1)],364 normal_concat=range(2, 6), 365 reduce=[('dil_conv_3x3', 0), 366 ('sep_conv_3x3', 1),367 ('max_pool_3x3', 0), 368 ('skip_connect', 2), 369 ('skip_connect', 2), 370 ('skip_connect', 3), 371 ('skip_connect', 2), 372 ('skip_connect', 3)], 373 reduce_concat=range(2, 6))374DARTS_CIFAR100_TS_50 = Genotype(375 normal=[('sep_conv_3x3', 0), 376 ('sep_conv_3x3', 1), 377 ('skip_connect', 0), 378 ('skip_connect', 1), 379 ('skip_connect', 0), 380 ('dil_conv_3x3', 1), 381 ('skip_connect', 0), 382 ('dil_conv_3x3', 1)], 383 normal_concat=range(2, 6), 384 reduce=[('max_pool_3x3', 1), 385 ('max_pool_3x3', 0), 386 ('max_pool_3x3', 0), 387 ('dil_conv_5x5', 2), 388 ('skip_connect', 2), 389 ('max_pool_3x3', 0), 390 ('skip_connect', 2), 391 ('max_pool_3x3', 0)], 392 reduce_concat=range(2, 6))393DARTS_CIFAR100_TS_34 = Genotype(394 normal=[('skip_connect', 0), 395 ('dil_conv_3x3', 1), 396 ('skip_connect', 0), 397 ('dil_conv_5x5', 1), 398 ('skip_connect', 0), 399 ('skip_connect', 1), 400 ('skip_connect', 0), 401 ('skip_connect', 1)], 402 normal_concat=range(2, 6), 403 reduce=[('avg_pool_3x3', 0), 404 ('avg_pool_3x3', 1), 405 ('skip_connect', 2), 406 ('avg_pool_3x3', 0), 407 ('skip_connect', 2), 408 ('avg_pool_3x3', 0), 409 ('skip_connect', 2), 410 ('avg_pool_3x3', 0)], 411 reduce_concat=range(2, 6))412DARTS_CIFAR10_TS_34 = Genotype(413 normal=[('sep_conv_3x3', 0), 414 ('sep_conv_3x3', 1), 415 ('skip_connect', 0), 416 ('dil_conv_3x3', 2), 417 ('sep_conv_3x3', 0), 418 ('dil_conv_5x5', 1), 419 ('skip_connect', 0), 420 ('sep_conv_3x3', 1)], 421 normal_concat=range(2, 6), 422 reduce=[('avg_pool_3x3', 1), 423 ('skip_connect', 0), 424 ('skip_connect', 2), 425 ('avg_pool_3x3', 1), 426 ('avg_pool_3x3', 1), 427 ('skip_connect', 2), 428 ('skip_connect', 2), 429 ('skip_connect', 3)], 430 reduce_concat=range(2, 6))431# DARTS_CIFAR100 = Genotype(432# normal=[('skip_connect', 0),433# ('skip_connect', 1),434# ('skip_connect', 0),435# ('skip_connect', 1),436# ('skip_connect', 0),437# ('skip_connect', 1),438# ('skip_connect', 0),439# ('skip_connect', 1)],440# normal_concat=range(2, 6),441# reduce=[('max_pool_3x3', 0),442# ('dil_conv_3x3', 1),443# ('skip_connect', 2),444# ('avg_pool_3x3', 0),445# ('skip_connect', 2),446# ('max_pool_3x3', 0),447# ('skip_connect', 2),448# ('avg_pool_3x3', 0)],449# reduce_concat=range(2, 6))450DARTS_CIFAR100_1ST = Genotype(451 normal=[('skip_connect', 0),452 ('skip_connect', 1),453 ('skip_connect', 0),454 ('sep_conv_3x3', 1),455 ('skip_connect', 0),456 ('skip_connect', 1),457 ('skip_connect', 0),458 ('skip_connect', 1)],459 normal_concat=range(2, 6),460 reduce=[('avg_pool_3x3', 0),461 ('avg_pool_3x3', 1),462 ('skip_connect', 2),463 ('avg_pool_3x3', 0),464 ('avg_pool_3x3', 0),465 ('skip_connect', 2),466 ('skip_connect', 2),467 ('avg_pool_3x3', 0)],468 reduce_concat=range(2, 6))469DARTS_CIFAR100 = Genotype(470 normal=[('skip_connect', 0),471 ('sep_conv_3x3', 1),472 ('skip_connect', 0),473 ('skip_connect', 1),474 ('skip_connect', 0),475 ('skip_connect', 1),476 ('skip_connect', 0),477 ('skip_connect', 1)],478 normal_concat=range(2, 6),479 reduce=[('avg_pool_3x3', 0),480 ('skip_connect', 1),481 ('skip_connect', 2),482 ('avg_pool_3x3', 0),483 ('avg_pool_3x3', 0),484 ('skip_connect', 2),485 ('skip_connect', 2),486 ('avg_pool_3x3', 0)],487 reduce_concat=range(2, 6))488DARTS_CIFAR100_TS_18 = Genotype(489 normal=[('sep_conv_3x3', 0),490 ('sep_conv_3x3', 1),491 ('skip_connect', 0),492 ('skip_connect', 1),493 ('skip_connect', 0),494 ('skip_connect', 1),495 ('skip_connect', 0),496 ('skip_connect', 1)],497 normal_concat=range(2, 6),498 reduce=[('avg_pool_3x3', 0),499 ('skip_connect', 1),500 ('avg_pool_3x3', 0),501 ('skip_connect', 2),502 ('avg_pool_3x3', 0),503 ('skip_connect', 2),504 ('skip_connect', 2),505 ('avg_pool_3x3', 0)],506 reduce_concat=range(2, 6))507DARTS_CIFAR100_ES = Genotype(508 normal=[('sep_conv_3x3', 1),509 ('skip_connect', 0),510 ('sep_conv_5x5', 1),511 ('skip_connect', 0),512 ('sep_conv_3x3', 0),513 ('sep_conv_3x3', 1),514 ('sep_conv_3x3', 1),515 ('sep_conv_3x3', 3)],516 normal_concat=range(2, 6),517 reduce=[('max_pool_3x3', 0),518 ('skip_connect', 1),519 ('max_pool_3x3', 0),520 ('dil_conv_3x3', 2),521 ('max_pool_3x3', 0),522 ('sep_conv_5x5', 2),523 ('max_pool_3x3', 0),524 ('skip_connect', 2)],525 reduce_concat=range(2, 6))526DARTS_CIFAR100_TS_18_ES = Genotype(527 normal=[('sep_conv_3x3', 0),528 ('sep_conv_3x3', 1),529 ('skip_connect', 0),530 ('sep_conv_5x5', 1),531 ('sep_conv_3x3', 0),532 ('sep_conv_3x3', 1),533 ('sep_conv_5x5', 2),534 ('skip_connect', 0)],535 normal_concat=range(2, 6),536 reduce=[('max_pool_3x3', 0),537 ('skip_connect', 1),538 ('max_pool_3x3', 0),539 ('skip_connect', 2),540 ('max_pool_3x3', 0),541 ('sep_conv_5x5', 3),542 ('max_pool_3x3', 0),543 ('skip_connect', 2)],544 reduce_concat=range(2, 6))545DARTS_CIFAR10_ES = Genotype(546 normal=[('sep_conv_3x3', 1),547 ('skip_connect', 0),548 ('dil_conv_5x5', 2),549 ('skip_connect', 0),550 ('sep_conv_5x5', 1),551 ('skip_connect', 0),552 ('sep_conv_3x3', 1),553 ('sep_conv_3x3', 2)],554 normal_concat=range(2, 6),555 reduce=[('max_pool_3x3', 0),556 ('sep_conv_3x3', 1),557 ('skip_connect', 2),558 ('max_pool_3x3', 0),559 ('skip_connect', 2),560 ('max_pool_3x3', 0),561 ('skip_connect', 2),562 ('max_pool_3x3', 0)],563 reduce_concat=range(2, 6))564DARTS_CIFAR10_TS_18_ES = Genotype(565 normal=[('sep_conv_3x3', 0),566 ('sep_conv_3x3', 1),567 ('skip_connect', 0),568 ('sep_conv_5x5', 1),569 ('sep_conv_3x3', 0),570 ('sep_conv_3x3', 1),571 ('skip_connect', 0),572 ('sep_conv_5x5', 1)],573 normal_concat=range(2, 6),574 reduce=[('avg_pool_3x3', 0),575 ('avg_pool_3x3', 1),576 ('avg_pool_3x3', 0),577 ('skip_connect', 2),578 ('skip_connect', 2),579 ('max_pool_3x3', 0),580 ('avg_pool_3x3', 0),581 ('skip_connect', 2)],582 reduce_concat=range(2, 6))583PDARTS_TS_CIFAR100_GAMMA_2 = Genotype(normal=[('sep_conv_3x3', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('sep_conv_3x3', 2), ('skip_connect', 0), ('sep_conv_3x3', 2), ('sep_conv_3x3', 0), ('sep_conv_3x3', 2)], normal_concat=range(2, 6), reduce=[('avg_pool_3x3', 0), ('avg_pool_3x3', 1), ('avg_pool_3x3', 0), ('dil_conv_5x5', 2), ('avg_pool_3x3', 0), ('sep_conv_5x5', 2), ('avg_pool_3x3', 0), ('sep_conv_5x5', 4)], reduce_concat=range(2, 6))584PDARTS_TS_CIFAR100_GAMMA_3 = Genotype(normal=[('sep_conv_3x3', 0), ('dil_conv_3x3', 1), ('skip_connect', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('dil_conv_5x5', 2), ('sep_conv_3x3', 0), ('dil_conv_5x5', 1)], normal_concat=range(2, 6), reduce=[('skip_connect', 0), ('max_pool_3x3', 1), ('skip_connect', 0), ('sep_conv_3x3', 1), ('avg_pool_3x3', 0), ('dil_conv_5x5', 3), ('dil_conv_3x3', 3), ('dil_conv_3x3', 4)], reduce_concat=range(2, 6))585PDARTS_TS_CIFAR100_GAMMA_0_1 = Genotype(normal=[('sep_conv_3x3', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('dil_conv_3x3', 2), ('skip_connect', 0), ('sep_conv_3x3', 2), ('sep_conv_3x3', 0), ('dil_conv_3x3', 3)], normal_concat=range(2, 6), reduce=[('avg_pool_3x3', 0), ('dil_conv_5x5', 1), ('avg_pool_3x3', 0), ('sep_conv_3x3', 2), ('dil_conv_5x5', 2), ('dil_conv_3x3', 3), ('avg_pool_3x3', 0), ('sep_conv_5x5', 2)], reduce_concat=range(2, 6))586PDARTS_TS_CIFAR100_GAMMA_0_5 = Genotype(normal=[('sep_conv_3x3', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('sep_conv_3x3', 1), ('sep_conv_3x3', 0), ('skip_connect', 2), ('sep_conv_3x3', 1), ('sep_conv_5x5', 4)], normal_concat=range(2, 6), reduce=[('sep_conv_3x3', 0), ('skip_connect', 1), ('avg_pool_3x3', 0), ('sep_conv_3x3', 2), ('avg_pool_3x3', 0), ('sep_conv_3x3', 1), ('avg_pool_3x3', 0), ('dil_conv_5x5', 2)], reduce_concat=range(2, 6))587DARTS_TS_18_CIFAR10_GAMMA_0_5 = Genotype(normal=[('skip_connect', 0), ('sep_conv_3x3', 1), ('sep_conv_3x3', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('dil_conv_5x5', 1), ('skip_connect', 0), ('dil_conv_3x3', 1)], normal_concat=range(2, 6), reduce=[('max_pool_3x3', 0), ('skip_connect', 1), ('skip_connect', 2), ('max_pool_3x3', 0), ('max_pool_3x3', 0), ('skip_connect', 2), ('skip_connect', 2), ('max_pool_3x3', 0)], reduce_concat=range(2, 6))588DARTS_TS_18_CIFAR10_GAMMA_0_1 = Genotype(normal=[('skip_connect', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('skip_connect', 1), ('skip_connect', 0), ('dil_conv_5x5', 1), ('skip_connect', 0), ('dil_conv_3x3', 1)], normal_concat=range(2, 6), reduce=[('max_pool_3x3', 0), ('avg_pool_3x3', 1), ('max_pool_3x3', 0), ('skip_connect', 2), ('max_pool_3x3', 0), ('skip_connect', 2), ('skip_connect', 2), ('avg_pool_3x3', 0)], reduce_concat=range(2, 6))589DARTS_TS_18_CIFAR10_GAMMA_2 = Genotype(normal=[('skip_connect', 0), ('sep_conv_5x5', 1), ('skip_connect', 0), ('skip_connect', 1), ('sep_conv_3x3', 0), ('dil_conv_3x3', 1), ('skip_connect', 0), ('dil_conv_3x3', 1)], normal_concat=range(2, 6), reduce=[('avg_pool_3x3', 0), ('avg_pool_3x3', 1), ('skip_connect', 2), ('avg_pool_3x3', 0), ('skip_connect', 2), ('avg_pool_3x3', 0), ('skip_connect', 2), ('skip_connect', 3)], reduce_concat=range(2, 6))590DARTS_TS_18_CIFAR10_GAMMA_3 = Genotype(normal=[('skip_connect', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('skip_connect', 1), ('skip_connect', 0), ('dil_conv_5x5', 1), ('skip_connect', 0), ('dil_conv_5x5', 1)], normal_concat=range(2, 6), reduce=[('avg_pool_3x3', 1), ('avg_pool_3x3', 0), ('skip_connect', 2), ('avg_pool_3x3', 1), ('skip_connect', 2), ('avg_pool_3x3', 0), ('skip_connect', 2), ('avg_pool_3x3', 0)], reduce_concat=range(2, 6))591DARTS_TS_18_CIFAR10_LAMBDA_2 = Genotype(normal=[('sep_conv_3x3', 0), ('sep_conv_3x3', 1), ('sep_conv_3x3', 0), ('dil_conv_5x5', 1), ('skip_connect', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('sep_conv_3x3', 1)], normal_concat=range(2, 6), reduce=[('skip_connect', 0), ('avg_pool_3x3', 1), ('skip_connect', 2), ('max_pool_3x3', 0), ('avg_pool_3x3', 1), ('skip_connect', 2), ('skip_connect', 2), ('skip_connect', 3)], reduce_concat=range(2, 6))592DARTS_TS_18_CIFAR10_LAMBDA_0_1 = Genotype(normal=[('sep_conv_3x3', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('skip_connect', 2), ('sep_conv_3x3', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('dil_conv_3x3', 1)], normal_concat=range(2, 6), reduce=[('avg_pool_3x3', 1), ('avg_pool_3x3', 0), ('skip_connect', 2), ('max_pool_3x3', 0), ('skip_connect', 2), ('skip_connect', 3), ('skip_connect', 2), ('avg_pool_3x3', 0)], reduce_concat=range(2, 6))593DARTS_TS_18_CIFAR10_LAMBDA_0_5 = Genotype(normal=[('sep_conv_3x3', 0), ('dil_conv_3x3', 1), ('sep_conv_3x3', 0), ('sep_conv_5x5', 1), ('skip_connect', 0), ('dil_conv_3x3', 1), ('skip_connect', 0), ('skip_connect', 1)], normal_concat=range(2, 6), reduce=[('max_pool_3x3', 0), ('dil_conv_3x3', 1), ('skip_connect', 2), ('max_pool_3x3', 0), ('skip_connect', 2), ('skip_connect', 3), ('skip_connect', 3), ('skip_connect', 2)], reduce_concat=range(2, 6))594DARTS_TS_18_CIFAR10_LAMBDA_3 = Genotype(normal=[('skip_connect', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('sep_conv_3x3', 1)], normal_concat=range(2, 6), reduce=[('max_pool_3x3', 0), ('dil_conv_5x5', 1), ('skip_connect', 2), ('avg_pool_3x3', 0), ('avg_pool_3x3', 0), ('skip_connect', 2), ('skip_connect', 2), ('avg_pool_3x3', 0)], reduce_concat=range(2, 6))595PDARTS_TS_18_CIFAR100_LAMBDA_3 = Genotype(normal=[('skip_connect', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('sep_conv_5x5', 1), ('dil_conv_3x3', 1), ('sep_conv_3x3', 2), ('sep_conv_3x3', 0), ('sep_conv_3x3', 1)], normal_concat=range(2, 6), reduce=[('max_pool_3x3', 0), ('sep_conv_3x3', 1), ('skip_connect', 1), ('sep_conv_3x3', 2), ('max_pool_3x3', 0), ('sep_conv_5x5', 1), ('dil_conv_3x3', 1), ('dil_conv_3x3', 2)], reduce_concat=range(2, 6))596PDARTS_TS_18_CIFAR100_LAMBDA_0_1 = Genotype(normal=[('sep_conv_3x3', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('sep_conv_3x3', 1), ('sep_conv_3x3', 0), ('dil_conv_3x3', 1)], normal_concat=range(2, 6), reduce=[('max_pool_3x3', 0), ('sep_conv_5x5', 1), ('avg_pool_3x3', 0), ('sep_conv_3x3', 1), ('avg_pool_3x3', 0), ('dil_conv_5x5', 3), ('avg_pool_3x3', 0), ('dil_conv_3x3', 1)], reduce_concat=range(2, 6))597PDARTS_TS_18_CIFAR100_LAMBDA_0_5 = Genotype(normal=[('skip_connect', 0), ('sep_conv_5x5', 1), ('sep_conv_3x3', 0), ('skip_connect', 1), ('sep_conv_3x3', 0), ('sep_conv_3x3', 3), ('sep_conv_3x3', 0), ('dil_conv_3x3', 1)], normal_concat=range(2, 6), reduce=[('skip_connect', 0), ('skip_connect', 1), ('skip_connect', 0), ('skip_connect', 1), ('avg_pool_3x3', 0), ('avg_pool_3x3', 1), ('avg_pool_3x3', 0), ('dil_conv_5x5', 4)], reduce_concat=range(2, 6))598PDARTS_TS_18_CIFAR100_LAMBDA_2 = Genotype(normal=[('sep_conv_3x3', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('dil_conv_3x3', 1), ('skip_connect', 0), ('sep_conv_5x5', 2), ('sep_conv_3x3', 0), ('dil_conv_5x5', 4)], normal_concat=range(2, 6), reduce=[('max_pool_3x3', 0), ('skip_connect', 1), ('avg_pool_3x3', 0), ('sep_conv_5x5', 1), ('avg_pool_3x3', 0), ('sep_conv_3x3', 2), ('max_pool_3x3', 0), ('dil_conv_3x3', 1)], reduce_concat=range(2, 6))599PDARTS_TS_18_CIFAR100_AB_1 = Genotype(normal=[('dil_conv_3x3', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('sep_conv_3x3', 2), ('sep_conv_3x3', 0), ('dil_conv_3x3', 1), ('sep_conv_3x3', 0), ('sep_conv_3x3', 3)], normal_concat=range(2, 6), reduce=[('skip_connect', 0), ('dil_conv_5x5', 1), ('avg_pool_3x3', 0), ('skip_connect', 1), ('skip_connect', 0), ('sep_conv_5x5', 2), ('skip_connect', 0), ('sep_conv_3x3', 1)], reduce_concat=range(2, 6))600PDARTS_TS_18_CIFAR100_AB_4 = Genotype(normal=[('sep_conv_3x3', 0), ('dil_conv_3x3', 1), ('sep_conv_3x3', 0), ('skip_connect', 1), ('max_pool_3x3', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('sep_conv_5x5', 1)], normal_concat=range(2, 6), reduce=[('avg_pool_3x3', 0), ('skip_connect', 1), ('avg_pool_3x3', 0), ('sep_conv_5x5', 2), ('avg_pool_3x3', 0), ('dil_conv_3x3', 1), ('avg_pool_3x3', 0), ('sep_conv_3x3', 4)], reduce_concat=range(2, 6))601DARTS_TS_18_CIFAR10_AB_1 = Genotype(normal=[('sep_conv_3x3', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('dil_conv_5x5', 1), ('skip_connect', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('sep_conv_3x3', 1)], normal_concat=range(2, 6), reduce=[('max_pool_3x3', 0), ('dil_conv_5x5', 1), ('skip_connect', 2), ('max_pool_3x3', 0), ('skip_connect', 2), ('avg_pool_3x3', 0), ('skip_connect', 2), ('skip_connect', 3)], reduce_concat=range(2, 6))602DARTS_TS_18_CIFAR10_AB_4 = Genotype(normal=[('sep_conv_3x3', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('dil_conv_3x3', 1), ('sep_conv_3x3', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('sep_conv_3x3', 1)], normal_concat=range(2, 6), reduce=[('dil_conv_3x3', 0), ('sep_conv_3x3', 1), ('skip_connect', 2), ('max_pool_3x3', 1), ('skip_connect', 2), ('dil_conv_3x3', 3), ('skip_connect', 2), ('skip_connect', 4)], reduce_concat=range(2, 6))603PDARTS_TUNED_CIFAR100 = Genotype(normal=[('sep_conv_3x3', 0), ('skip_connect', 1), ('sep_conv_3x3', 0), ('skip_connect', 1), ('sep_conv_3x3', 0), ('sep_conv_5x5', 3), ('sep_conv_5x5', 0), ('sep_conv_3x3', 1)], normal_concat=range(2, 6), reduce=[('avg_pool_3x3', 0), ('sep_conv_3x3', 1), ('avg_pool_3x3', 0), ('dil_conv_3x3', 2), ('max_pool_3x3', 1), ('sep_conv_3x3', 3), ('sep_conv_5x5', 1), ('dil_conv_5x5', 4)], reduce_concat=range(2, 6))...

Full Screen

Full Screen

routing.py

Source:routing.py Github

copy

Full Screen

...12class Mapper(_Mapper):13 ''' This Mapper allows us to intercept the connect calls used by routes14 so that we can collect named routes and later use them to create links15 via some helper functions like build_nav(). '''16 def connect(self, *args, **kw):17 '''Connect a new route, storing any named routes for later.18 This custom connect() method wraps the standard connect() method,19 and additionally saves any named routes that are connected in a dict20 ckan.routing.named_routes, which ends up being accessible via the21 Pylons config as config['routes.named_routes'].22 Also takes some additional params:23 :param ckan_icon: name of the icon to be associated with this route,24 e.g. 'group', 'time'. Available icons are listed here:25 http://fortawesome.github.io/Font-Awesome/3.2.1/icons/26 :type ckan_icon: string27 :param highlight_actions: space-separated list of controller actions28 that should be treated as the same as this named route for menu29 highlighting purposes, e.g. 'index search'30 :type highlight_actions: string31 '''32 ckan_icon = kw.pop('ckan_icon', None)33 highlight_actions = kw.pop('highlight_actions', kw.get('action', ''))34 ckan_core = kw.pop('ckan_core', None)35 out = _Mapper.connect(self, *args, **kw)36 route = self.matchlist[-1]37 if ckan_core is not None:38 route._ckan_core = ckan_core39 if len(args) == 1 or args[0].startswith('_redirect_'):40 return out41 # we have a named route42 needed = []43 matches = re.findall('\{([^:}]*)(\}|:)', args[1])44 for match in matches:45 needed.append(match[0])46 route_data = {47 'icon': ckan_icon,48 # needed lists the names of the parameters that need defining49 # for the route to be generated50 'needed': needed,51 'controller': kw.get('controller'),52 'action': kw.get('action', ''),53 'highlight_actions': highlight_actions54 }55 named_routes[args[0]] = route_data56 return out57def make_map():58 """Create, configure and return the routes Mapper"""59 # import controllers here rather than at root level because60 # pylons config is initialised by this point.61 # Helpers to reduce code clutter62 GET = dict(method=['GET'])63 PUT = dict(method=['PUT'])64 POST = dict(method=['POST'])65 DELETE = dict(method=['DELETE'])66 GET_POST = dict(method=['GET', 'POST'])67 PUT_POST = dict(method=['PUT', 'POST'])68 PUT_POST_DELETE = dict(method=['PUT', 'POST', 'DELETE'])69 OPTIONS = dict(method=['OPTIONS'])70 import ckan.lib.plugins as lib_plugins71 lib_plugins.reset_package_plugins()72 map = Mapper(directory=config['pylons.paths']['controllers'],73 always_scan=config['debug'])74 map.minimization = False75 map.explicit = True76 # CUSTOM ROUTES HERE77 for plugin in p.PluginImplementations(p.IRoutes):78 map = plugin.before_map(map)79 # The ErrorController route (handles 404/500 error pages); it should80 # likely stay at the top, ensuring it can always be resolved.81 map.connect('/error/{action}', controller='error', ckan_core=True)82 map.connect('/error/{action}/{id}', controller='error', ckan_core=True)83 map.connect('*url', controller='home', action='cors_options',84 conditions=OPTIONS, ckan_core=True)85 # Mark all routes added from extensions on the `before_map` extension point86 # as non-core87 for route in map.matchlist:88 if not hasattr(route, '_ckan_core'):89 route._ckan_core = False90 # CKAN API versioned.91 register_list = [92 'package',93 'dataset',94 'resource',95 'tag',96 'group',97 'revision',98 'licenses',99 'rating',100 'user',101 'activity'102 ]103 register_list_str = '|'.join(register_list)104 # /api ver 1, 2, 3 or none105 with SubMapper(map, controller='api', path_prefix='/api{ver:/1|/2|/3|}',106 ver='/1') as m:107 m.connect('/search/{register}', action='search')108 # /api/util ver 1, 2 or none109 with SubMapper(map, controller='api', path_prefix='/api{ver:/1|/2|}',110 ver='/1') as m:111 m.connect('/util/dataset/munge_name', action='munge_package_name')112 m.connect('/util/dataset/munge_title_to_name',113 action='munge_title_to_package_name')114 m.connect('/util/tag/munge', action='munge_tag')115 ###########116 ## /END API117 ###########118 map.redirect('/packages', '/dataset')119 map.redirect('/packages/{url:.*}', '/dataset/{url}')120 map.redirect('/package', '/dataset')121 map.redirect('/package/{url:.*}', '/dataset/{url}')122 with SubMapper(map, controller='package') as m:123 m.connect('search', '/dataset', action='search',124 highlight_actions='index search')125 m.connect('dataset_new', '/dataset/new', action='new')126 m.connect('/dataset/{action}',127 requirements=dict(action='|'.join([128 'list',129 'autocomplete',130 'search'131 ])))132 m.connect('/dataset/{action}/{id}/{revision}', action='read_ajax',133 requirements=dict(action='|'.join([134 'read',135 'edit',136 'history',137 ])))138 m.connect('/dataset/{action}/{id}',139 requirements=dict(action='|'.join([140 'new_resource',141 'history',142 'read_ajax',143 'history_ajax',144 'follow',145 'activity',146 'groups',147 'unfollow',148 'delete',149 'api_data',150 ])))151 m.connect('dataset_edit', '/dataset/edit/{id}', action='edit',152 ckan_icon='pencil-square-o')153 m.connect('dataset_followers', '/dataset/followers/{id}',154 action='followers', ckan_icon='users')155 m.connect('dataset_activity', '/dataset/activity/{id}',156 action='activity', ckan_icon='clock-o')157 m.connect('/dataset/activity/{id}/{offset}', action='activity')158 m.connect('dataset_groups', '/dataset/groups/{id}',159 action='groups', ckan_icon='users')160 m.connect('dataset_resources', '/dataset/resources/{id}',161 action='resources', ckan_icon='bars')162 m.connect('dataset_read', '/dataset/{id}', action='read',163 ckan_icon='sitemap')164 m.connect('/dataset/{id}/resource/{resource_id}',165 action='resource_read')166 m.connect('/dataset/{id}/resource_delete/{resource_id}',167 action='resource_delete')168 m.connect('resource_edit', '/dataset/{id}/resource_edit/{resource_id}',169 action='resource_edit', ckan_icon='pencil-square-o')170 m.connect('/dataset/{id}/resource/{resource_id}/download',171 action='resource_download')172 m.connect('/dataset/{id}/resource/{resource_id}/download/{filename}',173 action='resource_download')174 m.connect('/dataset/{id}/resource/{resource_id}/embed',175 action='resource_embedded_dataviewer')176 m.connect('/dataset/{id}/resource/{resource_id}/viewer',177 action='resource_embedded_dataviewer', width="960",178 height="800")179 m.connect('/dataset/{id}/resource/{resource_id}/preview',180 action='resource_datapreview')181 m.connect('views', '/dataset/{id}/resource/{resource_id}/views',182 action='resource_views', ckan_icon='bars')183 m.connect('new_view', '/dataset/{id}/resource/{resource_id}/new_view',184 action='edit_view', ckan_icon='pencil-square-o')185 m.connect('edit_view',186 '/dataset/{id}/resource/{resource_id}/edit_view/{view_id}',187 action='edit_view', ckan_icon='pencil-square-o')188 m.connect('resource_view',189 '/dataset/{id}/resource/{resource_id}/view/{view_id}',190 action='resource_view')191 m.connect('/dataset/{id}/resource/{resource_id}/view/',192 action='resource_view')193 # group194 map.redirect('/groups', '/group')195 map.redirect('/groups/{url:.*}', '/group/{url}')196 # These named routes are used for custom group forms which will use the197 # names below based on the group.type ('group' is the default type)198 with SubMapper(map, controller='group') as m:199 m.connect('group_index', '/group', action='index',200 highlight_actions='index search')201 m.connect('group_list', '/group/list', action='list')202 m.connect('group_new', '/group/new', action='new')203 for action in [204 'edit',205 'delete',206 'member_new',207 'member_delete',208 'history',209 'followers',210 'follow',211 'unfollow',212 'admins',213 'activity',214 ]:215 m.connect('group_' + action,216 '/group/' + action + '/{id}',217 action=action)218 m.connect('group_about', '/group/about/{id}', action='about',219 ckan_icon='info-circle'),220 m.connect('group_edit', '/group/edit/{id}', action='edit',221 ckan_icon='pencil-square-o')222 m.connect('group_members', '/group/members/{id}', action='members',223 ckan_icon='users'),224 m.connect('group_activity', '/group/activity/{id}/{offset}',225 action='activity', ckan_icon='clock-o'),226 m.connect('group_read', '/group/{id}', action='read',227 ckan_icon='sitemap')228 # organizations these basically end up being the same as groups229 with SubMapper(map, controller='organization') as m:230 m.connect('organizations_index', '/organization', action='index')231 m.connect('organization_index', '/organization', action='index')232 m.connect('organization_new', '/organization/new', action='new')233 for action in [234 'delete',235 'admins',236 'member_new',237 'member_delete',238 'history']:239 m.connect('organization_' + action,240 '/organization/' + action + '/{id}',241 action=action)242 m.connect('organization_activity', '/organization/activity/{id}/{offset}',243 action='activity', ckan_icon='clock-o')244 m.connect('organization_read', '/organization/{id}', action='read')245 m.connect('organization_about', '/organization/about/{id}',246 action='about', ckan_icon='info-circle')247 m.connect('organization_read', '/organization/{id}', action='read',248 ckan_icon='sitemap')249 m.connect('organization_edit', '/organization/edit/{id}',250 action='edit', ckan_icon='pencil-square-o')251 m.connect('organization_members', '/organization/members/{id}',252 action='members', ckan_icon='users')253 m.connect('organization_bulk_process',254 '/organization/bulk_process/{id}',255 action='bulk_process', ckan_icon='sitemap')256 lib_plugins.register_package_plugins(map)257 lib_plugins.register_group_plugins(map)258 # tags259 map.redirect('/tags', '/tag')260 map.redirect('/tags/{url:.*}', '/tag/{url}')261 map.redirect('/tag/read/{url:.*}', '/tag/{url}',262 _redirect_code='301 Moved Permanently')263 map.connect('/tag', controller='tag', action='index')264 map.connect('/tag/{id}', controller='tag', action='read')265 # users266 map.redirect('/users/{url:.*}', '/user/{url}')267 with SubMapper(map, controller='revision') as m:268 m.connect('/revision', action='index')269 m.connect('/revision/edit/{id}', action='edit')270 m.connect('/revision/diff/{id}', action='diff')271 m.connect('/revision/list', action='list')272 m.connect('/revision/{id}', action='read')273 with SubMapper(map, controller='ckan.controllers.storage:StorageController') as m:274 m.connect('storage_file', '/storage/f/{label:.*}',275 action='file')276 with SubMapper(map, controller='util') as m:277 m.connect('/i18n/strings_{lang}.js', action='i18n_js_strings')278 m.connect('/util/redirect', action='redirect')279 m.connect('/testing/primer', action='primer')280 m.connect('/testing/markup', action='markup')281 # robots.txt282 map.connect('/(robots.txt)', controller='template', action='view')283 # Mark all unmarked routes added up until now as core routes284 for route in map.matchlist:285 if not hasattr(route, '_ckan_core'):286 route._ckan_core = True287 for plugin in p.PluginImplementations(p.IRoutes):288 map = plugin.after_map(map)289 # Mark all routes added from extensions on the `after_map` extension point290 # as non-core291 for route in map.matchlist:292 if not hasattr(route, '_ckan_core'):293 route._ckan_core = False294 # sometimes we get requests for favicon.ico we should redirect to295 # the real favicon location.296 map.redirect('/favicon.ico', config.get('ckan.favicon'))297 map.redirect('/*(url)/', '/{url}',298 _redirect_code='301 Moved Permanently')299 map.connect('/*url', controller='template', action='view', ckan_core=True)...

Full Screen

Full Screen

test_protocol.py

Source:test_protocol.py Github

copy

Full Screen

...12from twisted.trial.unittest import TestCase13from twisted.test.proto_helpers import MemoryReactor, StringTransport14class MemoryConnector:15 _disconnected = False16 def disconnect(self):17 self._disconnected = True18class MemoryReactorWithConnectorsAndTime(MemoryReactor, Clock):19 """20 An extension of L{MemoryReactor} which returns L{IConnector}21 providers from its C{connectTCP} method.22 """23 def __init__(self):24 MemoryReactor.__init__(self)25 Clock.__init__(self)26 self.connectors = []27 def connectTCP(self, *a, **kw):28 MemoryReactor.connectTCP(self, *a, **kw)29 connector = MemoryConnector()30 self.connectors.append(connector)31 return connector32 def connectUNIX(self, *a, **kw):33 MemoryReactor.connectUNIX(self, *a, **kw)34 connector = MemoryConnector()35 self.connectors.append(connector)36 return connector37 def connectSSL(self, *a, **kw):38 MemoryReactor.connectSSL(self, *a, **kw)39 connector = MemoryConnector()40 self.connectors.append(connector)41 return connector42class ClientCreatorTests(TestCase):43 """44 Tests for L{twisted.internet.protocol.ClientCreator}.45 """46 def _basicConnectTest(self, check):47 """48 Helper for implementing a test to verify that one of the I{connect}49 methods of L{ClientCreator} passes the right arguments to the right50 reactor method.51 @param check: A function which will be invoked with a reactor and a52 L{ClientCreator} instance and which should call one of the53 L{ClientCreator}'s I{connect} methods and assert that all of its54 arguments except for the factory are passed on as expected to the55 reactor. The factory should be returned.56 """57 class SomeProtocol(Protocol):58 pass59 reactor = MemoryReactorWithConnectorsAndTime()60 cc = ClientCreator(reactor, SomeProtocol)61 factory = check(reactor, cc)62 protocol = factory.buildProtocol(None)63 self.assertIsInstance(protocol, SomeProtocol)64 def test_connectTCP(self):65 """66 L{ClientCreator.connectTCP} calls C{reactor.connectTCP} with the host67 and port information passed to it, and with a factory which will68 construct the protocol passed to L{ClientCreator.__init__}.69 """70 def check(reactor, cc):71 cc.connectTCP('example.com', 1234, 4321, ('1.2.3.4', 9876))72 host, port, factory, timeout, bindAddress = reactor.tcpClients.pop()73 self.assertEqual(host, 'example.com')74 self.assertEqual(port, 1234)75 self.assertEqual(timeout, 4321)76 self.assertEqual(bindAddress, ('1.2.3.4', 9876))77 return factory78 self._basicConnectTest(check)79 def test_connectUNIX(self):80 """81 L{ClientCreator.connectUNIX} calls C{reactor.connectUNIX} with the82 filename passed to it, and with a factory which will construct the83 protocol passed to L{ClientCreator.__init__}.84 """85 def check(reactor, cc):86 cc.connectUNIX('/foo/bar', 123, True)87 address, factory, timeout, checkPID = reactor.unixClients.pop()88 self.assertEqual(address, '/foo/bar')89 self.assertEqual(timeout, 123)90 self.assertEqual(checkPID, True)91 return factory92 self._basicConnectTest(check)93 def test_connectSSL(self):94 """95 L{ClientCreator.connectSSL} calls C{reactor.connectSSL} with the host,96 port, and context factory passed to it, and with a factory which will97 construct the protocol passed to L{ClientCreator.__init__}.98 """99 def check(reactor, cc):100 expectedContextFactory = object()101 cc.connectSSL('example.com', 1234, expectedContextFactory, 4321, ('4.3.2.1', 5678))102 host, port, factory, contextFactory, timeout, bindAddress = reactor.sslClients.pop()103 self.assertEqual(host, 'example.com')104 self.assertEqual(port, 1234)105 self.assertIdentical(contextFactory, expectedContextFactory)106 self.assertEqual(timeout, 4321)107 self.assertEqual(bindAddress, ('4.3.2.1', 5678))108 return factory109 self._basicConnectTest(check)110 def _cancelConnectTest(self, connect):111 """112 Helper for implementing a test to verify that cancellation of the113 L{Deferred} returned by one of L{ClientCreator}'s I{connect} methods is114 implemented to cancel the underlying connector.115 @param connect: A function which will be invoked with a L{ClientCreator}116 instance as an argument and which should call one its I{connect}117 methods and return the result.118 @return: A L{Deferred} which fires when the test is complete or fails if119 there is a problem.120 """121 reactor = MemoryReactorWithConnectorsAndTime()122 cc = ClientCreator(reactor, Protocol)123 d = connect(cc)124 connector = reactor.connectors.pop()125 self.assertFalse(connector._disconnected)126 d.cancel()127 self.assertTrue(connector._disconnected)128 return self.assertFailure(d, CancelledError)129 def test_cancelConnectTCP(self):130 """131 The L{Deferred} returned by L{ClientCreator.connectTCP} can be cancelled132 to abort the connection attempt before it completes.133 """134 def connect(cc):135 return cc.connectTCP('example.com', 1234)136 return self._cancelConnectTest(connect)137 def test_cancelConnectUNIX(self):138 """139 The L{Deferred} returned by L{ClientCreator.connectTCP} can be cancelled140 to abort the connection attempt before it completes.141 """142 def connect(cc):143 return cc.connectUNIX('/foo/bar')144 return self._cancelConnectTest(connect)145 def test_cancelConnectSSL(self):146 """147 The L{Deferred} returned by L{ClientCreator.connectTCP} can be cancelled148 to abort the connection attempt before it completes.149 """150 def connect(cc):151 return cc.connectSSL('example.com', 1234, object())152 return self._cancelConnectTest(connect)153 def _cancelConnectTimeoutTest(self, connect):154 """155 Like L{_cancelConnectTest}, but for the case where the L{Deferred} is156 cancelled after the connection is set up but before it is fired with the157 resulting protocol instance.158 """159 reactor = MemoryReactorWithConnectorsAndTime()160 cc = ClientCreator(reactor, Protocol)161 d = connect(reactor, cc)162 connector = reactor.connectors.pop()163 # Sanity check - there is an outstanding delayed call to fire the164 # Deferred.165 self.assertEqual(len(reactor.getDelayedCalls()), 1)166 # Cancel the Deferred, disconnecting the transport just set up and167 # cancelling the delayed call.168 d.cancel()169 self.assertEqual(reactor.getDelayedCalls(), [])170 # A real connector implementation is responsible for disconnecting the171 # transport as well. For our purposes, just check that someone told the172 # connector to disconnect.173 self.assertTrue(connector._disconnected)174 return self.assertFailure(d, CancelledError)175 def test_cancelConnectTCPTimeout(self):176 """177 L{ClientCreator.connectTCP} inserts a very short delayed call between178 the time the connection is established and the time the L{Deferred}179 returned from one of its connect methods actually fires. If the180 L{Deferred} is cancelled in this interval, the established connection is181 closed, the timeout is cancelled, and the L{Deferred} fails with182 L{CancelledError}.183 """184 def connect(reactor, cc):185 d = cc.connectTCP('example.com', 1234)186 host, port, factory, timeout, bindAddress = reactor.tcpClients.pop()187 protocol = factory.buildProtocol(None)188 transport = StringTransport()189 protocol.makeConnection(transport)190 return d191 return self._cancelConnectTimeoutTest(connect)192 def test_cancelConnectUNIXTimeout(self):193 """194 L{ClientCreator.connectUNIX} inserts a very short delayed call between195 the time the connection is established and the time the L{Deferred}196 returned from one of its connect methods actually fires. If the197 L{Deferred} is cancelled in this interval, the established connection is198 closed, the timeout is cancelled, and the L{Deferred} fails with199 L{CancelledError}.200 """201 def connect(reactor, cc):202 d = cc.connectUNIX('/foo/bar')203 address, factory, timeout, bindAddress = reactor.unixClients.pop()204 protocol = factory.buildProtocol(None)205 transport = StringTransport()206 protocol.makeConnection(transport)207 return d208 return self._cancelConnectTimeoutTest(connect)209 def test_cancelConnectSSLTimeout(self):210 """211 L{ClientCreator.connectSSL} inserts a very short delayed call between212 the time the connection is established and the time the L{Deferred}213 returned from one of its connect methods actually fires. If the214 L{Deferred} is cancelled in this interval, the established connection is215 closed, the timeout is cancelled, and the L{Deferred} fails with216 L{CancelledError}.217 """218 def connect(reactor, cc):219 d = cc.connectSSL('example.com', 1234, object())220 host, port, factory, contextFactory, timeout, bindADdress = reactor.sslClients.pop()221 protocol = factory.buildProtocol(None)222 transport = StringTransport()223 protocol.makeConnection(transport)224 return d225 return self._cancelConnectTimeoutTest(connect)226 def _cancelConnectFailedTimeoutTest(self, connect):227 """228 Like L{_cancelConnectTest}, but for the case where the L{Deferred} is229 cancelled after the connection attempt has failed but before it is fired230 with the resulting failure.231 """232 reactor = MemoryReactorWithConnectorsAndTime()233 cc = ClientCreator(reactor, Protocol)234 d, factory = connect(reactor, cc)235 connector = reactor.connectors.pop()236 factory.clientConnectionFailed(237 connector, Failure(Exception("Simulated failure")))238 # Sanity check - there is an outstanding delayed call to fire the239 # Deferred.240 self.assertEqual(len(reactor.getDelayedCalls()), 1)241 # Cancel the Deferred, cancelling the delayed call.242 d.cancel()243 self.assertEqual(reactor.getDelayedCalls(), [])244 return self.assertFailure(d, CancelledError)245 def test_cancelConnectTCPFailedTimeout(self):246 """247 Similar to L{test_cancelConnectTCPTimeout}, but for the case where the248 connection attempt fails.249 """250 def connect(reactor, cc):251 d = cc.connectTCP('example.com', 1234)252 host, port, factory, timeout, bindAddress = reactor.tcpClients.pop()253 return d, factory254 return self._cancelConnectFailedTimeoutTest(connect)255 def test_cancelConnectUNIXFailedTimeout(self):256 """257 Similar to L{test_cancelConnectUNIXTimeout}, but for the case where the258 connection attempt fails.259 """260 def connect(reactor, cc):261 d = cc.connectUNIX('/foo/bar')262 address, factory, timeout, bindAddress = reactor.unixClients.pop()263 return d, factory264 return self._cancelConnectFailedTimeoutTest(connect)265 def test_cancelConnectSSLFailedTimeout(self):266 """267 Similar to L{test_cancelConnectSSLTimeout}, but for the case where the268 connection attempt fails.269 """270 def connect(reactor, cc):271 d = cc.connectSSL('example.com', 1234, object())272 host, port, factory, contextFactory, timeout, bindADdress = reactor.sslClients.pop()273 return d, factory274 return self._cancelConnectFailedTimeoutTest(connect)275class ProtocolTests(TestCase):276 """277 Tests for L{twisted.internet.protocol.Protocol}.278 """279 def test_interfaces(self):280 """281 L{Protocol} instances provide L{IProtocol} and L{ILoggingContext}.282 """283 proto = Protocol()284 self.assertTrue(verifyObject(IProtocol, proto))...

Full Screen

Full Screen

test_sa_connection.py

Source:test_sa_connection.py Github

copy

Full Screen

...10 Column('id', Integer, nullable=False,11 primary_key=True),12 Column('name', String(255)))13@pytest.fixture()14def sa_connect(connection_creator):15 async def connect(**kwargs):16 conn = await connection_creator(**kwargs)17 await conn.autocommit(True)18 cur = await conn.cursor()19 await cur.execute("DROP TABLE IF EXISTS sa_tbl")20 await cur.execute("CREATE TABLE sa_tbl "21 "(id serial, name varchar(255))")22 await cur.execute("INSERT INTO sa_tbl (name)"23 "VALUES ('first')")24 await cur._connection.commit()25 # yield from cur.close()26 engine = mock.Mock()27 engine.dialect = sa.engine._dialect28 return sa.SAConnection(conn, engine)29 return connect30@pytest.mark.run_loop31async def test_execute_text_select(sa_connect):32 conn = await sa_connect()33 res = await conn.execute("SELECT * FROM sa_tbl;")34 assert isinstance(res.cursor, Cursor)35 assert ('id', 'name') == res.keys()36 rows = await res.fetchall()37 assert res.closed38 assert res.cursor is None39 assert 1 == len(rows)40 row = rows[0]41 assert 1 == row[0]42 assert 1 == row['id']43 assert 1 == row.id44 assert 'first' == row[1]45 assert 'first' == row['name']46 assert 'first' == row.name47 # TODO: fix this48 await conn._connection.commit()49@pytest.mark.run_loop50async def test_execute_sa_select(sa_connect):51 conn = await sa_connect()52 res = await conn.execute(tbl.select())53 assert isinstance(res.cursor, Cursor)54 assert ('id', 'name') == res.keys()55 rows = await res.fetchall()56 assert res.closed57 assert res.cursor is None58 assert res.returns_rows59 assert 1 == len(rows)60 row = rows[0]61 assert 1 == row[0]62 assert 1 == row['id']63 assert 1 == row.id64 assert 'first' == row[1]65 assert 'first' == row['name']66 assert 'first' == row.name67 # TODO: fix this68 await conn._connection.commit()69@pytest.mark.run_loop70async def test_execute_sa_insert_with_dict(sa_connect):71 conn = await sa_connect()72 await conn.execute(tbl.insert(), {"id": 2, "name": "second"})73 res = await conn.execute(tbl.select())74 rows = await res.fetchall()75 assert 2 == len(rows)76 assert (1, 'first') == rows[0]77 assert (2, 'second') == rows[1]78@pytest.mark.run_loop79async def test_execute_sa_insert_with_tuple(sa_connect):80 conn = await sa_connect()81 await conn.execute(tbl.insert(), (2, "second"))82 res = await conn.execute(tbl.select())83 rows = await res.fetchall()84 assert 2 == len(rows)85 assert (1, 'first') == rows[0]86 assert (2, 'second') == rows[1]87@pytest.mark.run_loop88async def test_execute_sa_insert_named_params(sa_connect):89 conn = await sa_connect()90 await conn.execute(tbl.insert(), id=2, name="second")91 res = await conn.execute(tbl.select())92 rows = await res.fetchall()93 assert 2 == len(rows)94 assert (1, 'first') == rows[0]95 assert (2, 'second') == rows[1]96@pytest.mark.run_loop97async def test_execute_sa_insert_positional_params(sa_connect):98 conn = await sa_connect()99 await conn.execute(tbl.insert(), 2, "second")100 res = await conn.execute(tbl.select())101 rows = await res.fetchall()102 assert 2 == len(rows)103 assert (1, 'first') == rows[0]104 assert (2, 'second') == rows[1]105@pytest.mark.run_loop106async def test_scalar(sa_connect):107 conn = await sa_connect()108 res = await conn.scalar(tbl.count())109 assert 1 == res110@pytest.mark.run_loop111async def test_scalar_None(sa_connect):112 conn = await sa_connect()113 await conn.execute(tbl.delete())114 res = await conn.scalar(tbl.select())115 assert res is None116 # TODO: fix this117 await conn._connection.commit()118@pytest.mark.run_loop119async def test_row_proxy(sa_connect):120 conn = await sa_connect()121 res = await conn.execute(tbl.select())122 rows = await res.fetchall()123 row = rows[0]124 row2 = await (await conn.execute(tbl.select())).first()125 assert 2 == len(row)126 assert ['id', 'name'] == list(row)127 assert 'id' in row128 assert 'unknown' not in row129 assert 'first' == row.name130 assert 'first' == row[tbl.c.name]131 with pytest.raises(AttributeError):132 row.unknown133 assert "(1, 'first')" == repr(row)134 assert (1, 'first') == row.as_tuple()135 assert (555, 'other') != row.as_tuple()136 assert row2 == row137 assert 5 != row138 # TODO: fix this139 await conn._connection.commit()140@pytest.mark.run_loop141async def test_insert(sa_connect):142 conn = await sa_connect()143 res = await conn.execute(tbl.insert().values(name='second'))144 assert 1 == res.rowcount145 assert 2 == res.lastrowid146@pytest.mark.run_loop147async def test_raw_insert(sa_connect):148 conn = await sa_connect()149 await conn.execute(150 "INSERT INTO sa_tbl (name) VALUES ('third')")151 res = await conn.execute(tbl.select())152 assert 2 == res.rowcount153 assert ('id', 'name') == res.keys()154 assert res.returns_rows155 rows = await res.fetchall()156 assert 2 == len(rows)157 assert 2 == rows[1].id158@pytest.mark.run_loop159async def test_raw_insert_with_params(sa_connect):160 conn = await sa_connect()161 res = await conn.execute(162 "INSERT INTO sa_tbl (id, name) VALUES (%s, %s)",163 2, 'third')164 res = await conn.execute(tbl.select())165 assert 2 == res.rowcount166 assert ('id', 'name') == res.keys()167 assert res.returns_rows168 rows = await res.fetchall()169 assert 2 == len(rows)170 assert 2 == rows[1].id171@pytest.mark.run_loop172async def test_raw_insert_with_params_dict(sa_connect):173 conn = await sa_connect()174 res = await conn.execute(175 "INSERT INTO sa_tbl (id, name) VALUES (%(id)s, %(name)s)",176 {'id': 2, 'name': 'third'})177 res = await conn.execute(tbl.select())178 assert 2 == res.rowcount179 assert ('id', 'name') == res.keys()180 assert res.returns_rows181 rows = await res.fetchall()182 assert 2 == len(rows)183 assert 2 == rows[1].id184@pytest.mark.run_loop185async def test_raw_insert_with_named_params(sa_connect):186 conn = await sa_connect()187 res = await conn.execute(188 "INSERT INTO sa_tbl (id, name) VALUES (%(id)s, %(name)s)",189 id=2, name='third')190 res = await conn.execute(tbl.select())191 assert 2 == res.rowcount192 assert ('id', 'name') == res.keys()193 assert res.returns_rows194 rows = await res.fetchall()195 assert 2 == len(rows)196 assert 2 == rows[1].id197@pytest.mark.run_loop198async def test_raw_insert_with_executemany(sa_connect):199 conn = await sa_connect()200 # with pytest.raises(sa.ArgumentError):201 await conn.execute(202 "INSERT INTO sa_tbl (id, name) VALUES (%(id)s, %(name)s)",203 [{"id": 2, "name": 'third'}, {"id": 3, "name": 'forth'}])204 await conn.execute(205 tbl.update().where(206 tbl.c.id == bindparam("id")207 ).values(208 {"name": bindparam("name")}209 ),210 [211 {"id": 2, "name": "t2"},212 {"id": 3, "name": "t3"}213 ]214 )215 with pytest.raises(sa.ArgumentError):216 await conn.execute(217 DropTable(tbl),218 [{}, {}]219 )220 with pytest.raises(sa.ArgumentError):221 await conn.execute(222 {},223 [{}, {}]224 )225@pytest.mark.run_loop226async def test_raw_select_with_wildcard(sa_connect):227 conn = await sa_connect()228 await conn.execute(229 'SELECT * FROM sa_tbl WHERE name LIKE "%test%"')230@pytest.mark.run_loop231async def test_delete(sa_connect):232 conn = await sa_connect()233 res = await conn.execute(tbl.delete().where(tbl.c.id == 1))234 assert () == res.keys()235 assert 1 == res.rowcount236 assert not res.returns_rows237 assert res.closed238 assert res.cursor is None239@pytest.mark.run_loop240async def test_double_close(sa_connect):241 conn = await sa_connect()242 res = await conn.execute("SELECT 1")243 await res.close()244 assert res.closed245 assert res.cursor is None246 await res.close()247 assert res.closed248 assert res.cursor is None249@pytest.mark.run_loop250@pytest.mark.skip("Find out how to close cursor on __del__ method")251async def test_weakrefs(sa_connect):252 conn = await sa_connect()253 assert 0 == len(conn._weak_results)254 res = await conn.execute("SELECT 1")255 assert 1 == len(conn._weak_results)256 cur = res.cursor257 assert not cur.closed258 # TODO: fix this, how close cursor if result was deleted259 # yield from cur.close()260 del res261 assert cur.closed262 assert 0 == len(conn._weak_results)263@pytest.mark.run_loop264async def test_fetchall(sa_connect):265 conn = await sa_connect()266 await conn.execute(tbl.insert().values(name='second'))267 res = await conn.execute(tbl.select())268 rows = await res.fetchall()269 assert 2 == len(rows)270 assert res.closed271 assert res.returns_rows272 assert [(1, 'first'), (2, 'second')] == rows273@pytest.mark.run_loop274async def test_fetchall_closed(sa_connect):275 conn = await sa_connect()276 await conn.execute(tbl.insert().values(name='second'))277 res = await conn.execute(tbl.select())278 await res.close()279 with pytest.raises(sa.ResourceClosedError):280 await res.fetchall()281@pytest.mark.run_loop282async def test_fetchall_not_returns_rows(sa_connect):283 conn = await sa_connect()284 res = await conn.execute(tbl.delete())285 with pytest.raises(sa.ResourceClosedError):286 await res.fetchall()287@pytest.mark.run_loop288async def test_fetchone_closed(sa_connect):289 conn = await sa_connect()290 await conn.execute(tbl.insert().values(name='second'))291 res = await conn.execute(tbl.select())292 await res.close()293 with pytest.raises(sa.ResourceClosedError):294 await res.fetchone()295@pytest.mark.run_loop296async def test_first_not_returns_rows(sa_connect):297 conn = await sa_connect()298 res = await conn.execute(tbl.delete())299 with pytest.raises(sa.ResourceClosedError):300 await res.first()301@pytest.mark.run_loop302async def test_fetchmany(sa_connect):303 conn = await sa_connect()304 await conn.execute(tbl.insert().values(name='second'))305 res = await conn.execute(tbl.select())306 rows = await res.fetchmany()307 assert 1 == len(rows)308 assert not res.closed309 assert res.returns_rows310 assert [(1, 'first')] == rows311@pytest.mark.run_loop312async def test_fetchmany_with_size(sa_connect):313 conn = await sa_connect()314 await conn.execute(tbl.insert().values(name='second'))315 res = await conn.execute(tbl.select())316 rows = await res.fetchmany(100)317 assert 2 == len(rows)318 assert not res.closed319 assert res.returns_rows320 assert [(1, 'first'), (2, 'second')] == rows321@pytest.mark.run_loop322async def test_fetchmany_closed(sa_connect):323 conn = await sa_connect()324 await conn.execute(tbl.insert().values(name='second'))325 res = await conn.execute(tbl.select())326 await res.close()327 with pytest.raises(sa.ResourceClosedError):328 await res.fetchmany()329@pytest.mark.run_loop330async def test_fetchmany_with_size_closed(sa_connect):331 conn = await sa_connect()332 await conn.execute(tbl.insert().values(name='second'))333 res = await conn.execute(tbl.select())334 await res.close()335 with pytest.raises(sa.ResourceClosedError):336 await res.fetchmany(5555)337@pytest.mark.run_loop338async def test_fetchmany_not_returns_rows(sa_connect):339 conn = await sa_connect()340 res = await conn.execute(tbl.delete())341 with pytest.raises(sa.ResourceClosedError):342 await res.fetchmany()343@pytest.mark.run_loop344async def test_fetchmany_close_after_last_read(sa_connect):345 conn = await sa_connect()346 res = await conn.execute(tbl.select())347 rows = await res.fetchmany()348 assert 1 == len(rows)349 assert not res.closed350 assert res.returns_rows351 assert [(1, 'first')] == rows352 rows2 = await res.fetchmany()353 assert 0 == len(rows2)354 assert res.closed355@pytest.mark.run_loop356async def test_create_table(sa_connect):357 conn = await sa_connect()358 res = await conn.execute(DropTable(tbl))359 with pytest.raises(sa.ResourceClosedError):360 await res.fetchmany()361 with pytest.raises(aiomysql.ProgrammingError):362 await conn.execute("SELECT * FROM sa_tbl")363 res = await conn.execute(CreateTable(tbl))364 with pytest.raises(sa.ResourceClosedError):365 await res.fetchmany()366 res = await conn.execute("SELECT * FROM sa_tbl")...

Full Screen

Full Screen

tcpclient_test.py

Source:tcpclient_test.py Github

copy

Full Screen

...65 families = set(addr[0] for addr in addrinfo)66 if socket.AF_INET6 not in families:67 self.skipTest("localhost does not resolve to ipv6")68 @gen_test69 def do_test_connect(self, family, host):70 port = self.start_server(family)71 stream = yield self.client.connect(host, port)72 with closing(stream):73 stream.write(b"hello")74 data = yield self.server.streams[0].read_bytes(5)75 self.assertEqual(data, b"hello")76 def test_connect_ipv4_ipv4(self):77 self.do_test_connect(socket.AF_INET, '127.0.0.1')78 def test_connect_ipv4_dual(self):79 self.do_test_connect(socket.AF_INET, 'localhost')80 @skipIfNoIPv681 def test_connect_ipv6_ipv6(self):82 self.skipIfLocalhostV4()83 self.do_test_connect(socket.AF_INET6, '::1')84 @skipIfNoIPv685 def test_connect_ipv6_dual(self):86 self.skipIfLocalhostV4()87 if Resolver.configured_class().__name__.endswith('TwistedResolver'):88 self.skipTest('TwistedResolver does not support multiple addresses')89 self.do_test_connect(socket.AF_INET6, 'localhost')90 def test_connect_unspec_ipv4(self):91 self.do_test_connect(socket.AF_UNSPEC, '127.0.0.1')92 @skipIfNoIPv693 def test_connect_unspec_ipv6(self):94 self.skipIfLocalhostV4()95 self.do_test_connect(socket.AF_UNSPEC, '::1')96 def test_connect_unspec_dual(self):97 self.do_test_connect(socket.AF_UNSPEC, 'localhost')98 @gen_test99 def test_refused_ipv4(self):100 cleanup_func, port = refusing_port()101 self.addCleanup(cleanup_func)102 with self.assertRaises(IOError):103 yield self.client.connect('127.0.0.1', port)104class TestConnectorSplit(unittest.TestCase):105 def test_one_family(self):106 # These addresses aren't in the right format, but split doesn't care.107 primary, secondary = _Connector.split(108 [(AF1, 'a'),109 (AF1, 'b')])110 self.assertEqual(primary, [(AF1, 'a'),111 (AF1, 'b')])112 self.assertEqual(secondary, [])113 def test_mixed(self):114 primary, secondary = _Connector.split(115 [(AF1, 'a'),116 (AF2, 'b'),117 (AF1, 'c'),118 (AF2, 'd')])119 self.assertEqual(primary, [(AF1, 'a'), (AF1, 'c')])120 self.assertEqual(secondary, [(AF2, 'b'), (AF2, 'd')])121class ConnectorTest(AsyncTestCase):122 class FakeStream(object):123 def __init__(self):124 self.closed = False125 def close(self):126 self.closed = True127 def setUp(self):128 super(ConnectorTest, self).setUp()129 self.connect_futures = {}130 self.streams = {}131 self.addrinfo = [(AF1, 'a'), (AF1, 'b'),132 (AF2, 'c'), (AF2, 'd')]133 def tearDown(self):134 # Unless explicitly checked (and popped) in the test, we shouldn't135 # be closing any streams136 for stream in self.streams.values():137 self.assertFalse(stream.closed)138 super(ConnectorTest, self).tearDown()139 def create_stream(self, af, addr):140 future = Future()141 self.connect_futures[(af, addr)] = future142 return future143 def assert_pending(self, *keys):144 self.assertEqual(sorted(self.connect_futures.keys()), sorted(keys))145 def resolve_connect(self, af, addr, success):146 future = self.connect_futures.pop((af, addr))147 if success:148 self.streams[addr] = ConnectorTest.FakeStream()149 future.set_result(self.streams[addr])150 else:151 future.set_exception(IOError())152 def start_connect(self, addrinfo):153 conn = _Connector(addrinfo, self.io_loop, self.create_stream)154 # Give it a huge timeout; we'll trigger timeouts manually.155 future = conn.start(3600)156 return conn, future157 def test_immediate_success(self):158 conn, future = self.start_connect(self.addrinfo)159 self.assertEqual(list(self.connect_futures.keys()),160 [(AF1, 'a')])161 self.resolve_connect(AF1, 'a', True)162 self.assertEqual(future.result(), (AF1, 'a', self.streams['a']))163 def test_immediate_failure(self):164 # Fail with just one address.165 conn, future = self.start_connect([(AF1, 'a')])166 self.assert_pending((AF1, 'a'))167 self.resolve_connect(AF1, 'a', False)168 self.assertRaises(IOError, future.result)169 def test_one_family_second_try(self):170 conn, future = self.start_connect([(AF1, 'a'), (AF1, 'b')])171 self.assert_pending((AF1, 'a'))172 self.resolve_connect(AF1, 'a', False)173 self.assert_pending((AF1, 'b'))174 self.resolve_connect(AF1, 'b', True)175 self.assertEqual(future.result(), (AF1, 'b', self.streams['b']))176 def test_one_family_second_try_failure(self):177 conn, future = self.start_connect([(AF1, 'a'), (AF1, 'b')])178 self.assert_pending((AF1, 'a'))179 self.resolve_connect(AF1, 'a', False)180 self.assert_pending((AF1, 'b'))181 self.resolve_connect(AF1, 'b', False)182 self.assertRaises(IOError, future.result)183 def test_one_family_second_try_timeout(self):184 conn, future = self.start_connect([(AF1, 'a'), (AF1, 'b')])185 self.assert_pending((AF1, 'a'))186 # trigger the timeout while the first lookup is pending;187 # nothing happens.188 conn.on_timeout()189 self.assert_pending((AF1, 'a'))190 self.resolve_connect(AF1, 'a', False)191 self.assert_pending((AF1, 'b'))192 self.resolve_connect(AF1, 'b', True)193 self.assertEqual(future.result(), (AF1, 'b', self.streams['b']))194 def test_two_families_immediate_failure(self):195 conn, future = self.start_connect(self.addrinfo)196 self.assert_pending((AF1, 'a'))197 self.resolve_connect(AF1, 'a', False)198 self.assert_pending((AF1, 'b'), (AF2, 'c'))199 self.resolve_connect(AF1, 'b', False)200 self.resolve_connect(AF2, 'c', True)201 self.assertEqual(future.result(), (AF2, 'c', self.streams['c']))202 def test_two_families_timeout(self):203 conn, future = self.start_connect(self.addrinfo)204 self.assert_pending((AF1, 'a'))205 conn.on_timeout()206 self.assert_pending((AF1, 'a'), (AF2, 'c'))207 self.resolve_connect(AF2, 'c', True)208 self.assertEqual(future.result(), (AF2, 'c', self.streams['c']))209 # resolving 'a' after the connection has completed doesn't start 'b'210 self.resolve_connect(AF1, 'a', False)211 self.assert_pending()212 def test_success_after_timeout(self):213 conn, future = self.start_connect(self.addrinfo)214 self.assert_pending((AF1, 'a'))215 conn.on_timeout()216 self.assert_pending((AF1, 'a'), (AF2, 'c'))217 self.resolve_connect(AF1, 'a', True)218 self.assertEqual(future.result(), (AF1, 'a', self.streams['a']))219 # resolving 'c' after completion closes the connection.220 self.resolve_connect(AF2, 'c', True)221 self.assertTrue(self.streams.pop('c').closed)222 def test_all_fail(self):223 conn, future = self.start_connect(self.addrinfo)224 self.assert_pending((AF1, 'a'))225 conn.on_timeout()226 self.assert_pending((AF1, 'a'), (AF2, 'c'))227 self.resolve_connect(AF2, 'c', False)228 self.assert_pending((AF1, 'a'), (AF2, 'd'))229 self.resolve_connect(AF2, 'd', False)230 # one queue is now empty231 self.assert_pending((AF1, 'a'))232 self.resolve_connect(AF1, 'a', False)233 self.assert_pending((AF1, 'b'))234 self.assertFalse(future.done())235 self.resolve_connect(AF1, 'b', False)...

Full Screen

Full Screen

connect_control.py

Source:connect_control.py Github

copy

Full Screen

...104connect_fail_time = 0105scan_allow_time = 0106block_delay = 5107scan_sleep_time = 600 # Need examination108def allow_connect():109 global connect_allow_time110 if time.time() < connect_allow_time:111 return False112 else:113 return True114def allow_scan():115 global scan_allow_time116 if not allow_connect:117 return False118 if time.time() < scan_allow_time:119 return False120 else:121 return True122def fall_into_honeypot():...

Full Screen

Full Screen

chromeos_wifi_compliance.py

Source:chromeos_wifi_compliance.py Github

copy

Full Screen

1#!/usr/bin/env python2# Copyright (c) 2011 The Chromium Authors. All rights reserved.3# Use of this source code is governed by a BSD-style license that can be4# found in the LICENSE file.5import pyauto_functional6import chromeos_network # pyauto_functional must come before chromeos_network7class ChromeosWifiCompliance(chromeos_network.PyNetworkUITest):8 """Tests for ChromeOS wifi complaince.9 These tests should be run within vacinity of the power strip where the wifi10 routers are attached.11 """12 def _BasicConnectRouterCompliance(self, router_name):13 """Generic basic test routine for connecting to a router.14 Args:15 router_name: The name of the router.16 """17 self.InitWifiPowerStrip()18 router = self.GetRouterConfig(router_name)19 self.RouterPower(router_name, True)20 # If the wifi network is expected to be invisible, the following21 # line should timeout which is expected.22 wifi_visible = self.WaitUntilWifiNetworkAvailable(router['ssid'],23 is_hidden=router.get('hidden'))24 # Note, we expect wifi_visible and 'hidden' status to be opposites.25 # The test fails if the network visibility is not as expected.26 if wifi_visible == router.get('hidden', False):27 self.fail('We expected wifi network "%s" to be %s, but it was not.' %28 (router['ssid'],29 {True: 'hidden', False: 'visible'}[router.get('hidden',30 False)]))31 # Verify connect did not have any errors.32 error = self.ConnectToWifiRouter(router_name)33 self.assertFalse(error, 'Failed to connect to wifi network %s. '34 'Reason: %s.' % (router['ssid'], error))35 # Verify the network we connected to.36 ssid = self.GetConnectedWifi()37 self.assertEqual(ssid, router['ssid'],38 'Did not successfully connect to wifi network %s.' % ssid)39 self.DisconnectFromWifiNetwork()40 def testConnectBelkinG(self):41 """Test connecting to the Belkin G router."""42 self._BasicConnectRouterCompliance('Belkin_G')43 def testConnectBelkinNPlus(self):44 """Test connecting to the Belkin N+ router."""45 self._BasicConnectRouterCompliance('Belkin_N+')46 def testConnectDLinkN150(self):47 """Test connecting to the D-Link N150 router."""48 self._BasicConnectRouterCompliance('D-Link_N150')49 def testConnectLinksysE3000(self):50 """Test connecting to the Linksys E3000 router.51 The LinksysE3000 supports broadcasting of up to 2 SSID's.52 This test will try connecting to each of them one at a time.53 """54 self._BasicConnectRouterCompliance('LinksysE3000')55 self._BasicConnectRouterCompliance('LinksysE3000_2')56 def testConnectLinksysWRT54G2(self):57 """Test connecting to the Linksys WRT54G2 router."""58 self._BasicConnectRouterCompliance('Linksys_WRT54G2')59 def testConnectLinksysWRT54GL(self):60 """Test connecting to the LinksysWRT54GL router."""61 self._BasicConnectRouterCompliance('Linksys_WRT54GL')62 def testConnectNetgearN300(self):63 """Test connecting to the Netgear N300 router."""64 self._BasicConnectRouterCompliance('Netgear_N300')65 def testConnectNetgearWGR614(self):66 """Test connecting to the Netgear WGR 614 router."""67 self._BasicConnectRouterCompliance('Netgear_WGR614')68 def testConnectNfiniti(self):69 """Test connecting to the Nfiniti router."""70 self._BasicConnectRouterCompliance('Nfiniti')71 def testConnectSMCWBR145(self):72 """Test connecting to the SMC WBR 145 router."""73 self._BasicConnectRouterCompliance('SMC_WBR145')74 def testConnectTrendnet_639gr(self):75 """Test connecting to the Trendnet 639gr router.76 The LinksysE3000 supports broadcasting of up to 4 SSID's.77 This test will try connecting to each of them one at a time.78 """79 self._BasicConnectRouterCompliance('Trendnet_639gr')80 self._BasicConnectRouterCompliance('Trendnet_639gr_2')81 self._BasicConnectRouterCompliance('Trendnet_639gr_3')82 self._BasicConnectRouterCompliance('Trendnet_639gr_4')83if __name__ == '__main__':...

Full Screen

Full Screen

connect_sql.py

Source:connect_sql.py Github

copy

Full Screen

1import pymysql2class ConnectSql(object):3 '''def connect_tuqiang_sql(self):4 # 连接图强的第一台数据库5 connect = pymysql.connect(6 host='120.24.75.214',7 port=3306,8 user='tuqiang_query',9 passwd='tuqiang_query',10 db='tracker-web',11 charset='utf8'12 )13 return connect14 def connect_tuqiang_form(self):15 # 链接图强在线第二台数据库,主要查报表、告警16 connect = pymysql.connect(17 host='119.23.127.137',18 port=8066,19 user='test',20 passwd='test@123',21 db='his',22 charset='utf8'23 )24 return connect25 '''26 def connect_tuqiang_sql(self):27 # 连接图强测试环境的第一台数据库28 connect = pymysql.connect(29 host='172.16.10.103',30 port=3306,31 user='root',32 passwd='123456',33 db='tracker-web',34 charset='utf8'35 )36 return connect37 def connect_tuqiang_form(self):38 # 链接图强在线第二台数据库,主要查报表、告警39 connect = pymysql.connect(40 host='172.16.10.105',41 port=8066,42 user='jimi',43 passwd='jimi',44 db='his',45 charset='utf8'46 )...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test Suite', function() 2{3 it('My FirstTest case',function() {4 cy.get('.search-keyword').type('ca')5 cy.wait(2000)6 cy.get('.products').as('productLocator')7 cy.get('@productLocator').find('.product').should('have.length',4)8 cy.get('@productLocator').find('.product').eq(2).contains('ADD TO CART').click().then(function()9 {10 console.log('sf')11 })12 cy.get('@productLocator').find('.product').each(($el, index, $list) => {13 const textVeg=$el.find('h4.product-name').text()14 if(textVeg.includes('Cashews'))15 {16 $el.find('button').click()17 }18 })19 cy.get('.brand').should('have.text','GREENKART')20 cy.get('.brand').then(function(logoelement)21 {22 cy.log(logoelement.text())23 })24 cy.get('.brand').then(function(logoelement)25 {26 cy.log(logoelement.text())27 })28 cy.get('.brand').then(function(logoelement)29 {30 cy.log(logoelement.text())31 })32 cy.get('.brand').then(function(logoelement)33 {34 cy.log(logoelement.text())35 })36 cy.get('.brand').then(function(logoelement)37 {38 cy.log(logoelement.text())39 })40 cy.get('.brand').then(function(logoelement)41 {42 cy.log(logoelement.text())43 })44 cy.get('.brand').then(function(logoelement)45 {46 cy.log(logoelement.text())47 })48 cy.get('.brand').then(function(logoelement)49 {50 cy.log(logoelement.text())51 })52 cy.get('.brand').then(function(logoelement)53 {54 cy.log(logoelement.text())55 })56 cy.get('.brand').then(function(logoelement)57 {58 cy.log(logoelement.text())59 })60 })61})

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test Suite', function() 2{3it('My FirstTest case',function() {4cy.get('select').select('option2').should('have.value','option2')5cy.get('#autocomplete').type('ind')6cy.get('.ui-menu-item div').each(($el, index, $list) => {7 if($el.text()==="India")8 {9 $el.click()10 }11})12cy.get('#displayed-text').should('be.visible')13cy.get('#hide-textbox').click()14cy.get('#displayed-text').should('not.be.visible')15cy.get('#show-textbox').click()16cy.get('#displayed-text').should('be.visible')17cy.get('[value="radio2"]').check().should('be.checked')18cy.get('tr td:nth-child(2)').each(($el, index, $list) => {19 const text=$el.text()20 if(text.includes("Python"))21 {22 cy.get('tr td:nth-child(2)').eq(index).next().then(function(price)23 {24 const priceText=price.text()25 expect(priceText).to.equal('25')26 })27 }28})29cy.get('[class="mouse-hover-content"]').invoke('show')30cy.contains('Top').click()31cy.url().should('include','top')32cy.get('#alertbtn').click()33cy.on('window:alert',(str)=>34{35 expect(str).to.equal('Hello , share this practice page and share your knowledge')36})37cy.get('#confirmbtn').click()38cy.on('window:confirm',(str)=>39{40 expect(str).to.equal('Hello , Are you sure you want to confirm?')41})42})43})

Full Screen

Using AI Code Generation

copy

Full Screen

1Cypress.config('defaultCommandTimeout', 10000)2Cypress.config('responseTimeout', 10000)3Cypress.config('requestTimeout', 10000)4Cypress.config('viewportWidth', 1280)5Cypress.config('viewportHeight', 720)6Cypress.config('watchForFileChanges', true)7Cypress.config('waitForAnimations', true)8Cypress.config('animationDistanceThreshold', 5)

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('test', () => {2 it('test', () => {3 }).then(({ body }) => {4 localStorage.setItem('loggedUser', JSON.stringify(body))5 })6 })7})8const App = () => {9 const [user, setUser] = useState(null)10 useEffect(() => {11 const loggedUserJSON = window.localStorage.getItem('loggedUser')12 if (loggedUserJSON) {13 const user = JSON.parse(loggedUserJSON)14 setUser(user)15 blogService.setToken(user.token)16 }17 }, [])18 const handleLogin = async (userObject) => {19 try {20 const user = await loginService.login(userObject)21 window.localStorage.setItem('loggedUser', JSON.stringify(user))22 blogService.setToken(user.token)23 setUser(user)24 } catch (exception) {25 console.log(exception)26 }27 }28 const handleLogout = () => {29 window.localStorage.removeItem('loggedUser')30 setUser(null)31 }32 return (33 {user === null ? (34 <LoginForm handleLogin={handleLogin} />35 ) : (36 <p>{user.name} logged in</p>37 <button onClick={handleLogout}>logout</button>38 )}39}40const LoginForm = ({ handleLogin }) => {41 const [username, setUsername] = useState('')42 const [password, setPassword] = useState('')43 const handleUsernameChange = ({ target }) => {44 setUsername(target.value)45 }46 const handlePasswordChange = ({ target }) => {47 setPassword(target.value)48 }49 const login = (event) => {50 event.preventDefault()

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress 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