Buckets:
AnonymousSpottedToad/human_verified_bucket / codebase /python /ddeutils_ddeutil-observe /tests /models /conftest.py
| from collections.abc import AsyncGenerator | |
| from pathlib import Path | |
| import pytest | |
| from sqlalchemy.ext.asyncio import ( | |
| AsyncConnection, | |
| AsyncSession, | |
| async_sessionmaker, | |
| create_async_engine, | |
| ) | |
| from src.ddeutil.observe.auth.models import Base | |
| DB_POINTER = Path(__file__).parent.parent.parent / "observe.test.db" | |
| engine = create_async_engine( | |
| f"sqlite+aiosqlite:///{DB_POINTER}", | |
| echo=False, | |
| pool_pre_ping=False, | |
| connect_args={"check_same_thread": False}, | |
| ) | |
| async def connection() -> AsyncGenerator[AsyncConnection, None]: | |
| async with engine.connect() as conn: | |
| yield conn | |
| async def session() -> AsyncGenerator[AsyncSession, None]: | |
| sessionmaker = async_sessionmaker( | |
| autoflush=False, | |
| autocommit=False, | |
| future=True, | |
| expire_on_commit=False, | |
| bind=engine, | |
| ) | |
| async with sessionmaker() as session: | |
| try: | |
| yield session | |
| await session.commit() | |
| except Exception: | |
| await session.rollback() | |
| raise | |
| finally: | |
| await session.close() | |
| async def create_and_drop_tables(connection: AsyncConnection): | |
| await connection.run_sync(Base.metadata.create_all) | |
| yield | |
| await connection.run_sync(Base.metadata.drop_all) | |
Xet Storage Details
- Size:
- 1.4 kB
- Xet hash:
- 6d26a901111fdb1aba9404c6f29b5e0a456b80b68d9a9ee422db71607eb26e6d
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.