-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtest_command_parser.py
44 lines (30 loc) · 1.11 KB
/
test_command_parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import unittest
from commandparser import CommandParser
class CommandParserTest(unittest.TestCase):
"""docstring for CommandParserTest"""
def setUp(self):
self.cp = CommandParser()
self.called = False
def test_on_with_single_command(self):
def callback(arguments):
self.called = True
self.assertEqual(0, len(arguments))
self.cp.on("command", callback)
self.cp.take_command("command")
self.assertTrue(self.called)
def test_on_with_full_command(self):
def callback(arguments):
self.called = True
self.assertEqual(["1", "2"], arguments)
self.cp.on("delete_subscriber", callback)
self.cp.take_command("delete_subscriber 1 2")
self.assertTrue(self.called)
def test_on_with_command_not_found(self):
def callback(arguments):
self.called = True
self.cp.on("something", callback)
result = self.cp.take_command("something_else")
self.assertFalse(self.called)
self.assertIsNone(result)
if __name__ == '__main__':
unittest.main()