コード例 #1
0
ファイル: test_component.py プロジェクト: forter/pystorm
 def test_read_message_unicode(self):
     inputs = [  # Task IDs
         '[12, 22, 24]\n',
         'end\n',
         # Incoming Tuple for bolt
         ('{ "id": "-6955786537413359385", "comp": "1", "stream": "1"'
          ', "task": 9, "tuple": ["snow white \uFFE6 the seven dwarfs"'
          ', "field2", 3]}\n'),
         'end\n',
         # next command for spout
         '{"command": "next"}\n',
         'end\n',
         # empty message, which should trigger sys.exit (end ignored)
         '',
         ''
     ]
     outputs = [json.loads(msg) for msg in inputs[::2] if msg]
     outputs.append('')
     component = Component(input_stream=BytesIO(
         ''.join(inputs).encode('utf8')),
                           output_stream=BytesIO())
     for output in outputs:
         log.info('Checking msg for %r', output)
         if output:
             msg = component.read_message()
             self.assertEqual(output, msg)
         else:
             with self.assertRaises(StormWentAwayError):
                 component.read_message()
コード例 #2
0
ファイル: test_component.py プロジェクト: forter/pystorm
    def test_read_split_message(self):
        # Make sure we can read something that's broken up into many "lines"
        inputs = [
            '{ "id": "-6955786537413359385", ', '"comp": "1", "stream": "1"\n',
            '\n', ', "task": 9, "tuple": ["snow white and the seven dwarfs", ',
            '"field2", 3]}\n', 'end\n'
        ]
        output = json.loads(''.join(inputs[:-1]))

        component = Component(input_stream=BytesIO(
            ''.join(inputs).encode('utf-8')),
                              output_stream=BytesIO())
        msg = component.read_message()
        self.assertEqual(output, msg)
コード例 #3
0
ファイル: test_component.py プロジェクト: pystorm/pystorm
 def test_read_message(self):
     inputs = [# Task IDs
               '[12, 22, 24]\n', 'end\n',
               # Incoming Tuple for bolt
               ('{ "id": "-6955786537413359385", "comp": "1", "stream": "1"'
                ', "task": 9, "tuple": ["snow white and the seven dwarfs", '
                '"field2", 3]}\n'), 'end\n',
               # next command for spout
               '{"command": "next"}\n', 'end\n',
               # empty message, which should trigger sys.exit (end ignored)
               '', '']
     outputs = [json.loads(msg) for msg in inputs[::2] if msg]
     outputs.append('')
     component = Component(input_stream=BytesIO(''.join(inputs).encode('utf-8')),
                           output_stream=BytesIO())
     for output in outputs:
         log.info('Checking msg for %r', output)
         if output:
             msg = component.read_message()
             self.assertEqual(output, msg)
         else:
             with self.assertRaises(StormWentAwayError):
                 component.read_message()
コード例 #4
0
ファイル: test_component.py プロジェクト: pystorm/pystorm
    def test_read_split_message(self):
        # Make sure we can read something that's broken up into many "lines"
        inputs = ['{ "id": "-6955786537413359385", ',
                  '"comp": "1", "stream": "1"\n',
                  '\n',
                  ', "task": 9, "tuple": ["snow white and the seven dwarfs", ',
                  '"field2", 3]}\n',
                  'end\n']
        output = json.loads(''.join(inputs[:-1]))

        component = Component(input_stream=BytesIO(''.join(inputs).encode('utf-8')),
                              output_stream=BytesIO())
        msg = component.read_message()
        self.assertEqual(output, msg)