test_irc.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Copyright (c) 2017–2018 crocoite contributors
  2. #
  3. # Permission is hereby granted, free of charge, to any person obtaining a copy
  4. # of this software and associated documentation files (the "Software"), to deal
  5. # in the Software without restriction, including without limitation the rights
  6. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. # copies of the Software, and to permit persons to whom the Software is
  8. # furnished to do so, subject to the following conditions:
  9. #
  10. # The above copyright notice and this permission notice shall be included in
  11. # all copies or substantial portions of the Software.
  12. #
  13. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. # THE SOFTWARE.
  20. import pytest
  21. from .irc import ArgparseBot, RefCountEvent, User, NickMode
  22. def test_mode_parse ():
  23. assert ArgparseBot.parseMode ('+a') == [('+', 'a')]
  24. assert ArgparseBot.parseMode ('+ab') == [('+', 'a'), ('+', 'b')]
  25. assert ArgparseBot.parseMode ('+a+b') == [('+', 'a'), ('+', 'b')]
  26. assert ArgparseBot.parseMode ('-a') == [('-', 'a')]
  27. assert ArgparseBot.parseMode ('-ab') == [('-', 'a'), ('-', 'b')]
  28. assert ArgparseBot.parseMode ('-a-b') == [('-', 'a'), ('-', 'b')]
  29. assert ArgparseBot.parseMode ('+a-b') == [('+', 'a'), ('-', 'b')]
  30. assert ArgparseBot.parseMode ('-a+b') == [('-', 'a'), ('+', 'b')]
  31. assert ArgparseBot.parseMode ('-ab+cd') == [('-', 'a'), ('-', 'b'), ('+', 'c'), ('+', 'd')]
  32. @pytest.fixture
  33. def event ():
  34. return RefCountEvent ()
  35. def test_refcountevent_arm (event):
  36. event.arm ()
  37. assert event.event.is_set ()
  38. def test_refcountevent_ctxmgr (event):
  39. with event:
  40. assert event.count == 1
  41. with event:
  42. assert event.count == 2
  43. def test_refcountevent_arm_with (event):
  44. with event:
  45. event.arm ()
  46. assert not event.event.is_set ()
  47. assert event.event.is_set ()
  48. def test_nick_mode ():
  49. a = User.fromName ('a')
  50. a2 = User.fromName ('a')
  51. a3 = User.fromName ('+a')
  52. b = User.fromName ('+b')
  53. c = User.fromName ('@c')
  54. # equality is based on name only, not mode
  55. assert a == a2
  56. assert a == a3
  57. assert a != b
  58. assert a.hasPriv (None) and not a.hasPriv (NickMode.voice) and not a.hasPriv (NickMode.operator)
  59. assert b.hasPriv (None) and b.hasPriv (NickMode.voice) and not b.hasPriv (NickMode.operator)
  60. assert c.hasPriv (None) and c.hasPriv (NickMode.voice) and c.hasPriv (NickMode.operator)