# Path: alembic/testing/assertions.py
# def _assert_proper_exception_context(exception):
# def assert_raises(except_cls, callable_, *args, **kw):
# def assert_raises_context_ok(except_cls, callable_, *args, **kw):
# def assert_raises_message(except_cls, msg, callable_, *args, **kwargs):
# def assert_raises_message_context_ok(
#     except_cls, msg, callable_, *args, **kwargs
# ):
# def _assert_raises(
#     except_cls, callable_, args, kwargs, msg=None, check_context=False
# ):
# def _expect_raises(except_cls, msg=None, check_context=False):
# def expect_raises(except_cls, check_context=True):
# def expect_raises_message(except_cls, msg, check_context=True):
# def eq_ignore_whitespace(a, b, msg=None):
# def _get_dialect(name):
# def expect_warnings(*messages, **kw):
# def emits_python_deprecation_warning(*messages):
#     def decorate(fn, *args, **kw):
# def expect_sqlalchemy_deprecated(*messages, **kw):
# def expect_sqlalchemy_deprecated_20(*messages, **kw):
# class _ErrorContainer:
# 
# Path: alembic/testing/fixtures.py
# class TestBase(SQLAlchemyTestBase):
#     is_sqlalchemy_future = False
# 
#     @testing.fixture()
#     def ops_context(self, migration_context):
#         with migration_context.begin_transaction(_per_migration=True):
#             yield Operations(migration_context)
# 
#     @testing.fixture
#     def migration_context(self, connection):
#         return MigrationContext.configure(
#             connection, opts=dict(transaction_per_migration=True)
#         )
# 
#     @testing.fixture
#     def connection(self):
#         with config.db.connect() as conn:
#             yield conn


from pathlib import Path
from alembic.testing import eq_
from alembic.testing import TestBase
import subprocess
import sys
import alembic

def run_command(file):
    res = subprocess.run(
        [
            sys.executable,
            str((_home / "tools" / "write_pyi.py").relative_to(_home)),
            "--stdout",
            "--file",
            file,
        ],
        stdout=subprocess.PIPE,
        cwd=_home,
        encoding="utf-8",
    )
    return res


class TestStubFiles(TestBase):
    __requires__ = ("stubs_test",)

    def test_op_pyi(self):
        res = run_command("op")
        generated = res.stdout
        expected = Path(alembic.__file__).parent / "op.pyi"
        eq_(generated, expected.read_text())

    def test_context_pyi(self):
        res = run_command("context")
        generated = res.stdout
        expected = Path(alembic.__file__).parent / "context.pyi"

# Path: alembic/testing/assertions.py
# def _assert_proper_exception_context(exception):
# def assert_raises(except_cls, callable_, *args, **kw):
# def assert_raises_context_ok(except_cls, callable_, *args, **kw):
# def assert_raises_message(except_cls, msg, callable_, *args, **kwargs):
# def assert_raises_message_context_ok(
#     except_cls, msg, callable_, *args, **kwargs
# ):
# def _assert_raises(
#     except_cls, callable_, args, kwargs, msg=None, check_context=False
# ):
# def _expect_raises(except_cls, msg=None, check_context=False):
# def expect_raises(except_cls, check_context=True):
# def expect_raises_message(except_cls, msg, check_context=True):
# def eq_ignore_whitespace(a, b, msg=None):
# def _get_dialect(name):
# def expect_warnings(*messages, **kw):
# def emits_python_deprecation_warning(*messages):
#     def decorate(fn, *args, **kw):
# def expect_sqlalchemy_deprecated(*messages, **kw):
# def expect_sqlalchemy_deprecated_20(*messages, **kw):
# class _ErrorContainer:
# 
# Path: alembic/testing/fixtures.py
# class TestBase(SQLAlchemyTestBase):
#     is_sqlalchemy_future = False
# 
#     @testing.fixture()
#     def ops_context(self, migration_context):
#         with migration_context.begin_transaction(_per_migration=True):
#             yield Operations(migration_context)
# 
#     @testing.fixture
#     def migration_context(self, connection):
#         return MigrationContext.configure(
#             connection, opts=dict(transaction_per_migration=True)
#         )
# 
#     @testing.fixture
#     def connection(self):
#         with config.db.connect() as conn:
#             yield conn


# Path: tests/test_stubs.py
from pathlib import Path
from alembic.testing import eq_
from alembic.testing import TestBase
import subprocess
import sys
import alembic


def run_command(file):
    res = subprocess.run(
        [
            sys.executable,
            str((_home / "tools" / "write_pyi.py").relative_to(_home)),
            "--stdout",
            "--file",
            file,
        ],
        stdout=subprocess.PIPE,
        cwd=_home,
        encoding="utf-8",
    )
    return res


class TestStubFiles(TestBase):
    __requires__ = ("stubs_test",)

    def test_op_pyi(self):
        res = run_command("op")
        generated = res.stdout
        expected = Path(alembic.__file__).parent / "op.pyi"
        eq_(generated, expected.read_text())

    def test_context_pyi(self):
        res = run_command("context")
        generated = res.stdout
        expected = Path(alembic.__file__).parent / "context.pyi"

        eq_(generated, expected.read_text())