This repository has been archived by the owner on Mar 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_robot.py
57 lines (47 loc) · 1.9 KB
/
test_robot.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
45
46
47
48
49
50
51
52
53
54
55
56
57
import asynctest
from asynctest.mock import call
from asynctest.mock import patch
from asynctest.mock import MagicMock
class TestRobot(asynctest.TestCase):
def setUp(self):
patcher1 = patch('charlesbot.robot.Robot.initialize_robot')
self.addCleanup(patcher1.stop)
self.mock_initialize_robot = patcher1.start()
from charlesbot.robot import Robot
self.robot = Robot()
@asynctest.ignore_loop
def test_exit_cleanly_no_plugins(self):
self.robot.plugin_list = []
self.robot.exit_cleanly()
self.assertEqual(self.robot.is_running(), False)
@asynctest.ignore_loop
def test_exit_cleanly_multiple_plugins(self):
plugin1 = MagicMock()
plugin2 = MagicMock()
self.robot.plugin_list = [plugin1, plugin2]
self.robot.exit_cleanly()
self.assertEqual(self.robot.is_running(), False)
self.assertFalse(plugin1.is_running)
self.assertFalse(plugin2.is_running)
def test_queue_message_empty_msg_1(self):
plugin1 = MagicMock()
msg = ""
yield from self.robot.queue_message(msg, plugin1)
self.assertEqual(plugin1.method_calls, [])
def test_queue_message_empty_msg_2(self):
plugin1 = MagicMock()
msg = []
yield from self.robot.queue_message(msg, plugin1)
self.assertEqual(plugin1.method_calls, [])
def test_queue_message_actual_msg_1(self):
plugin1 = MagicMock()
msg = "HelloPlugin"
yield from self.robot.queue_message(msg, plugin1)
expected = call.queue_message('HelloPlugin')
self.assertEqual(plugin1.method_calls, [expected])
def test_queue_message_actual_msg_2(self):
plugin1 = MagicMock()
msg = ["HelloPlugin"]
yield from self.robot.queue_message(msg, plugin1)
expected = call.queue_message(['HelloPlugin'])
self.assertEqual(plugin1.method_calls, [expected])