# 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

        self.assertEqual(sa.event.listen.call_args_list, expected_calls)

    @mock.patch("osprofiler.sqlalchemy.handle_error")
    @mock.patch("osprofiler.sqlalchemy._before_cursor_execute")
    @mock.patch("osprofiler.sqlalchemy._after_cursor_execute")
    @mock.patch("osprofiler.profiler")
    def test_with_sql_result(self, mock_profiler, mock_after_exc,
                             mock_before_exc, mock_handle_error):
        sa = mock.MagicMock()
        engine = mock.MagicMock()

        mock_before_exc.return_value = "before"
        mock_after_exc.return_value = "after"

        sqlalchemy.add_tracing(sa, engine, "sql", hide_result=False)

        mock_before_exc.assert_called_once_with("sql")
        # Default set hide_result=True
        mock_after_exc.assert_called_once_with(hide_result=False)
        expected_calls = [
            mock.call(engine, "before_cursor_execute", "before"),
            mock.call(engine, "after_cursor_execute", "after"),
            mock.call(engine, "handle_error", mock_handle_error),
        ]
        self.assertEqual(sa.event.listen.call_args_list, expected_calls)

    @mock.patch("osprofiler.sqlalchemy._before_cursor_execute")
    @mock.patch("osprofiler.sqlalchemy._after_cursor_execute")
    def test_disable_and_enable(self, mock_after_exc, mock_before_exc):

# 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


        self.assertEqual(sa.event.listen.call_args_list, expected_calls)

    @mock.patch("osprofiler.sqlalchemy.handle_error")
    @mock.patch("osprofiler.sqlalchemy._before_cursor_execute")
    @mock.patch("osprofiler.sqlalchemy._after_cursor_execute")
    @mock.patch("osprofiler.profiler")
    def test_with_sql_result(self, mock_profiler, mock_after_exc,
                             mock_before_exc, mock_handle_error):
        sa = mock.MagicMock()
        engine = mock.MagicMock()

        mock_before_exc.return_value = "before"
        mock_after_exc.return_value = "after"

        sqlalchemy.add_tracing(sa, engine, "sql", hide_result=False)

        mock_before_exc.assert_called_once_with("sql")
        # Default set hide_result=True
        mock_after_exc.assert_called_once_with(hide_result=False)
        expected_calls = [
            mock.call(engine, "before_cursor_execute", "before"),
            mock.call(engine, "after_cursor_execute", "after"),
            mock.call(engine, "handle_error", mock_handle_error),
        ]
        self.assertEqual(sa.event.listen.call_args_list, expected_calls)

    @mock.patch("osprofiler.sqlalchemy._before_cursor_execute")
    @mock.patch("osprofiler.sqlalchemy._after_cursor_execute")
    def test_disable_and_enable(self, mock_after_exc, mock_before_exc):

        sqlalchemy.disable()