PageRenderTime 54ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/net/protocols/test_irc.py

https://bitbucket.org/prologic/circuits/
Python | 1011 lines | 706 code | 294 blank | 11 comment | 33 complexity | 23d726671c28a13c9553cd6a8a2e5f21 MD5 | raw file
  1. #!/usr/bin/env python
  2. from circuits import handler, Event, Component
  3. from circuits.net.protocols.irc import strip, sourceJoin, sourceSplit, IRC
  4. from circuits.net.protocols.irc import (
  5. PASS, USER, NICK, PING, PONG, QUIT,
  6. JOIN, PART, PRIVMSG, NOTICE, CTCP, CTCPREPLY,
  7. KICK, TOPIC, MODE, INVITE, NAMES)
  8. class Read(Event):
  9. """Read Event"""
  10. class App(Component):
  11. def __init__(self):
  12. super(App, self).__init__()
  13. IRC().register(self)
  14. self.data = []
  15. self.events = []
  16. @handler(False)
  17. def reset(self):
  18. self.data = []
  19. self.events = []
  20. @handler(filter=True)
  21. def event(self, event, *args, **kwargs):
  22. self.events.append(event)
  23. def write(self, data):
  24. self.data.append(data)
  25. def pytest_funcarg__app(request):
  26. return request.cached_setup(
  27. setup=lambda: setupapp(request),
  28. scope="module")
  29. def setupapp(request):
  30. app = App()
  31. while app:
  32. app.flush()
  33. app.reset()
  34. return app
  35. ###
  36. ### Test Functions (utility)
  37. ###
  38. def test_strip():
  39. s = ":\x01\x02test\x02\x01"
  40. s = strip(s)
  41. assert s == "\x01\x02test\x02\x01"
  42. s = ":\x01\x02test\x02\x01"
  43. s = strip(s, color=True)
  44. assert s == "test"
  45. def test_sourceJoin():
  46. nick, ident, host = "test", "foo", "localhost"
  47. s = sourceJoin(nick, ident, host)
  48. assert s == "test!foo@localhost"
  49. def test_sourceSplit():
  50. s = "test!foo@localhost"
  51. nick, ident, host = sourceSplit(s)
  52. assert nick == "test"
  53. assert ident == "foo"
  54. assert host == "localhost"
  55. s = "test"
  56. nick, ident, host = sourceSplit(s)
  57. assert nick == "test"
  58. assert ident == None
  59. assert host == None
  60. ###
  61. ### Test IRC Commands
  62. ###
  63. def test_PASS(app):
  64. app.reset()
  65. app.fire(PASS("secret"))
  66. while app:
  67. app.flush()
  68. events = iter(app.events)
  69. e = next(events)
  70. assert e.name == "PASS"
  71. assert e.args[0] == "secret"
  72. e = next(events)
  73. assert e.name == "RAW"
  74. assert e.args[0] == "PASS secret"
  75. e = next(events)
  76. assert e.name == "Write"
  77. assert e.args[0] == "PASS secret\r\n"
  78. data = iter(app.data)
  79. s = next(data)
  80. assert s == "PASS secret\r\n"
  81. def test_USER(app):
  82. app.reset()
  83. app.fire(USER("foo", "localhost", "localhost", "Test Client"))
  84. while app:
  85. app.flush()
  86. events = iter(app.events)
  87. e = next(events)
  88. assert e.name == "USER"
  89. assert e.args[0] == "foo"
  90. assert e.args[1] == "localhost"
  91. assert e.args[2] == "localhost"
  92. assert e.args[3] == "Test Client"
  93. e = next(events)
  94. assert e.name == "RAW"
  95. assert e.args[0] == "USER foo \"localhost\" \"localhost\" :Test Client"
  96. e = next(events)
  97. assert e.name == "Write"
  98. assert e.args[0] == "USER foo \"localhost\" \"localhost\" :Test Client\r\n"
  99. data = iter(app.data)
  100. s = next(data)
  101. assert s == "USER foo \"localhost\" \"localhost\" :Test Client\r\n"
  102. def test_NICK(app):
  103. app.reset()
  104. app.fire(NICK("test"))
  105. while app:
  106. app.flush()
  107. events = iter(app.events)
  108. e = next(events)
  109. assert e.name == "NICK"
  110. assert e.args[0] == "test"
  111. e = next(events)
  112. assert e.name == "RAW"
  113. assert e.args[0] == "NICK test"
  114. e = next(events)
  115. assert e.name == "Write"
  116. assert e.args[0] == "NICK test\r\n"
  117. data = iter(app.data)
  118. s = next(data)
  119. assert s == "NICK test\r\n"
  120. def test_PING(app):
  121. app.reset()
  122. app.fire(PING("localhost"))
  123. while app:
  124. app.flush()
  125. events = iter(app.events)
  126. e = next(events)
  127. assert e.name == "PING"
  128. assert e.args[0] == "localhost"
  129. e = next(events)
  130. assert e.name == "RAW"
  131. assert e.args[0] == "PING :localhost"
  132. e = next(events)
  133. assert e.name == "Write"
  134. assert e.args[0] == "PING :localhost\r\n"
  135. data = iter(app.data)
  136. s = next(data)
  137. assert s == "PING :localhost\r\n"
  138. def test_PONG(app):
  139. app.reset()
  140. app.fire(PONG("localhost"))
  141. while app:
  142. app.flush()
  143. events = iter(app.events)
  144. e = next(events)
  145. assert e.name == "PONG"
  146. assert e.args[0] == "localhost"
  147. e = next(events)
  148. assert e.name == "RAW"
  149. assert e.args[0] == "PONG :localhost"
  150. e = next(events)
  151. assert e.name == "Write"
  152. assert e.args[0] == "PONG :localhost\r\n"
  153. data = iter(app.data)
  154. s = next(data)
  155. assert s == "PONG :localhost\r\n"
  156. def test_QUIT(app):
  157. app.reset()
  158. app.fire(QUIT())
  159. while app:
  160. app.flush()
  161. events = iter(app.events)
  162. e = next(events)
  163. assert e.name == "QUIT"
  164. assert not e.args
  165. e = next(events)
  166. assert e.name == "RAW"
  167. assert e.args[0] == "QUIT :Leaving"
  168. e = next(events)
  169. assert e.name == "Write"
  170. assert e.args[0] == "QUIT :Leaving\r\n"
  171. data = iter(app.data)
  172. s = next(data)
  173. assert s == "QUIT :Leaving\r\n"
  174. app.reset()
  175. app.fire(QUIT("Test"))
  176. while app:
  177. app.flush()
  178. events = iter(app.events)
  179. e = next(events)
  180. assert e.name == "QUIT"
  181. assert e.args[0] == "Test"
  182. e = next(events)
  183. assert e.name == "RAW"
  184. assert e.args[0] == "QUIT :Test"
  185. e = next(events)
  186. assert e.name == "Write"
  187. assert e.args[0] == "QUIT :Test\r\n"
  188. data = iter(app.data)
  189. s = next(data)
  190. assert s == "QUIT :Test\r\n"
  191. def test_JOIN(app):
  192. app.reset()
  193. app.fire(JOIN("#test"))
  194. while app:
  195. app.flush()
  196. events = iter(app.events)
  197. e = next(events)
  198. assert e.name == "JOIN"
  199. assert e.args[0] == "#test"
  200. e = next(events)
  201. assert e.name == "RAW"
  202. assert e.args[0] == "JOIN #test"
  203. e = next(events)
  204. assert e.name == "Write"
  205. assert e.args[0] == "JOIN #test\r\n"
  206. data = iter(app.data)
  207. s = next(data)
  208. assert s == "JOIN #test\r\n"
  209. app.reset()
  210. app.fire(JOIN("#test", "secret"))
  211. while app:
  212. app.flush()
  213. events = iter(app.events)
  214. e = next(events)
  215. assert e.name == "JOIN"
  216. assert e.args[0] == "#test"
  217. assert e.args[1] == "secret"
  218. e = next(events)
  219. assert e.name == "RAW"
  220. assert e.args[0] == "JOIN #test secret"
  221. e = next(events)
  222. assert e.name == "Write"
  223. assert e.args[0] == "JOIN #test secret\r\n"
  224. data = iter(app.data)
  225. s = next(data)
  226. assert s == "JOIN #test secret\r\n"
  227. def test_PART(app):
  228. app.reset()
  229. app.fire(PART("#test"))
  230. while app:
  231. app.flush()
  232. events = iter(app.events)
  233. e = next(events)
  234. assert e.name == "PART"
  235. assert e.args[0] == "#test"
  236. e = next(events)
  237. assert e.name == "RAW"
  238. assert e.args[0] == "PART #test :Leaving"
  239. e = next(events)
  240. assert e.name == "Write"
  241. assert e.args[0] == "PART #test :Leaving\r\n"
  242. data = iter(app.data)
  243. s = next(data)
  244. assert s == "PART #test :Leaving\r\n"
  245. app.reset()
  246. app.fire(PART("#test", "Test"))
  247. while app:
  248. app.flush()
  249. events = iter(app.events)
  250. e = next(events)
  251. assert e.name == "PART"
  252. assert e.args[0] == "#test"
  253. assert e.args[1] == "Test"
  254. e = next(events)
  255. assert e.name == "RAW"
  256. assert e.args[0] == "PART #test :Test"
  257. e = next(events)
  258. assert e.name == "Write"
  259. assert e.args[0] == "PART #test :Test\r\n"
  260. data = iter(app.data)
  261. s = next(data)
  262. assert s == "PART #test :Test\r\n"
  263. def test_PRIVMSG(app):
  264. app.reset()
  265. app.fire(PRIVMSG("test", "Hello"))
  266. while app:
  267. app.flush()
  268. events = iter(app.events)
  269. e = next(events)
  270. assert e.name == "PRIVMSG"
  271. assert e.args[0] == "test"
  272. assert e.args[1] == "Hello"
  273. e = next(events)
  274. assert e.name == "RAW"
  275. assert e.args[0] == "PRIVMSG test :Hello"
  276. e = next(events)
  277. assert e.name == "Write"
  278. assert e.args[0] == "PRIVMSG test :Hello\r\n"
  279. data = iter(app.data)
  280. s = next(data)
  281. assert s == "PRIVMSG test :Hello\r\n"
  282. def test_NOTICE(app):
  283. app.reset()
  284. app.fire(NOTICE("test", "Hello"))
  285. while app:
  286. app.flush()
  287. events = iter(app.events)
  288. e = next(events)
  289. assert e.name == "NOTICE"
  290. assert e.args[0] == "test"
  291. assert e.args[1] == "Hello"
  292. e = next(events)
  293. assert e.name == "RAW"
  294. assert e.args[0] == "NOTICE test :Hello"
  295. e = next(events)
  296. assert e.name == "Write"
  297. assert e.args[0] == "NOTICE test :Hello\r\n"
  298. data = iter(app.data)
  299. s = next(data)
  300. assert s == "NOTICE test :Hello\r\n"
  301. def test_CTCP(app):
  302. app.reset()
  303. app.fire(CTCP("test", "PING", "1234567890"))
  304. while app:
  305. app.flush()
  306. events = iter(app.events)
  307. e = next(events)
  308. assert e.name == "CTCP"
  309. assert e.args[0] == "test"
  310. assert e.args[1] == "PING"
  311. assert e.args[2] == "1234567890"
  312. e = next(events)
  313. assert e.name == "PRIVMSG"
  314. assert e.args[0] == "test"
  315. assert e.args[1] == "PING 1234567890"
  316. e = next(events)
  317. assert e.name == "RAW"
  318. assert e.args[0] == "PRIVMSG test :PING 1234567890"
  319. e = next(events)
  320. assert e.name == "Write"
  321. assert e.args[0] == "PRIVMSG test :PING 1234567890\r\n"
  322. data = iter(app.data)
  323. s = next(data)
  324. assert s == "PRIVMSG test :PING 1234567890\r\n"
  325. def test_CTCPREPLY(app):
  326. app.reset()
  327. app.fire(CTCPREPLY("test", "PING", "1234567890"))
  328. while app:
  329. app.flush()
  330. events = iter(app.events)
  331. e = next(events)
  332. assert e.name == "CTCPREPLY"
  333. assert e.args[0] == "test"
  334. assert e.args[1] == "PING"
  335. assert e.args[2] == "1234567890"
  336. e = next(events)
  337. assert e.name == "NOTICE"
  338. assert e.args[0] == "test"
  339. assert e.args[1] == "PING 1234567890"
  340. e = next(events)
  341. assert e.name == "RAW"
  342. assert e.args[0] == "NOTICE test :PING 1234567890"
  343. e = next(events)
  344. assert e.name == "Write"
  345. assert e.args[0] == "NOTICE test :PING 1234567890\r\n"
  346. data = iter(app.data)
  347. s = next(data)
  348. assert s == "NOTICE test :PING 1234567890\r\n"
  349. def test_KICK(app):
  350. app.reset()
  351. app.fire(KICK("#test", "test"))
  352. while app:
  353. app.flush()
  354. events = iter(app.events)
  355. e = next(events)
  356. assert e.name == "KICK"
  357. assert e.args[0] == "#test"
  358. assert e.args[1] == "test"
  359. e = next(events)
  360. assert e.name == "RAW"
  361. assert e.args[0] == "KICK #test test :"
  362. e = next(events)
  363. assert e.name == "Write"
  364. assert e.args[0] == "KICK #test test :\r\n"
  365. data = iter(app.data)
  366. s = next(data)
  367. assert s == "KICK #test test :\r\n"
  368. app.reset()
  369. app.fire(KICK("#test", "test", "Bye"))
  370. while app:
  371. app.flush()
  372. events = iter(app.events)
  373. e = next(events)
  374. assert e.name == "KICK"
  375. assert e.args[0] == "#test"
  376. assert e.args[1] == "test"
  377. assert e.args[2] == "Bye"
  378. e = next(events)
  379. assert e.name == "RAW"
  380. assert e.args[0] == "KICK #test test :Bye"
  381. e = next(events)
  382. assert e.name == "Write"
  383. assert e.args[0] == "KICK #test test :Bye\r\n"
  384. data = iter(app.data)
  385. s = next(data)
  386. assert s == "KICK #test test :Bye\r\n"
  387. def test_TOPIC(app):
  388. app.reset()
  389. app.fire(TOPIC("#test", "Hello World!"))
  390. while app:
  391. app.flush()
  392. events = iter(app.events)
  393. e = next(events)
  394. assert e.name == "TOPIC"
  395. assert e.args[0] == "#test"
  396. assert e.args[1] == "Hello World!"
  397. e = next(events)
  398. assert e.name == "RAW"
  399. assert e.args[0] == "TOPIC #test :Hello World!"
  400. e = next(events)
  401. assert e.name == "Write"
  402. assert e.args[0] == "TOPIC #test :Hello World!\r\n"
  403. data = iter(app.data)
  404. s = next(data)
  405. assert s == "TOPIC #test :Hello World!\r\n"
  406. def test_MODE(app):
  407. app.reset()
  408. app.fire(MODE("+i"))
  409. while app:
  410. app.flush()
  411. events = iter(app.events)
  412. e = next(events)
  413. assert e.name == "MODE"
  414. assert e.args[0] == "+i"
  415. e = next(events)
  416. assert e.name == "RAW"
  417. assert e.args[0] == "MODE :+i"
  418. e = next(events)
  419. assert e.name == "Write"
  420. assert e.args[0] == "MODE :+i\r\n"
  421. data = iter(app.data)
  422. s = next(data)
  423. assert s == "MODE :+i\r\n"
  424. app.reset()
  425. app.fire(MODE("+o test", "#test"))
  426. while app:
  427. app.flush()
  428. events = iter(app.events)
  429. e = next(events)
  430. assert e.name == "MODE"
  431. assert e.args[0] == "+o test"
  432. assert e.args[1] == "#test"
  433. e = next(events)
  434. assert e.name == "RAW"
  435. assert e.args[0] == "MODE #test :+o test"
  436. e = next(events)
  437. assert e.name == "Write"
  438. assert e.args[0] == "MODE #test :+o test\r\n"
  439. data = iter(app.data)
  440. s = next(data)
  441. assert s == "MODE #test :+o test\r\n"
  442. def test_INVITE(app):
  443. app.reset()
  444. app.fire(INVITE("test", "#test"))
  445. while app:
  446. app.flush()
  447. events = iter(app.events)
  448. e = next(events)
  449. assert e.name == "INVITE"
  450. assert e.args[0] == "test"
  451. assert e.args[1] == "#test"
  452. e = next(events)
  453. assert e.name == "RAW"
  454. assert e.args[0] == "INVITE test #test"
  455. e = next(events)
  456. assert e.name == "Write"
  457. assert e.args[0] == "INVITE test #test\r\n"
  458. data = iter(app.data)
  459. s = next(data)
  460. assert s == "INVITE test #test\r\n"
  461. def test_NAMES(app):
  462. app.reset()
  463. app.fire(NAMES())
  464. while app:
  465. app.flush()
  466. events = iter(app.events)
  467. e = next(events)
  468. assert e.name == "NAMES"
  469. assert not e.args
  470. e = next(events)
  471. assert e.name == "RAW"
  472. assert e.args[0] == "NAMES"
  473. e = next(events)
  474. assert e.name == "Write"
  475. assert e.args[0] == "NAMES\r\n"
  476. data = iter(app.data)
  477. s = next(data)
  478. assert s == "NAMES\r\n"
  479. app.reset()
  480. app.fire(NAMES("#test"))
  481. while app:
  482. app.flush()
  483. events = iter(app.events)
  484. e = next(events)
  485. assert e.name == "NAMES"
  486. assert e.args[0] == "#test"
  487. e = next(events)
  488. assert e.name == "RAW"
  489. assert e.args[0] == "NAMES #test"
  490. e = next(events)
  491. assert e.name == "Write"
  492. assert e.args[0] == "NAMES #test\r\n"
  493. data = iter(app.data)
  494. s = next(data)
  495. assert s == "NAMES #test\r\n"
  496. ###
  497. ### Test IRC Responses
  498. ###
  499. def test_ping(app):
  500. app.reset()
  501. app.fire(Read(b"PING :localhost\r\n"))
  502. while app:
  503. app.flush()
  504. events = iter(app.events)
  505. e = next(events)
  506. assert e.name == "Read"
  507. assert e.args[0] == b"PING :localhost\r\n"
  508. e = next(events)
  509. assert e.name == "Line"
  510. assert e.args[0] == "PING :localhost"
  511. e = next(events)
  512. assert e.name == "Ping"
  513. assert e.args[0] == "localhost"
  514. e = next(events)
  515. assert e.name == "PONG"
  516. assert e.args[0] == "localhost"
  517. e = next(events)
  518. assert e.name == "RAW"
  519. assert e.args[0] == "PONG :localhost"
  520. e = next(events)
  521. assert e.name == "Write"
  522. assert e.args[0] == "PONG :localhost\r\n"
  523. data = iter(app.data)
  524. s = next(data)
  525. assert s == "PONG :localhost\r\n"
  526. def test_numerics(app):
  527. app.reset()
  528. app.fire(Read(b":localhost 001 test " +
  529. b":Welcome to the circuits Internet Relay Chat Network test\r\n"))
  530. while app:
  531. app.flush()
  532. events = iter(app.events)
  533. e = next(events)
  534. assert e.name == "Read"
  535. assert e.args[0] == b":localhost 001 test " \
  536. b":Welcome to the circuits Internet Relay Chat Network test\r\n"
  537. e = next(events)
  538. assert e.name == "Line"
  539. assert e.args[0] == ":localhost 001 test " \
  540. ":Welcome to the circuits Internet Relay Chat Network test"
  541. e = next(events)
  542. assert e.name == "Numeric"
  543. assert e.args[0] == "localhost"
  544. assert e.args[1] == "test"
  545. assert e.args[2] == 1
  546. assert e.args[3] == None
  547. assert e.args[4] == \
  548. "Welcome to the circuits Internet Relay Chat Network test"
  549. app.reset()
  550. app.fire(Read(b":localhost 332 test #test :Hello World!\r\n"))
  551. while app:
  552. app.flush()
  553. events = iter(app.events)
  554. e = next(events)
  555. assert e.name == "Read"
  556. assert e.args[0] == b":localhost 332 test #test :Hello World!\r\n"
  557. e = next(events)
  558. assert e.name == "Line"
  559. assert e.args[0] == ":localhost 332 test #test :Hello World!"
  560. e = next(events)
  561. assert e.name == "Numeric"
  562. assert e.args[0] == "localhost"
  563. assert e.args[1] == "test"
  564. assert e.args[2] == 332
  565. assert e.args[3] == "#test"
  566. assert e.args[4] == "Hello World!"
  567. def test_ctcp(app):
  568. app.reset()
  569. app.fire(Read(b":test!foo@localhost PRIVMSG test :TIME\r\n"))
  570. while app:
  571. app.flush()
  572. events = iter(app.events)
  573. e = next(events)
  574. assert e.name == "Read"
  575. assert e.args[0] == b":test!foo@localhost PRIVMSG test :TIME\r\n"
  576. e = next(events)
  577. assert e.name == "Line"
  578. assert e.args[0] == ":test!foo@localhost PRIVMSG test :TIME"
  579. e = next(events)
  580. assert e.name == "Ctcp"
  581. assert e.args[0] == ("test", "foo", "localhost")
  582. assert e.args[1] == "test"
  583. assert e.args[2] == "TIME"
  584. assert e.args[3] == ""
  585. def test_message(app):
  586. app.reset()
  587. app.fire(Read(b":test!foo@localhost PRIVMSG test :Hello\r\n"))
  588. while app:
  589. app.flush()
  590. events = iter(app.events)
  591. e = next(events)
  592. assert e.name == "Read"
  593. assert e.args[0] == b":test!foo@localhost PRIVMSG test :Hello\r\n"
  594. e = next(events)
  595. assert e.name == "Line"
  596. assert e.args[0] == ":test!foo@localhost PRIVMSG test :Hello"
  597. e = next(events)
  598. assert e.name == "Message"
  599. assert e.args[0] == ("test", "foo", "localhost")
  600. assert e.args[1] == "test"
  601. assert e.args[2] == "Hello"
  602. def test_notice(app):
  603. app.reset()
  604. app.fire(Read(b":test!foo@localhost NOTICE test :Hello\r\n"))
  605. while app:
  606. app.flush()
  607. events = iter(app.events)
  608. e = next(events)
  609. assert e.name == "Read"
  610. assert e.args[0] == b":test!foo@localhost NOTICE test :Hello\r\n"
  611. e = next(events)
  612. assert e.name == "Line"
  613. assert e.args[0] == ":test!foo@localhost NOTICE test :Hello"
  614. e = next(events)
  615. assert e.name == "Notice"
  616. assert e.args[0] == ("test", "foo", "localhost")
  617. assert e.args[1] == "test"
  618. assert e.args[2] == "Hello"
  619. def test_join(app):
  620. app.reset()
  621. app.fire(Read(b":test!foo@localhost JOIN #test\r\n"))
  622. while app:
  623. app.flush()
  624. events = iter(app.events)
  625. e = next(events)
  626. assert e.name == "Read"
  627. assert e.args[0] == b":test!foo@localhost JOIN #test\r\n"
  628. e = next(events)
  629. assert e.name == "Line"
  630. assert e.args[0] == ":test!foo@localhost JOIN #test"
  631. e = next(events)
  632. assert e.name == "Join"
  633. assert e.args[0] == ("test", "foo", "localhost")
  634. assert e.args[1] == "#test"
  635. def test_part(app):
  636. app.reset()
  637. app.fire(Read(b":test!foo@localhost PART #test :Leaving\r\n"))
  638. while app:
  639. app.flush()
  640. events = iter(app.events)
  641. e = next(events)
  642. assert e.name == "Read"
  643. assert e.args[0] == b":test!foo@localhost PART #test :Leaving\r\n"
  644. e = next(events)
  645. assert e.name == "Line"
  646. assert e.args[0] == ":test!foo@localhost PART #test :Leaving"
  647. e = next(events)
  648. assert e.name == "Part"
  649. assert e.args[0] == ("test", "foo", "localhost")
  650. assert e.args[1] == "#test"
  651. assert e.args[2] == "Leaving"
  652. def test_quit(app):
  653. app.reset()
  654. app.fire(Read(b":test!foo@localhost QUIT :Leaving\r\n"))
  655. while app:
  656. app.flush()
  657. events = iter(app.events)
  658. e = next(events)
  659. assert e.name == "Read"
  660. assert e.args[0] == b":test!foo@localhost QUIT :Leaving\r\n"
  661. e = next(events)
  662. assert e.name == "Line"
  663. assert e.args[0] == ":test!foo@localhost QUIT :Leaving"
  664. e = next(events)
  665. assert e.name == "Quit"
  666. assert e.args[0] == ("test", "foo", "localhost")
  667. assert e.args[1] == "Leaving"
  668. def test_nick(app):
  669. app.reset()
  670. app.fire(Read(b":test!foo@localhost NICK :test_\r\n"))
  671. while app:
  672. app.flush()
  673. events = iter(app.events)
  674. e = next(events)
  675. assert e.name == "Read"
  676. assert e.args[0] == b":test!foo@localhost NICK :test_\r\n"
  677. e = next(events)
  678. assert e.name == "Line"
  679. assert e.args[0] == ":test!foo@localhost NICK :test_"
  680. e = next(events)
  681. assert e.name == "Nick"
  682. assert e.args[0] == ("test", "foo", "localhost")
  683. assert e.args[1] == "test_"
  684. def test_mode(app):
  685. app.reset()
  686. app.fire(Read(b":test!foo@localhost MODE #test +o test\r\n"))
  687. while app:
  688. app.flush()
  689. events = iter(app.events)
  690. e = next(events)
  691. assert e.name == "Read"
  692. assert e.args[0] == b":test!foo@localhost MODE #test +o test\r\n"
  693. e = next(events)
  694. assert e.name == "Line"
  695. assert e.args[0] == ":test!foo@localhost MODE #test +o test"
  696. e = next(events)
  697. assert e.name == "Mode"
  698. assert e.args[0] == ("test", "foo", "localhost")
  699. assert e.args[1] == "#test"
  700. assert e.args[2] == "+o test"