SILENT KILLERPanel

Current Path: > > opt > cloudlinux > venv > lib64 > python3.11 > site-packages > > sqlalchemy > testing


Operation   : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
Software     : Apache
Server IP    : 162.0.232.56 | Your IP: 216.73.216.111
Domains      : 1034 Domain(s)
Permission   : [ 0755 ]

Files and Folders in: //opt/cloudlinux/venv/lib64/python3.11/site-packages//sqlalchemy/testing

NameTypeSizeLast ModifiedActions
__pycache__ Directory - -
plugin Directory - -
suite Directory - -
__init__.py File 2867 bytes April 17 2025 13:10:58.
assertions.py File 22260 bytes April 17 2025 13:10:58.
assertsql.py File 13590 bytes April 17 2025 13:10:58.
config.py File 5661 bytes April 17 2025 13:10:58.
engines.py File 10528 bytes April 17 2025 13:10:58.
entities.py File 3203 bytes April 17 2025 13:10:58.
exclusions.py File 13220 bytes April 17 2025 13:10:58.
fixtures.py File 14917 bytes April 17 2025 13:10:58.
mock.py File 893 bytes April 17 2025 13:10:58.
pickleable.py File 2693 bytes April 17 2025 13:10:58.
profiling.py File 8741 bytes April 17 2025 13:10:58.
provision.py File 5572 bytes April 17 2025 13:10:58.
replay_fixture.py File 5875 bytes April 17 2025 13:10:58.
requirements.py File 33063 bytes April 17 2025 13:10:58.
schema.py File 4764 bytes April 17 2025 13:10:58.
util.py File 10149 bytes April 17 2025 13:10:58.
warnings.py File 1649 bytes April 17 2025 13:10:58.

Reading File: //opt/cloudlinux/venv/lib64/python3.11/site-packages//sqlalchemy/testing/replay_fixture.py

from collections import deque
import contextlib
import types

from . import config
from . import fixtures
from . import profiling
from .. import create_engine
from .. import MetaData
from .. import util
from ..orm import Session


class ReplayFixtureTest(fixtures.TestBase):
    @contextlib.contextmanager
    def _dummy_ctx(self, *arg, **kw):
        yield

    def test_invocation(self):

        dbapi_session = ReplayableSession()
        creator = config.db.pool._creator

        def recorder():
            return dbapi_session.recorder(creator())

        engine = create_engine(
            config.db.url, creator=recorder, use_native_hstore=False
        )
        self.metadata = MetaData(engine)
        self.engine = engine
        self.session = Session(engine)

        self.setup_engine()
        try:
            self._run_steps(ctx=self._dummy_ctx)
        finally:
            self.teardown_engine()
            engine.dispose()

        def player():
            return dbapi_session.player()

        engine = create_engine(
            config.db.url, creator=player, use_native_hstore=False
        )

        self.metadata = MetaData(engine)
        self.engine = engine
        self.session = Session(engine)

        self.setup_engine()
        try:
            self._run_steps(ctx=profiling.count_functions)
        finally:
            self.session.close()
            engine.dispose()

    def setup_engine(self):
        pass

    def teardown_engine(self):
        pass

    def _run_steps(self, ctx):
        raise NotImplementedError()


class ReplayableSession(object):
    """A simple record/playback tool.

    This is *not* a mock testing class.  It only records a session for later
    playback and makes no assertions on call consistency whatsoever.  It's
    unlikely to be suitable for anything other than DB-API recording.

    """

    Callable = object()
    NoAttribute = object()

    if util.py2k:
        Natives = set(
            [getattr(types, t) for t in dir(types) if not t.startswith("_")]
        ).difference(
            [
                getattr(types, t)
                for t in (
                    "FunctionType",
                    "BuiltinFunctionType",
                    "MethodType",
                    "BuiltinMethodType",
                    "LambdaType",
                    "UnboundMethodType",
                )
            ]
        )
    else:
        Natives = (
            set(
                [
                    getattr(types, t)
                    for t in dir(types)
                    if not t.startswith("_")
                ]
            )
            .union(
                [
                    type(t) if not isinstance(t, type) else t
                    for t in __builtins__.values()
                ]
            )
            .difference(
                [
                    getattr(types, t)
                    for t in (
                        "FunctionType",
                        "BuiltinFunctionType",
                        "MethodType",
                        "BuiltinMethodType",
                        "LambdaType",
                    )
                ]
            )
        )

    def __init__(self):
        self.buffer = deque()

    def recorder(self, base):
        return self.Recorder(self.buffer, base)

    def player(self):
        return self.Player(self.buffer)

    class Recorder(object):
        def __init__(self, buffer, subject):
            self._buffer = buffer
            self._subject = subject

        def __call__(self, *args, **kw):
            subject, buffer = [
                object.__getattribute__(self, x)
                for x in ("_subject", "_buffer")
            ]

            result = subject(*args, **kw)
            if type(result) not in ReplayableSession.Natives:
                buffer.append(ReplayableSession.Callable)
                return type(self)(buffer, result)
            else:
                buffer.append(result)
                return result

        @property
        def _sqla_unwrap(self):
            return self._subject

        def __getattribute__(self, key):
            try:
                return object.__getattribute__(self, key)
            except AttributeError:
                pass

            subject, buffer = [
                object.__getattribute__(self, x)
                for x in ("_subject", "_buffer")
            ]
            try:
                result = type(subject).__getattribute__(subject, key)
            except AttributeError:
                buffer.append(ReplayableSession.NoAttribute)
                raise
            else:
                if type(result) not in ReplayableSession.Natives:
                    buffer.append(ReplayableSession.Callable)
                    return type(self)(buffer, result)
                else:
                    buffer.append(result)
                    return result

    class Player(object):
        def __init__(self, buffer):
            self._buffer = buffer

        def __call__(self, *args, **kw):
            buffer = object.__getattribute__(self, "_buffer")
            result = buffer.popleft()
            if result is ReplayableSession.Callable:
                return self
            else:
                return result

        @property
        def _sqla_unwrap(self):
            return None

        def __getattribute__(self, key):
            try:
                return object.__getattribute__(self, key)
            except AttributeError:
                pass
            buffer = object.__getattribute__(self, "_buffer")
            result = buffer.popleft()
            if result is ReplayableSession.Callable:
                return self
            elif result is ReplayableSession.NoAttribute:
                raise AttributeError(key)
            else:
                return result

SILENT KILLER Tool