コード例 #1
0
ファイル: test_component.py プロジェクト: Inuits/pystorm
 def test_exit_on_exception_true(self):
     handshake_dict = {"conf": self.conf,
                       "pidDir": ".",
                       "context": self.context}
     inputs = ["{}\n".format(json.dumps(handshake_dict)),
               "end\n"]
     component = Component(input_stream=BytesIO(''.join(inputs).encode('utf-8')),
                           output_stream=BytesIO())
     with self.assertRaises(SystemExit) as raises_fixture:
         component.run()
         assert raises_fixture.exception.value == 1
コード例 #2
0
ファイル: test_component.py プロジェクト: tchandrap/pystorm
 def test_exit_on_exception_true(self):
     handshake_dict = {
         "conf": self.conf,
         "pidDir": ".",
         "context": self.context
     }
     inputs = ["{}\n".format(json.dumps(handshake_dict)), "end\n"]
     component = Component(input_stream=BytesIO(
         ''.join(inputs).encode('utf-8')),
                           output_stream=BytesIO())
     component.exit_on_exception = True
     with self.assertRaises(SystemExit) as raises_fixture:
         component.run()
     assert raises_fixture.exception.code == 1
コード例 #3
0
ファイル: test_component.py プロジェクト: pystorm/pystorm
    def test_exit_on_exception_false(self, _run_mock):
        # Make sure _run raises an exception
        def raiser(self): # lambdas can't raise
            raise StormWentAwayError if _run_mock.called else NotImplementedError
        _run_mock.side_effect = raiser

        handshake_dict = {"conf": self.conf,
                          "pidDir": ".",
                          "context": self.context}
        inputs = ["{}\n".format(json.dumps(handshake_dict)),
                  "end\n"]
        component = Component(input_stream=BytesIO(''.join(inputs).encode('utf-8')),
                              output_stream=BytesIO())
        component.exit_on_exception = False
        with self.assertRaises(SystemExit) as raises_fixture:
            component.run()
        assert raises_fixture.exception.code == 2
コード例 #4
0
ファイル: test_component.py プロジェクト: pystorm/pystorm
    def test_nested_exception(self, log_mock, _handle_run_exception_mock):
        # Make sure self._handle_run_exception raises an exception
        def raiser(self): # lambdas can't raise
            raise Exception('Oops')

        handshake_dict = {"conf": self.conf,
                          "pidDir": ".",
                          "context": self.context}
        inputs = ["{}\n".format(json.dumps(handshake_dict)),
                  "end\n"]
        component = Component(input_stream=BytesIO(''.join(inputs).encode('utf-8')),
                              output_stream=BytesIO())
        component.exit_on_exception = True
        _handle_run_exception_mock.side_effect = raiser

        with self.assertRaises(SystemExit) as raises_fixture:
            component.run()
        assert log_mock.error.call_count == 2
        assert raises_fixture.exception.code == 1
コード例 #5
0
ファイル: test_component.py プロジェクト: tchandrap/pystorm
    def test_exit_on_exception_false(self, _run_mock):
        # Make sure _run raises an exception
        def raiser(self):  # lambdas can't raise
            raise StormWentAwayError if _run_mock.called else NotImplementedError

        _run_mock.side_effect = raiser

        handshake_dict = {
            "conf": self.conf,
            "pidDir": ".",
            "context": self.context
        }
        inputs = ["{}\n".format(json.dumps(handshake_dict)), "end\n"]
        component = Component(input_stream=BytesIO(
            ''.join(inputs).encode('utf-8')),
                              output_stream=BytesIO())
        component.exit_on_exception = False
        with self.assertRaises(SystemExit) as raises_fixture:
            component.run()
        assert raises_fixture.exception.code == 2
コード例 #6
0
ファイル: test_component.py プロジェクト: tchandrap/pystorm
    def test_nested_exception(self, log_mock, _handle_run_exception_mock):
        # Make sure self._handle_run_exception raises an exception
        def raiser(self):  # lambdas can't raise
            raise Exception('Oops')

        handshake_dict = {
            "conf": self.conf,
            "pidDir": ".",
            "context": self.context
        }
        inputs = ["{}\n".format(json.dumps(handshake_dict)), "end\n"]
        component = Component(input_stream=BytesIO(
            ''.join(inputs).encode('utf-8')),
                              output_stream=BytesIO())
        component.exit_on_exception = True
        _handle_run_exception_mock.side_effect = raiser

        with self.assertRaises(SystemExit) as raises_fixture:
            component.run()
        assert log_mock.error.call_count == 2
        assert raises_fixture.exception.code == 1