Add test for socket printer
This commit is contained in:
parent
981f6cc66c
commit
a1e7a7cff8
1 changed files with 86 additions and 0 deletions
86
nemubot/message/printer/test_socket.py
Normal file
86
nemubot/message/printer/test_socket.py
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
# Nemubot is a smart and modulable IM bot.
|
||||||
|
# Copyright (C) 2012-2015 Mercier Pierre-Olivier
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from nemubot.message import Command, DirectAsk, Text
|
||||||
|
from nemubot.message.printer.socket import Socket as SocketVisitor
|
||||||
|
|
||||||
|
class TestSocketPrinter(unittest.TestCase):
|
||||||
|
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.msgs = [
|
||||||
|
# Texts
|
||||||
|
(
|
||||||
|
Text(message="TEXT",
|
||||||
|
),
|
||||||
|
"TEXT"
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Text(message="TEXT TEXT2",
|
||||||
|
),
|
||||||
|
"TEXT TEXT2"
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Text(message="TEXT @ARG=1 TEXT2",
|
||||||
|
),
|
||||||
|
"TEXT @ARG=1 TEXT2"
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
|
# DirectAsk
|
||||||
|
(
|
||||||
|
DirectAsk(message="TEXT",
|
||||||
|
designated="someone",
|
||||||
|
to=["#somechannel"]
|
||||||
|
),
|
||||||
|
"someone: TEXT"
|
||||||
|
),
|
||||||
|
(
|
||||||
|
# Private message to someone
|
||||||
|
DirectAsk(message="TEXT",
|
||||||
|
designated="someone",
|
||||||
|
to=["someone"]
|
||||||
|
),
|
||||||
|
"TEXT"
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
|
# Commands
|
||||||
|
(
|
||||||
|
Command(cmd="COMMAND",
|
||||||
|
),
|
||||||
|
"!COMMAND"
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Command(cmd="COMMAND",
|
||||||
|
args=["TEXT"],
|
||||||
|
),
|
||||||
|
"!COMMAND TEXT"
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_printer(self):
|
||||||
|
for msg, pp in self.msgs:
|
||||||
|
sv = SocketVisitor()
|
||||||
|
msg.accept(sv)
|
||||||
|
self.assertEqual(sv.pp, pp)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
Add table
Add a link
Reference in a new issue