PageRenderTime 71ms CodeModel.GetById 13ms app.highlight 53ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/net/protocols/test_irc.py

https://bitbucket.org/prologic/circuits/
Python | 1011 lines | 706 code | 294 blank | 11 comment | 35 complexity | 23d726671c28a13c9553cd6a8a2e5f21 MD5 | raw file
   1#!/usr/bin/env python
   2
   3from circuits import handler, Event, Component
   4from circuits.net.protocols.irc import strip, sourceJoin, sourceSplit, IRC
   5
   6from circuits.net.protocols.irc import (
   7        PASS, USER, NICK, PING, PONG, QUIT,
   8        JOIN, PART, PRIVMSG, NOTICE, CTCP, CTCPREPLY,
   9        KICK, TOPIC, MODE, INVITE, NAMES)
  10
  11
  12class Read(Event):
  13    """Read Event"""
  14
  15
  16class App(Component):
  17
  18    def __init__(self):
  19        super(App, self).__init__()
  20
  21        IRC().register(self)
  22
  23        self.data = []
  24        self.events = []
  25
  26    @handler(False)
  27    def reset(self):
  28        self.data = []
  29        self.events = []
  30
  31    @handler(filter=True)
  32    def event(self, event, *args, **kwargs):
  33        self.events.append(event)
  34
  35    def write(self, data):
  36        self.data.append(data)
  37
  38
  39def pytest_funcarg__app(request):
  40    return request.cached_setup(
  41            setup=lambda: setupapp(request),
  42            scope="module")
  43
  44
  45def setupapp(request):
  46    app = App()
  47    while app:
  48        app.flush()
  49    app.reset()
  50    return app
  51
  52###
  53### Test Functions (utility)
  54###
  55
  56
  57def test_strip():
  58    s = ":\x01\x02test\x02\x01"
  59    s = strip(s)
  60    assert s == "\x01\x02test\x02\x01"
  61
  62    s = ":\x01\x02test\x02\x01"
  63    s = strip(s, color=True)
  64    assert s == "test"
  65
  66
  67def test_sourceJoin():
  68    nick, ident, host = "test", "foo", "localhost"
  69    s = sourceJoin(nick, ident, host)
  70    assert s == "test!foo@localhost"
  71
  72
  73def test_sourceSplit():
  74    s = "test!foo@localhost"
  75    nick, ident, host = sourceSplit(s)
  76    assert nick == "test"
  77    assert ident == "foo"
  78    assert host == "localhost"
  79
  80    s = "test"
  81    nick, ident, host = sourceSplit(s)
  82    assert nick == "test"
  83    assert ident == None
  84    assert host == None
  85
  86###
  87### Test IRC Commands
  88###
  89
  90
  91def test_PASS(app):
  92    app.reset()
  93
  94    app.fire(PASS("secret"))
  95    while app:
  96        app.flush()
  97
  98    events = iter(app.events)
  99
 100    e = next(events)
 101    assert e.name == "PASS"
 102    assert e.args[0] == "secret"
 103
 104    e = next(events)
 105    assert e.name == "RAW"
 106    assert e.args[0] == "PASS secret"
 107
 108    e = next(events)
 109    assert e.name == "Write"
 110    assert e.args[0] == "PASS secret\r\n"
 111
 112    data = iter(app.data)
 113
 114    s = next(data)
 115    assert s == "PASS secret\r\n"
 116
 117
 118def test_USER(app):
 119    app.reset()
 120
 121    app.fire(USER("foo", "localhost", "localhost", "Test Client"))
 122    while app:
 123        app.flush()
 124
 125    events = iter(app.events)
 126
 127    e = next(events)
 128    assert e.name == "USER"
 129    assert e.args[0] == "foo"
 130    assert e.args[1] == "localhost"
 131    assert e.args[2] == "localhost"
 132    assert e.args[3] == "Test Client"
 133
 134    e = next(events)
 135    assert e.name == "RAW"
 136    assert e.args[0] == "USER foo \"localhost\" \"localhost\" :Test Client"
 137
 138    e = next(events)
 139    assert e.name == "Write"
 140    assert e.args[0] == "USER foo \"localhost\" \"localhost\" :Test Client\r\n"
 141
 142    data = iter(app.data)
 143
 144    s = next(data)
 145    assert s == "USER foo \"localhost\" \"localhost\" :Test Client\r\n"
 146
 147
 148def test_NICK(app):
 149    app.reset()
 150
 151    app.fire(NICK("test"))
 152    while app:
 153        app.flush()
 154
 155    events = iter(app.events)
 156
 157    e = next(events)
 158    assert e.name == "NICK"
 159    assert e.args[0] == "test"
 160
 161    e = next(events)
 162    assert e.name == "RAW"
 163    assert e.args[0] == "NICK test"
 164
 165    e = next(events)
 166    assert e.name == "Write"
 167    assert e.args[0] == "NICK test\r\n"
 168
 169    data = iter(app.data)
 170
 171    s = next(data)
 172    assert s == "NICK test\r\n"
 173
 174
 175def test_PING(app):
 176    app.reset()
 177
 178    app.fire(PING("localhost"))
 179    while app:
 180        app.flush()
 181
 182    events = iter(app.events)
 183
 184    e = next(events)
 185    assert e.name == "PING"
 186    assert e.args[0] == "localhost"
 187
 188    e = next(events)
 189    assert e.name == "RAW"
 190    assert e.args[0] == "PING :localhost"
 191
 192    e = next(events)
 193    assert e.name == "Write"
 194    assert e.args[0] == "PING :localhost\r\n"
 195
 196    data = iter(app.data)
 197
 198    s = next(data)
 199    assert s == "PING :localhost\r\n"
 200
 201
 202def test_PONG(app):
 203    app.reset()
 204
 205    app.fire(PONG("localhost"))
 206    while app:
 207        app.flush()
 208
 209    events = iter(app.events)
 210
 211    e = next(events)
 212    assert e.name == "PONG"
 213    assert e.args[0] == "localhost"
 214
 215    e = next(events)
 216    assert e.name == "RAW"
 217    assert e.args[0] == "PONG :localhost"
 218
 219    e = next(events)
 220    assert e.name == "Write"
 221    assert e.args[0] == "PONG :localhost\r\n"
 222
 223    data = iter(app.data)
 224
 225    s = next(data)
 226    assert s == "PONG :localhost\r\n"
 227
 228
 229def test_QUIT(app):
 230    app.reset()
 231
 232    app.fire(QUIT())
 233    while app:
 234        app.flush()
 235
 236    events = iter(app.events)
 237
 238    e = next(events)
 239    assert e.name == "QUIT"
 240    assert not e.args
 241
 242    e = next(events)
 243    assert e.name == "RAW"
 244    assert e.args[0] == "QUIT :Leaving"
 245
 246    e = next(events)
 247    assert e.name == "Write"
 248    assert e.args[0] == "QUIT :Leaving\r\n"
 249
 250    data = iter(app.data)
 251
 252    s = next(data)
 253    assert s == "QUIT :Leaving\r\n"
 254
 255    app.reset()
 256
 257    app.fire(QUIT("Test"))
 258    while app:
 259        app.flush()
 260
 261    events = iter(app.events)
 262
 263    e = next(events)
 264    assert e.name == "QUIT"
 265    assert e.args[0] == "Test"
 266
 267    e = next(events)
 268    assert e.name == "RAW"
 269    assert e.args[0] == "QUIT :Test"
 270
 271    e = next(events)
 272    assert e.name == "Write"
 273    assert e.args[0] == "QUIT :Test\r\n"
 274
 275    data = iter(app.data)
 276
 277    s = next(data)
 278    assert s == "QUIT :Test\r\n"
 279
 280
 281def test_JOIN(app):
 282    app.reset()
 283
 284    app.fire(JOIN("#test"))
 285    while app:
 286        app.flush()
 287
 288    events = iter(app.events)
 289
 290    e = next(events)
 291    assert e.name == "JOIN"
 292    assert e.args[0] == "#test"
 293
 294    e = next(events)
 295    assert e.name == "RAW"
 296    assert e.args[0] == "JOIN #test"
 297
 298    e = next(events)
 299    assert e.name == "Write"
 300    assert e.args[0] == "JOIN #test\r\n"
 301
 302    data = iter(app.data)
 303
 304    s = next(data)
 305    assert s == "JOIN #test\r\n"
 306
 307    app.reset()
 308
 309    app.fire(JOIN("#test", "secret"))
 310    while app:
 311        app.flush()
 312
 313    events = iter(app.events)
 314
 315    e = next(events)
 316    assert e.name == "JOIN"
 317    assert e.args[0] == "#test"
 318    assert e.args[1] == "secret"
 319
 320    e = next(events)
 321    assert e.name == "RAW"
 322    assert e.args[0] == "JOIN #test secret"
 323
 324    e = next(events)
 325    assert e.name == "Write"
 326    assert e.args[0] == "JOIN #test secret\r\n"
 327
 328    data = iter(app.data)
 329
 330    s = next(data)
 331    assert s == "JOIN #test secret\r\n"
 332
 333
 334def test_PART(app):
 335    app.reset()
 336
 337    app.fire(PART("#test"))
 338    while app:
 339        app.flush()
 340
 341    events = iter(app.events)
 342
 343    e = next(events)
 344    assert e.name == "PART"
 345    assert e.args[0] == "#test"
 346
 347    e = next(events)
 348    assert e.name == "RAW"
 349    assert e.args[0] == "PART #test :Leaving"
 350
 351    e = next(events)
 352    assert e.name == "Write"
 353    assert e.args[0] == "PART #test :Leaving\r\n"
 354
 355    data = iter(app.data)
 356
 357    s = next(data)
 358    assert s == "PART #test :Leaving\r\n"
 359
 360    app.reset()
 361
 362    app.fire(PART("#test", "Test"))
 363    while app:
 364        app.flush()
 365
 366    events = iter(app.events)
 367
 368    e = next(events)
 369    assert e.name == "PART"
 370    assert e.args[0] == "#test"
 371    assert e.args[1] == "Test"
 372
 373    e = next(events)
 374    assert e.name == "RAW"
 375    assert e.args[0] == "PART #test :Test"
 376
 377    e = next(events)
 378    assert e.name == "Write"
 379    assert e.args[0] == "PART #test :Test\r\n"
 380
 381    data = iter(app.data)
 382
 383    s = next(data)
 384    assert s == "PART #test :Test\r\n"
 385
 386
 387def test_PRIVMSG(app):
 388    app.reset()
 389
 390    app.fire(PRIVMSG("test", "Hello"))
 391    while app:
 392        app.flush()
 393
 394    events = iter(app.events)
 395
 396    e = next(events)
 397    assert e.name == "PRIVMSG"
 398    assert e.args[0] == "test"
 399    assert e.args[1] == "Hello"
 400
 401    e = next(events)
 402    assert e.name == "RAW"
 403    assert e.args[0] == "PRIVMSG test :Hello"
 404
 405    e = next(events)
 406    assert e.name == "Write"
 407    assert e.args[0] == "PRIVMSG test :Hello\r\n"
 408
 409    data = iter(app.data)
 410
 411    s = next(data)
 412    assert s == "PRIVMSG test :Hello\r\n"
 413
 414
 415def test_NOTICE(app):
 416    app.reset()
 417
 418    app.fire(NOTICE("test", "Hello"))
 419    while app:
 420        app.flush()
 421
 422    events = iter(app.events)
 423
 424    e = next(events)
 425    assert e.name == "NOTICE"
 426    assert e.args[0] == "test"
 427    assert e.args[1] == "Hello"
 428
 429    e = next(events)
 430    assert e.name == "RAW"
 431    assert e.args[0] == "NOTICE test :Hello"
 432
 433    e = next(events)
 434    assert e.name == "Write"
 435    assert e.args[0] == "NOTICE test :Hello\r\n"
 436
 437    data = iter(app.data)
 438
 439    s = next(data)
 440    assert s == "NOTICE test :Hello\r\n"
 441
 442
 443def test_CTCP(app):
 444    app.reset()
 445
 446    app.fire(CTCP("test", "PING", "1234567890"))
 447    while app:
 448        app.flush()
 449
 450    events = iter(app.events)
 451
 452    e = next(events)
 453    assert e.name == "CTCP"
 454    assert e.args[0] == "test"
 455    assert e.args[1] == "PING"
 456    assert e.args[2] == "1234567890"
 457
 458    e = next(events)
 459    assert e.name == "PRIVMSG"
 460    assert e.args[0] == "test"
 461    assert e.args[1] == "PING 1234567890"
 462
 463    e = next(events)
 464    assert e.name == "RAW"
 465    assert e.args[0] == "PRIVMSG test :PING 1234567890"
 466
 467    e = next(events)
 468    assert e.name == "Write"
 469    assert e.args[0] == "PRIVMSG test :PING 1234567890\r\n"
 470
 471    data = iter(app.data)
 472
 473    s = next(data)
 474    assert s == "PRIVMSG test :PING 1234567890\r\n"
 475
 476
 477def test_CTCPREPLY(app):
 478    app.reset()
 479
 480    app.fire(CTCPREPLY("test", "PING", "1234567890"))
 481    while app:
 482        app.flush()
 483
 484    events = iter(app.events)
 485
 486    e = next(events)
 487    assert e.name == "CTCPREPLY"
 488    assert e.args[0] == "test"
 489    assert e.args[1] == "PING"
 490    assert e.args[2] == "1234567890"
 491
 492    e = next(events)
 493    assert e.name == "NOTICE"
 494    assert e.args[0] == "test"
 495    assert e.args[1] == "PING 1234567890"
 496
 497    e = next(events)
 498    assert e.name == "RAW"
 499    assert e.args[0] == "NOTICE test :PING 1234567890"
 500
 501    e = next(events)
 502    assert e.name == "Write"
 503    assert e.args[0] == "NOTICE test :PING 1234567890\r\n"
 504
 505    data = iter(app.data)
 506
 507    s = next(data)
 508    assert s == "NOTICE test :PING 1234567890\r\n"
 509
 510
 511def test_KICK(app):
 512    app.reset()
 513
 514    app.fire(KICK("#test", "test"))
 515    while app:
 516        app.flush()
 517
 518    events = iter(app.events)
 519
 520    e = next(events)
 521    assert e.name == "KICK"
 522    assert e.args[0] == "#test"
 523    assert e.args[1] == "test"
 524
 525    e = next(events)
 526    assert e.name == "RAW"
 527    assert e.args[0] == "KICK #test test :"
 528
 529    e = next(events)
 530    assert e.name == "Write"
 531    assert e.args[0] == "KICK #test test :\r\n"
 532
 533    data = iter(app.data)
 534
 535    s = next(data)
 536    assert s == "KICK #test test :\r\n"
 537
 538    app.reset()
 539
 540    app.fire(KICK("#test", "test", "Bye"))
 541    while app:
 542        app.flush()
 543
 544    events = iter(app.events)
 545
 546    e = next(events)
 547    assert e.name == "KICK"
 548    assert e.args[0] == "#test"
 549    assert e.args[1] == "test"
 550    assert e.args[2] == "Bye"
 551
 552    e = next(events)
 553    assert e.name == "RAW"
 554    assert e.args[0] == "KICK #test test :Bye"
 555
 556    e = next(events)
 557    assert e.name == "Write"
 558    assert e.args[0] == "KICK #test test :Bye\r\n"
 559
 560    data = iter(app.data)
 561
 562    s = next(data)
 563    assert s == "KICK #test test :Bye\r\n"
 564
 565
 566def test_TOPIC(app):
 567    app.reset()
 568
 569    app.fire(TOPIC("#test", "Hello World!"))
 570    while app:
 571        app.flush()
 572
 573    events = iter(app.events)
 574
 575    e = next(events)
 576    assert e.name == "TOPIC"
 577    assert e.args[0] == "#test"
 578    assert e.args[1] == "Hello World!"
 579
 580    e = next(events)
 581    assert e.name == "RAW"
 582    assert e.args[0] == "TOPIC #test :Hello World!"
 583
 584    e = next(events)
 585    assert e.name == "Write"
 586    assert e.args[0] == "TOPIC #test :Hello World!\r\n"
 587
 588    data = iter(app.data)
 589
 590    s = next(data)
 591    assert s == "TOPIC #test :Hello World!\r\n"
 592
 593
 594def test_MODE(app):
 595    app.reset()
 596
 597    app.fire(MODE("+i"))
 598    while app:
 599        app.flush()
 600
 601    events = iter(app.events)
 602
 603    e = next(events)
 604    assert e.name == "MODE"
 605    assert e.args[0] == "+i"
 606
 607    e = next(events)
 608    assert e.name == "RAW"
 609    assert e.args[0] == "MODE :+i"
 610
 611    e = next(events)
 612    assert e.name == "Write"
 613    assert e.args[0] == "MODE :+i\r\n"
 614
 615    data = iter(app.data)
 616
 617    s = next(data)
 618    assert s == "MODE :+i\r\n"
 619
 620    app.reset()
 621
 622    app.fire(MODE("+o test", "#test"))
 623    while app:
 624        app.flush()
 625
 626    events = iter(app.events)
 627
 628    e = next(events)
 629    assert e.name == "MODE"
 630    assert e.args[0] == "+o test"
 631    assert e.args[1] == "#test"
 632
 633    e = next(events)
 634    assert e.name == "RAW"
 635    assert e.args[0] == "MODE #test :+o test"
 636
 637    e = next(events)
 638    assert e.name == "Write"
 639    assert e.args[0] == "MODE #test :+o test\r\n"
 640
 641    data = iter(app.data)
 642
 643    s = next(data)
 644    assert s == "MODE #test :+o test\r\n"
 645
 646
 647def test_INVITE(app):
 648    app.reset()
 649
 650    app.fire(INVITE("test", "#test"))
 651    while app:
 652        app.flush()
 653
 654    events = iter(app.events)
 655
 656    e = next(events)
 657    assert e.name == "INVITE"
 658    assert e.args[0] == "test"
 659    assert e.args[1] == "#test"
 660
 661    e = next(events)
 662    assert e.name == "RAW"
 663    assert e.args[0] == "INVITE test #test"
 664
 665    e = next(events)
 666    assert e.name == "Write"
 667    assert e.args[0] == "INVITE test #test\r\n"
 668
 669    data = iter(app.data)
 670
 671    s = next(data)
 672    assert s == "INVITE test #test\r\n"
 673
 674
 675def test_NAMES(app):
 676    app.reset()
 677
 678    app.fire(NAMES())
 679    while app:
 680        app.flush()
 681
 682    events = iter(app.events)
 683
 684    e = next(events)
 685    assert e.name == "NAMES"
 686    assert not e.args
 687
 688    e = next(events)
 689    assert e.name == "RAW"
 690    assert e.args[0] == "NAMES"
 691
 692    e = next(events)
 693    assert e.name == "Write"
 694    assert e.args[0] == "NAMES\r\n"
 695
 696    data = iter(app.data)
 697
 698    s = next(data)
 699    assert s == "NAMES\r\n"
 700
 701    app.reset()
 702
 703    app.fire(NAMES("#test"))
 704    while app:
 705        app.flush()
 706
 707    events = iter(app.events)
 708
 709    e = next(events)
 710    assert e.name == "NAMES"
 711    assert e.args[0] == "#test"
 712
 713    e = next(events)
 714    assert e.name == "RAW"
 715    assert e.args[0] == "NAMES #test"
 716
 717    e = next(events)
 718    assert e.name == "Write"
 719    assert e.args[0] == "NAMES #test\r\n"
 720
 721    data = iter(app.data)
 722
 723    s = next(data)
 724    assert s == "NAMES #test\r\n"
 725
 726###
 727### Test IRC Responses
 728###
 729
 730
 731def test_ping(app):
 732    app.reset()
 733
 734    app.fire(Read(b"PING :localhost\r\n"))
 735    while app:
 736        app.flush()
 737
 738    events = iter(app.events)
 739
 740    e = next(events)
 741    assert e.name == "Read"
 742    assert e.args[0] == b"PING :localhost\r\n"
 743
 744    e = next(events)
 745    assert e.name == "Line"
 746    assert e.args[0] == "PING :localhost"
 747
 748    e = next(events)
 749    assert e.name == "Ping"
 750    assert e.args[0] == "localhost"
 751
 752    e = next(events)
 753    assert e.name == "PONG"
 754    assert e.args[0] == "localhost"
 755
 756    e = next(events)
 757    assert e.name == "RAW"
 758    assert e.args[0] == "PONG :localhost"
 759
 760    e = next(events)
 761    assert e.name == "Write"
 762    assert e.args[0] == "PONG :localhost\r\n"
 763
 764    data = iter(app.data)
 765
 766    s = next(data)
 767    assert s == "PONG :localhost\r\n"
 768
 769
 770def test_numerics(app):
 771    app.reset()
 772
 773    app.fire(Read(b":localhost 001 test " +
 774        b":Welcome to the circuits Internet Relay Chat Network test\r\n"))
 775    while app:
 776        app.flush()
 777
 778    events = iter(app.events)
 779
 780    e = next(events)
 781    assert e.name == "Read"
 782    assert e.args[0] == b":localhost 001 test " \
 783            b":Welcome to the circuits Internet Relay Chat Network test\r\n"
 784
 785    e = next(events)
 786    assert e.name == "Line"
 787    assert e.args[0] == ":localhost 001 test " \
 788            ":Welcome to the circuits Internet Relay Chat Network test"
 789
 790    e = next(events)
 791    assert e.name == "Numeric"
 792    assert e.args[0] == "localhost"
 793    assert e.args[1] == "test"
 794    assert e.args[2] == 1
 795    assert e.args[3] == None
 796    assert e.args[4] == \
 797            "Welcome to the circuits Internet Relay Chat Network test"
 798
 799    app.reset()
 800
 801    app.fire(Read(b":localhost 332 test #test :Hello World!\r\n"))
 802    while app:
 803        app.flush()
 804
 805    events = iter(app.events)
 806
 807    e = next(events)
 808    assert e.name == "Read"
 809    assert e.args[0] == b":localhost 332 test #test :Hello World!\r\n"
 810
 811    e = next(events)
 812    assert e.name == "Line"
 813    assert e.args[0] == ":localhost 332 test #test :Hello World!"
 814
 815    e = next(events)
 816    assert e.name == "Numeric"
 817    assert e.args[0] == "localhost"
 818    assert e.args[1] == "test"
 819    assert e.args[2] == 332
 820    assert e.args[3] == "#test"
 821    assert e.args[4] == "Hello World!"
 822
 823
 824def test_ctcp(app):
 825    app.reset()
 826
 827    app.fire(Read(b":test!foo@localhost PRIVMSG test :TIME\r\n"))
 828    while app:
 829        app.flush()
 830
 831    events = iter(app.events)
 832
 833    e = next(events)
 834    assert e.name == "Read"
 835    assert e.args[0] == b":test!foo@localhost PRIVMSG test :TIME\r\n"
 836
 837    e = next(events)
 838    assert e.name == "Line"
 839    assert e.args[0] == ":test!foo@localhost PRIVMSG test :TIME"
 840
 841    e = next(events)
 842    assert e.name == "Ctcp"
 843    assert e.args[0] == ("test", "foo", "localhost")
 844    assert e.args[1] == "test"
 845    assert e.args[2] == "TIME"
 846    assert e.args[3] == ""
 847
 848
 849def test_message(app):
 850    app.reset()
 851
 852    app.fire(Read(b":test!foo@localhost PRIVMSG test :Hello\r\n"))
 853    while app:
 854        app.flush()
 855
 856    events = iter(app.events)
 857
 858    e = next(events)
 859    assert e.name == "Read"
 860    assert e.args[0] == b":test!foo@localhost PRIVMSG test :Hello\r\n"
 861
 862    e = next(events)
 863    assert e.name == "Line"
 864    assert e.args[0] == ":test!foo@localhost PRIVMSG test :Hello"
 865
 866    e = next(events)
 867    assert e.name == "Message"
 868    assert e.args[0] == ("test", "foo", "localhost")
 869    assert e.args[1] == "test"
 870    assert e.args[2] == "Hello"
 871
 872
 873def test_notice(app):
 874    app.reset()
 875
 876    app.fire(Read(b":test!foo@localhost NOTICE test :Hello\r\n"))
 877    while app:
 878        app.flush()
 879
 880    events = iter(app.events)
 881
 882    e = next(events)
 883    assert e.name == "Read"
 884    assert e.args[0] == b":test!foo@localhost NOTICE test :Hello\r\n"
 885
 886    e = next(events)
 887    assert e.name == "Line"
 888    assert e.args[0] == ":test!foo@localhost NOTICE test :Hello"
 889
 890    e = next(events)
 891    assert e.name == "Notice"
 892    assert e.args[0] == ("test", "foo", "localhost")
 893    assert e.args[1] == "test"
 894    assert e.args[2] == "Hello"
 895
 896
 897def test_join(app):
 898    app.reset()
 899
 900    app.fire(Read(b":test!foo@localhost JOIN #test\r\n"))
 901    while app:
 902        app.flush()
 903
 904    events = iter(app.events)
 905
 906    e = next(events)
 907    assert e.name == "Read"
 908    assert e.args[0] == b":test!foo@localhost JOIN #test\r\n"
 909
 910    e = next(events)
 911    assert e.name == "Line"
 912    assert e.args[0] == ":test!foo@localhost JOIN #test"
 913
 914    e = next(events)
 915    assert e.name == "Join"
 916    assert e.args[0] == ("test", "foo", "localhost")
 917    assert e.args[1] == "#test"
 918
 919
 920def test_part(app):
 921    app.reset()
 922
 923    app.fire(Read(b":test!foo@localhost PART #test :Leaving\r\n"))
 924    while app:
 925        app.flush()
 926
 927    events = iter(app.events)
 928
 929    e = next(events)
 930    assert e.name == "Read"
 931    assert e.args[0] == b":test!foo@localhost PART #test :Leaving\r\n"
 932
 933    e = next(events)
 934    assert e.name == "Line"
 935    assert e.args[0] == ":test!foo@localhost PART #test :Leaving"
 936
 937    e = next(events)
 938    assert e.name == "Part"
 939    assert e.args[0] == ("test", "foo", "localhost")
 940    assert e.args[1] == "#test"
 941    assert e.args[2] == "Leaving"
 942
 943
 944def test_quit(app):
 945    app.reset()
 946
 947    app.fire(Read(b":test!foo@localhost QUIT :Leaving\r\n"))
 948    while app:
 949        app.flush()
 950
 951    events = iter(app.events)
 952
 953    e = next(events)
 954    assert e.name == "Read"
 955    assert e.args[0] == b":test!foo@localhost QUIT :Leaving\r\n"
 956
 957    e = next(events)
 958    assert e.name == "Line"
 959    assert e.args[0] == ":test!foo@localhost QUIT :Leaving"
 960
 961    e = next(events)
 962    assert e.name == "Quit"
 963    assert e.args[0] == ("test", "foo", "localhost")
 964    assert e.args[1] == "Leaving"
 965
 966
 967def test_nick(app):
 968    app.reset()
 969
 970    app.fire(Read(b":test!foo@localhost NICK :test_\r\n"))
 971    while app:
 972        app.flush()
 973
 974    events = iter(app.events)
 975
 976    e = next(events)
 977    assert e.name == "Read"
 978    assert e.args[0] == b":test!foo@localhost NICK :test_\r\n"
 979
 980    e = next(events)
 981    assert e.name == "Line"
 982    assert e.args[0] == ":test!foo@localhost NICK :test_"
 983
 984    e = next(events)
 985    assert e.name == "Nick"
 986    assert e.args[0] == ("test", "foo", "localhost")
 987    assert e.args[1] == "test_"
 988
 989
 990def test_mode(app):
 991    app.reset()
 992
 993    app.fire(Read(b":test!foo@localhost MODE #test +o test\r\n"))
 994    while app:
 995        app.flush()
 996
 997    events = iter(app.events)
 998
 999    e = next(events)
1000    assert e.name == "Read"
1001    assert e.args[0] == b":test!foo@localhost MODE #test +o test\r\n"
1002
1003    e = next(events)
1004    assert e.name == "Line"
1005    assert e.args[0] == ":test!foo@localhost MODE #test +o test"
1006
1007    e = next(events)
1008    assert e.name == "Mode"
1009    assert e.args[0] == ("test", "foo", "localhost")
1010    assert e.args[1] == "#test"
1011    assert e.args[2] == "+o test"