# Path: opentracing_instrumentation/client_hooks/sqlalchemy.py
# class SQLAlchemyPatcher(Patcher):
#     def _install_patches(self):
#     def _reset_patches(self):
#     def before_cursor_execute(conn, cursor, statement, parameters, context,
#                               executemany):
#     def after_cursor_execute(conn, cursor, statement, parameters, context,
#                              executemany):
# 
# Path: tests/opentracing_instrumentation/sql_common.py
# class User(object):
#     def __init__(self, name, fullname, password):


import pytest
import sqlalchemy.engine.url
from opentracing.ext import tags
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from opentracing_instrumentation.client_hooks import (
    sqlalchemy as sqlalchemy_hooks
)
from .sql_common import metadata, User
    except:
        pass


@pytest.fixture(autouse=True, scope='module')
def patch_sqlalchemy():
    sqlalchemy_hooks.install_patches()
    try:
        yield
    finally:
        sqlalchemy_hooks.reset_patches()


def assert_span(span, operation):
    assert span.operation_name == 'SQL ' + operation
    assert span.tags.get(tags.SPAN_KIND) == tags.SPAN_KIND_RPC_CLIENT
    assert span.tags.get(tags.DATABASE_TYPE) == 'sqlite'
    assert span.tags.get(tags.DATABASE_INSTANCE) == 'sqlite://'
    assert span.tags.get(tags.COMPONENT) == 'sqlalchemy'


def test_db(tracer, session):
    user = User(name='user', fullname='User', password='password')
    session.add(user)
    session.commit()

    spans = tracer.recorder.get_spans()
    assert len(spans) == 4

    pragma_span_1, pragma_span_2, create_span, insert_span = spans

# Path: opentracing_instrumentation/client_hooks/sqlalchemy.py
# class SQLAlchemyPatcher(Patcher):
#     def _install_patches(self):
#     def _reset_patches(self):
#     def before_cursor_execute(conn, cursor, statement, parameters, context,
#                               executemany):
#     def after_cursor_execute(conn, cursor, statement, parameters, context,
#                              executemany):
# 
# Path: tests/opentracing_instrumentation/sql_common.py
# class User(object):
#     def __init__(self, name, fullname, password):


# Path: tests/opentracing_instrumentation/test_sqlalchemy.py
import pytest
import sqlalchemy.engine.url
from opentracing.ext import tags
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from opentracing_instrumentation.client_hooks import (
    sqlalchemy as sqlalchemy_hooks
)
from .sql_common import metadata, User

    except:
        pass


@pytest.fixture(autouse=True, scope='module')
def patch_sqlalchemy():
    sqlalchemy_hooks.install_patches()
    try:
        yield
    finally:
        sqlalchemy_hooks.reset_patches()


def assert_span(span, operation):
    assert span.operation_name == 'SQL ' + operation
    assert span.tags.get(tags.SPAN_KIND) == tags.SPAN_KIND_RPC_CLIENT
    assert span.tags.get(tags.DATABASE_TYPE) == 'sqlite'
    assert span.tags.get(tags.DATABASE_INSTANCE) == 'sqlite://'
    assert span.tags.get(tags.COMPONENT) == 'sqlalchemy'


def test_db(tracer, session):
    user = User(name='user', fullname='User', password='password')
    session.add(user)
    session.commit()

    spans = tracer.recorder.get_spans()
    assert len(spans) == 4

    pragma_span_1, pragma_span_2, create_span, insert_span = spans

    assert_span(pragma_span_1, 'PRAGMA')