示例#1
0
文件: database.py 项目: saoili/storm
    def test_tracing_check_disconnect(self):
        tracer = FakeTracer()
        tracer_mock = self.mocker.patch(tracer)
        tracer_mock.connection_raw_execute(ARGS)
        self.mocker.throw(DatabaseError('connection closed'))
        self.mocker.replay()

        install_tracer(tracer_mock)
        self.connection.is_disconnection_error = (
            lambda exc, extra_disconnection_errors=(
            ): 'connection closed' in str(exc))

        self.assertRaises(DisconnectionError, self.connection.execute,
                          "something")
示例#2
0
    def test_tracing_success_check_disconnect(self):
        tracer = FakeTracer()
        tracer_mock = self.mocker.patch(tracer)
        tracer_mock.connection_raw_execute(ARGS)
        tracer_mock.connection_raw_execute_success(ARGS)
        self.mocker.throw(DatabaseError("connection closed"))
        self.mocker.replay()

        install_tracer(tracer_mock)
        self.connection.is_disconnection_error = (
            lambda exc, extra_disconnection_errors=():
                "connection closed" in ustr(exc))

        with pytest.raises(DisconnectionError):
            self.connection.execute("something")
示例#3
0
    def test_tracing_error_check_disconnect(self):
        cursor_mock = self.mocker.patch(RawCursor)
        cursor_mock.execute(ARGS)
        error = ZeroDivisionError()
        self.mocker.throw(error)
        tracer = FakeTracer()
        tracer_mock = self.mocker.patch(tracer)
        tracer_mock.connection_raw_execute(ARGS)
        tracer_mock.connection_raw_execute_error(ARGS)
        self.mocker.throw(DatabaseError('connection closed'))
        self.mocker.replay()

        install_tracer(tracer_mock)
        self.connection.is_disconnection_error = (
            lambda exc, extra_disconnection_errors=():
                'connection closed' in ustr(exc))

        with pytest.raises(DisconnectionError):
            self.connection.execute("something")
示例#4
0
文件: database.py 项目: saoili/storm
 def _fail_to_connect():
     raise DatabaseError("could not connect")
示例#5
0
文件: database.py 项目: saoili/storm
 def connect():
     raise DatabaseError("_ensure_connected() tried to connect")