Skip to content

Commit

Permalink
Add test for sending unicode messages to test_component
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-blanchard committed Jun 23, 2015
1 parent aa5bb7e commit 5939657
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions test/streamparse/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import mock
from mock import patch

from six.moves import range

from streamparse.storm import Component, Tuple


Expand Down Expand Up @@ -281,6 +279,23 @@ def test_send_message(self):
# Check that we properly skip over invalid input
self.assertIsNone(component.send_message(['foo', 'bar']))

def test_send_message_unicode(self):
component = Component(input_stream=BytesIO(), output_stream=BytesIO())
inputs = [{"command": "emit", "id": 4, "stream": "", "task": 9,
"tuple": ["field\uFFE6", 2, 3]},
{"command": "log", "msg": "I am a robot monkey."},
{"command": "next"},
{"command": "sync"}]
for cmd in inputs:
component.output_stream.close()
component.output_stream = component._wrap_stream(BytesIO())
component.send_message(cmd)
self.assertEqual("{}\nend\n".format(json.dumps(cmd)).encode('utf-8'),
component.output_stream.buffer.getvalue())

# Check that we properly skip over invalid input
self.assertIsNone(component.send_message(['foo', 'bar']))

@patch.object(Component, 'send_message', autospec=True)
def test_log(self, send_message_mock):
component = Component(input_stream=BytesIO(), output_stream=BytesIO())
Expand Down

0 comments on commit 5939657

Please sign in to comment.