示例#1
0
    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']))
 def test_log(self, send_message_mock):
     component = Component(input_stream=BytesIO(), output_stream=BytesIO())
     inputs = [("I am a robot monkey.", None, 2),
               ("I am a monkey who learned to talk.", 'warning', 3)]
     for msg, level, storm_level in inputs:
         component.output_stream.close()
         component.output_stream = component._wrap_stream(BytesIO())
         component.log(msg, level=level)
         send_message_mock.assert_called_with(component, {'command': 'log',
                                                          'msg': msg,
                                                          'level': storm_level})
示例#3
0
 def test_log(self, send_message_mock):
     component = Component(input_stream=BytesIO(), output_stream=BytesIO())
     inputs = [("I am a robot monkey.", None, 2),
               ("I am a monkey who learned to talk.", 'warning', 3)]
     for msg, level, storm_level in inputs:
         component.output_stream.close()
         component.output_stream = component._wrap_stream(BytesIO())
         component.log(msg, level=level)
         send_message_mock.assert_called_with(component, {'command': 'log',
                                                          'msg': msg,
                                                          'level': storm_level})
    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']))