Added tests for Comms ACK messages
+import json
from nose.tools import *
from holoviews.element.comparison import ComparisonTestCase
@@ -17,13 +18,33 @@ class TestComm(ComparisonTestCase):
msg = 'Test'
self.assertEqual(Comm.decode(msg), msg)
- def test_on_msg(self):
+ def test_handle_message_error_reply(self):
def raise_error(msg):
- if msg == 'Error':
- raise Exception()
+ raise Exception('Test')
+ def assert_error(msg):
+ decoded = json.loads(msg)
+ self.assertEqual(decoded['msg_type'], "Error")
+ self.assertTrue(decoded['traceback'].endswith('Exception: Test'))
comm = Comm(None, target='Test', on_msg=raise_error)
- with self.assertRaises(Exception):
- comm._handle_msg('Error')
+ comm.send = assert_error
+ comm._handle_msg({})
+
+ def test_handle_message_ready_reply(self):
+ def assert_ready(msg):
+ self.assertEqual(json.loads(msg), {'msg_type': "Ready", 'content': ''})
+ comm = Comm(None, target='Test')
+ comm.send = assert_ready
+ comm._handle_msg({})
+
+ def test_handle_message_ready_reply_with_comms_target(self):
+ def assert_ready(msg):
+ decoded = json.loads(msg)
+ self.assertEqual(decoded, {'msg_type': "Ready", 'content': '',
+ 'comms_target': 'Testing target'})
+ comm = Comm(None, target='Test')
+ comm.send = assert_ready
+ comm._handle_msg({'comms_target': 'Testing target'})
+
class TestJupyterComm(ComparisonTestCase):
