# Path: osprofiler/sqlalchemy.py
# LOG = log.getLogger(__name__)
# _DISABLED = False
#     _DISABLED = True
#     _DISABLED = False
# def disable():
# def enable():
# def add_tracing(sqlalchemy, engine, name, hide_result=True):
# def wrap_session(sqlalchemy, sess):
# def _before_cursor_execute(name):
#     def handler(conn, cursor, statement, params, context, executemany):
# def _after_cursor_execute(hide_result=True):
#     def handler(conn, cursor, statement, params, context, executemany):
# def handle_error(exception_context):
# 
# Path: osprofiler/tests/test.py
# class TestCase(testcase.TestCase):
# class FunctionalTestCase(TestCase):
#     def setUp(self):


import contextlib
from unittest import mock
from osprofiler import sqlalchemy
from osprofiler.tests import test

    @mock.patch("osprofiler.sqlalchemy.profiler")
    def test_after_execute(self, mock_profiler):
        handler = sqlalchemy._after_cursor_execute()
        handler(mock.MagicMock(), 1, 2, 3, 4, 5)
        mock_profiler.stop.assert_called_once_with()

    @mock.patch("osprofiler.sqlalchemy.profiler")
    def test_after_execute_with_sql_result(self, mock_profiler):
        handler = sqlalchemy._after_cursor_execute(hide_result=False)
        cursor = mock.MagicMock()
        cursor._rows = (1,)
        handler(1, cursor, 2, 3, 4, 5)
        info = {
            "db": {
                "result": str(cursor._rows)
            }
        }
        mock_profiler.stop.assert_called_once_with(info=info)

    @mock.patch("osprofiler.sqlalchemy.profiler")
    def test_handle_error(self, mock_profiler):
        original_exception = Exception("error")
        chained_exception = Exception("error and the reason")

        sqlalchemy_exception_ctx = mock.MagicMock()
        sqlalchemy_exception_ctx.original_exception = original_exception
        sqlalchemy_exception_ctx.chained_exception = chained_exception

        sqlalchemy.handle_error(sqlalchemy_exception_ctx)

# Path: osprofiler/sqlalchemy.py
# LOG = log.getLogger(__name__)
# _DISABLED = False
#     _DISABLED = True
#     _DISABLED = False
# def disable():
# def enable():
# def add_tracing(sqlalchemy, engine, name, hide_result=True):
# def wrap_session(sqlalchemy, sess):
# def _before_cursor_execute(name):
#     def handler(conn, cursor, statement, params, context, executemany):
# def _after_cursor_execute(hide_result=True):
#     def handler(conn, cursor, statement, params, context, executemany):
# def handle_error(exception_context):
# 
# Path: osprofiler/tests/test.py
# class TestCase(testcase.TestCase):
# class FunctionalTestCase(TestCase):
#     def setUp(self):


# Path: osprofiler/tests/unit/test_sqlalchemy.py
import contextlib
from unittest import mock
from osprofiler import sqlalchemy
from osprofiler.tests import test


    @mock.patch("osprofiler.sqlalchemy.profiler")
    def test_after_execute(self, mock_profiler):
        handler = sqlalchemy._after_cursor_execute()
        handler(mock.MagicMock(), 1, 2, 3, 4, 5)
        mock_profiler.stop.assert_called_once_with()

    @mock.patch("osprofiler.sqlalchemy.profiler")
    def test_after_execute_with_sql_result(self, mock_profiler):
        handler = sqlalchemy._after_cursor_execute(hide_result=False)
        cursor = mock.MagicMock()
        cursor._rows = (1,)
        handler(1, cursor, 2, 3, 4, 5)
        info = {
            "db": {
                "result": str(cursor._rows)
            }
        }
        mock_profiler.stop.assert_called_once_with(info=info)

    @mock.patch("osprofiler.sqlalchemy.profiler")
    def test_handle_error(self, mock_profiler):
        original_exception = Exception("error")
        chained_exception = Exception("error and the reason")

        sqlalchemy_exception_ctx = mock.MagicMock()
        sqlalchemy_exception_ctx.original_exception = original_exception
        sqlalchemy_exception_ctx.chained_exception = chained_exception

        sqlalchemy.handle_error(sqlalchemy_exception_ctx)

        expected_info = {